camarilladt1_v1

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
camarilladt1_v1

This script is designed as a technical analysis tool for the MetaTrader platform, specifically built to identify key price levels on a trading chart. It automates the calculation and visualization of three distinct types of support and resistance levels: Pivot Points, Camarilla Breaks, and Midpoint Pivots.

Core Functionality

The primary purpose of this script is to help traders visualize "zones of interest" based on previous market behavior. It automatically looks back at the price action of the previous trading day to calculate specific numerical boundaries for the current day.

Key Components Explained

1. Data Collection and Time Management The script begins by scanning historical price data to identify the high, low, and closing prices of the previous session. It accounts for different time zones (via a GMT shift setting) to ensure that "daily" boundaries are correctly identified regardless of your local time. It is specifically designed to work on intraday charts; if you attempt to use it on a timeframe larger than one day (like a weekly or monthly chart), the script will alert you with an error.

2. Standard Pivot Points The script calculates traditional Pivot Points, which are used by many traders to determine the "balance" of the market.

  • Pivot Point (P): The central equilibrium point based on the average of the previous day's high, low, and close.
  • Resistance (R1, R2, R3): These represent levels where price may face difficulty moving higher.
  • Support (S1, S2, S3): These represent levels where price may find a "floor" and stop falling.

3. Camarilla Breaks (The Camarilla Theory) A significant portion of this script is dedicated to the Camarilla calculation. This logic is often used by day traders to identify breakout points and reversal zones:

  • Breakout Levels: These help identify where a trend might be accelerating or breaking out of its current range.
  • Target/Reversal Levels: These are used to identify potential areas where price might exhaust itself and turn around. The script draws these as specific horizontal lines with distinct labels (like "Long," "Short," or "Breakout") to guide the user's perspective on potential trade directions.

4. Midpoint Pivots For traders who prefer a more granular view, the script can calculate "Midpoints." These are the halfway marks between various support and resistance levels. They act as secondary "buffer zones," providing extra detail on where price might pause before continuing its move.

Visual Experience

Instead of just providing raw numbers in a data window, the script actively draws these calculations onto your chart:

  • Dynamic Lines: It creates horizontal lines that move automatically as the market updates.
  • Color Coding: It uses different colors (such as Red for resistance/shorts and Green/Blue for support/longs) to make it easy to distinguish between "ceiling" and "floor" prices at a glance.
  • Labels: Every line is accompanied by a text label, ensuring the trader knows exactly which price level they are looking at without having to manually check the math.

Summary of Use

This tool simplifies complex mathematical forecasting into a visual map. By providing these levels instantly, it allows traders to see potential "battlegrounds" where the market might react, helping them decide where to enter or exit trades based on historical price volatility.

14 Views
0 Downloads
0 Favorites
camarilladt1_v1
//+------------------------------------------------------------------+
//|                                                  camarilladt.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
//---- input parameters
extern int  GMTshift=6;
extern bool pivots = false;
extern bool camarilla = true;
extern bool midpivots = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
ObjectDelete("R1 Label"); 
ObjectDelete("R1 Line");
ObjectDelete("R2 Label");
ObjectDelete("R2 Line");
ObjectDelete("R3 Label");
ObjectDelete("R3 Line");
ObjectDelete("S1 Label");
ObjectDelete("S1 Line");
ObjectDelete("S2 Label");
ObjectDelete("S2 Line");
ObjectDelete("S3 Label");
ObjectDelete("S3 Line");
ObjectDelete("P Label");
ObjectDelete("P Line");
ObjectDelete("H5 Label");
ObjectDelete("H5 Line");
ObjectDelete("H4 Label");
ObjectDelete("H4 Line");
ObjectDelete("H3 Label");
ObjectDelete("H3 Line");
ObjectDelete("L3 Label");
ObjectDelete("L3 Line");
ObjectDelete("L4 Label");
ObjectDelete("L4 Line");
ObjectDelete("L5 Label");
ObjectDelete("L5 Line");
ObjectDelete("M5 Label");
ObjectDelete("M5 Line");
ObjectDelete("M4 Label");
ObjectDelete("M4 Line");
ObjectDelete("M3 Label");
ObjectDelete("M3 Line");
ObjectDelete("M2 Label");
ObjectDelete("M2 Line");
ObjectDelete("M1 Label");
ObjectDelete("M1 Line");
ObjectDelete("M0 Label");
ObjectDelete("M0 Line");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//---- TODO: add your code here
double day_high=0;
double day_low=0;
double yesterday_high=0;
double yesterday_open=0;
double yesterday_low=0;
double yesterday_close=0;
double today_open=0;
double ch1=0;
double ch2=0;
double ch3=0;
double ch4=0;
double cl1=0;
double cl2=0;
double cl3=0;
double cl4=0;
double D1=0.091667;
double D2=0.183333;
double D3=0.2750;
double D4=0.55;
double P=0,Q=0,S=0,R=0,M2=0,M3=0,S1=0,R1=0,M1=0,M4=0,S2=0,R2=0,M0=0,M5=0,S3=0,R3=0,L3=0,L4=0,H3=0,H4=0,nQ=0,nD=0,D=0;
double ch5=0;
double cl5=0;
//double D1=0.083333;
//double D2=0.166666;
//double D3=0.25;
//double D4=0.5;

int cnt=720;
double cur_day=0;
double prev_day=0;

double rates_d1[2][6];

//---- exit if period is greater than daily charts
if(Period() > 1440)
{
Print("Error - Chart period is greater than 1 day.");
return(-1); // then exit
}

//---- Get new daily prices & calculate pivots

while (cnt!= 0)
{
	cur_day = TimeDay(Time[cnt]- (GMTshift*3600));
	
	if (prev_day != cur_day)
	{
		yesterday_close = Close[cnt+1];
		today_open = Open[cnt];
		yesterday_high = day_high;
		yesterday_low = day_low;

		day_high = High[cnt];
		day_low  = Low[cnt];

		prev_day = cur_day;
	}
   
   if (High[cnt]>day_high)
   {
      day_high = High[cnt];
   }
   if (Low[cnt]<day_low)
   {
      day_low = Low[cnt];
   }
	
//	SetIndexValue(cnt, 0);
	cnt--;

}



D = (day_high - day_low);
Q = (yesterday_high - yesterday_low);
//------ Pivot Points ------

P = (yesterday_high + yesterday_low + yesterday_close)/3;//Pivot
R1 = (2*P)-yesterday_low;
S1 = (2*P)-yesterday_high;
R2 = P-S1+R1;
S2 = P-R1+S1;
R3 = (2*P)+(yesterday_high-(2*yesterday_low));
S3 = (2*P)-((2* yesterday_high)-yesterday_low);
M0 = (S2+S3)/2;
M1 = (S1+S2)/2;
M2 = (P+S1)/2;
M3 = (P+R1)/2;
M4 = (R1+R2)/2;
M5 = (R2+R3)/2;
//---- To display all 8 Camarilla pivots remove comment symbols below and
// add the appropriate object functions below
ch5 = (yesterday_high/yesterday_low)*yesterday_close;
ch4 = ((yesterday_high - yesterday_low)* D4) + yesterday_close;
ch3 = ((yesterday_high - yesterday_low)* D3) + yesterday_close;
//ch2 = ((yesterday_high - yesterday_low) * D2) + yesterday_close;
//ch1 = ((yesterday_high - yesterday_low) * D1) + yesterday_close;

//cl1 = yesterday_close - ((yesterday_high - yesterday_low)*(D1));
//cl2 = yesterday_close - ((yesterday_high - yesterday_low)*(D2));
cl3 = yesterday_close - ((yesterday_high - yesterday_low)*(D3));
cl4 = yesterday_close - ((yesterday_high - yesterday_low)*(D4));
cl5 = yesterday_close - (ch5 - yesterday_close);


//comment on OHLC and daily range

if (Q > 5) 
{
	nQ = Q;
}
else
{
	nQ = Q*10000;
}

if (D > 5)
{
	nD = D;
}
else
{
	nD = D*10000;
}


Comment("High= ",yesterday_high,"    Previous Days Range= ",nQ,"\nLow= ",yesterday_low,"    Current Days Range= ",nD,"\nClose= ",yesterday_close,"   CONCENTRATE AND GOOD HUNTING");

//---- Set line labels on chart window
 if (pivots==true)
   {
if(ObjectFind("R1 label") != 0)
      {
      ObjectCreate("R1 label", OBJ_TEXT, 0, Time[0], R1);
      ObjectSetText("R1 label", " R1", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("R1 label", 0, Time[0], R1);
      }

      if(ObjectFind("R2 label") != 0)
      {
      ObjectCreate("R2 label", OBJ_TEXT, 0, Time[20], R2);
      ObjectSetText("R2 label", " R2", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("R2 label", 0, Time[20], R2);
      }

      if(ObjectFind("R3 label") != 0)
      {
      ObjectCreate("R3 label", OBJ_TEXT, 0, Time[20], R3);
      ObjectSetText("R3 label", " R3", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("R3 label", 0, Time[20], R3);
      }

      if(ObjectFind("P label") != 0)
      {
      ObjectCreate("P label", OBJ_TEXT, 0, Time[0], P);
      ObjectSetText("P label", "Pivot  " +DoubleToStr(P,4), 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("P label", 0, Time[0], P);
      }

      if(ObjectFind("S1 label") != 0)
      {
      ObjectCreate("S1 label", OBJ_TEXT, 0, Time[0], S1);
      ObjectSetText("S1 label", "S1", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("S1 label", 0, Time[0], S1);
      }

      if(ObjectFind("S2 label") != 0)
      {
      ObjectCreate("S2 label", OBJ_TEXT, 0, Time[20], S2);
      ObjectSetText("S2 label", "S2", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("S2 label", 0, Time[20], S2);
      }

      if(ObjectFind("S3 label") != 0)
      {
      ObjectCreate("S3 label", OBJ_TEXT, 0, Time[20], S3);
      ObjectSetText("S3 label", "S3", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("S3 label", 0, Time[20], S3);
      }

//---  Draw  Pivot lines on chart
      if(ObjectFind("S1 line") != 0)
      {
      ObjectCreate("S1 line", OBJ_HLINE, 0, Time[40], S1);
      ObjectSet("S1 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("S1 line", OBJPROP_COLOR, DeepSkyBlue);
      }
      else
      {
      ObjectMove("S1 line", 0, Time[40], S1);
      }

      if(ObjectFind("S2 line") != 0)
      {
      ObjectCreate("S2 line", OBJ_HLINE, 0, Time[40], S2);
      ObjectSet("S2 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("S2 line", OBJPROP_COLOR, DeepSkyBlue);
      }
      else
      {
      ObjectMove("S2 line", 0, Time[40], S2);
      }

      if(ObjectFind("S3 line") != 0)
      {
      ObjectCreate("S3 line", OBJ_HLINE, 0, Time[40], S3);
      ObjectSet("S3 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("S3 line", OBJPROP_COLOR, DeepSkyBlue);
      }
      else
      {
      ObjectMove("S3 line", 0, Time[40], S3);
      }

      if(ObjectFind("P line") != 0)
      {
      ObjectCreate("P line", OBJ_HLINE, 0, Time[40], P);
      ObjectSet("P line", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("P line", OBJPROP_COLOR, Magenta);
      }
      else
      {
      ObjectMove("P line", 0, Time[40], P);
      }

      if(ObjectFind("R1 line") != 0)
      {
      ObjectCreate("R1 line", OBJ_HLINE, 0, Time[40], R1);
      ObjectSet("R1 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("R1 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("R1 line", 0, Time[40], R1);
      }

      if(ObjectFind("R2 line") != 0)
      {
      ObjectCreate("R2 line", OBJ_HLINE, 0, Time[40], R2);
      ObjectSet("R2 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("R2 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("R2 line", 0, Time[40], R2);
      }

      if(ObjectFind("R3 line") != 0)
      {
      ObjectCreate("R3 line", OBJ_HLINE, 0, Time[40], R3);
      ObjectSet("R3 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("R3 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("R3 line", 0, Time[40], R3);
      }
}
// --- THE CAMARILLA ---
if (camarilla==true)
   {
   if(ObjectFind("H5 label") != 0)
      {
      ObjectCreate("H5 label", OBJ_TEXT, 0, Time[20], ch5);
      ObjectSetText("H5 label", " H5 LB TARGET", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("H5 label", 0, Time[20], ch5);
      }
      
      if(ObjectFind("H4 label") != 0)
      {
      ObjectCreate("H4 label", OBJ_TEXT, 0, Time[20], ch4);
      ObjectSetText("H4 label", " H4 LONG BREAKOUT", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("H4 label", 0, Time[20], ch4);
      }

      if(ObjectFind("H3 label") != 0)
      {
      ObjectCreate("H3 label", OBJ_TEXT, 0, Time[20], ch3);
      ObjectSetText("H3 label", " H3 SHORT", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("H3 label", 0, Time[20], ch3);
      }

      if(ObjectFind("L3 label") != 0)
      {
      ObjectCreate("L3 label", OBJ_TEXT, 0, Time[20], cl3);
      ObjectSetText("L3 label", " L3 LONG", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("L3 label", 0, Time[20], cl3);
      }

      if(ObjectFind("L4 label") != 0)
      {
      ObjectCreate("L4 label", OBJ_TEXT, 0, Time[20], cl4);
      ObjectSetText("L4 label", " L4 SHORT BREAKOUT", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("L4 label", 0, Time[20], cl4);
      }
      
      if(ObjectFind("L5 label") != 0)
      {
      ObjectCreate("L5 label", OBJ_TEXT, 0, Time[20], cl5);
      ObjectSetText("L5 label", " L5 SB TARGET", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("L5 label", 0, Time[20], cl5);
      }

//---- Draw Camarilla lines on Chart
      if(ObjectFind("H5 line") != 0)
      {
      ObjectCreate("H5 line", OBJ_HLINE, 0, Time[40], ch5);
      ObjectSet("H5 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H5 line", OBJPROP_COLOR, Green);
      }
      else
      {
      ObjectMove("H5 line", 0, Time[40], ch5);
      }
      
      if(ObjectFind("H4 line") != 0)
      {
      ObjectCreate("H4 line", OBJ_HLINE, 0, Time[40], ch4);
      ObjectSet("H4 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H4 line", OBJPROP_COLOR, Green);
      }
      else
      {
      ObjectMove("H4 line", 0, Time[40], ch4);
      }

      if(ObjectFind("H3 line") != 0)
      {
      ObjectCreate("H3 line", OBJ_HLINE, 0, Time[40], ch3);
      ObjectSet("H3 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H3 line", OBJPROP_COLOR, Green);
      }
      else
      {
      ObjectMove("H3 line", 0, Time[40], ch3);
      }

      if(ObjectFind("L3 line") != 0)
      {
      ObjectCreate("L3 line", OBJ_HLINE, 0, Time[40], cl3);
      ObjectSet("L3 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L3 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("L3 line", 0, Time[40], cl3);
      }

      if(ObjectFind("L4 line") != 0)
      {
      ObjectCreate("L4 line", OBJ_HLINE, 0, Time[40], cl4);
      ObjectSet("L4 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L4 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("L4 line", 0, Time[40], cl4);
      }
      
      if(ObjectFind("L5 line") != 0)
      {
      ObjectCreate("L5 line", OBJ_HLINE, 0, Time[40], cl5);
      ObjectSet("L5 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L5 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("L5 line", 0, Time[40], cl5);
      }
} 
//---- Draw Midpoint Pivots on Chart
 if (midpivots==true)
   {    
      if(ObjectFind("M5 label") != 0)
      {
      ObjectCreate("M5 label", OBJ_TEXT, 0, Time[20], M5);
      ObjectSetText("M5 label", " M5", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("M5 label", 0, Time[20], M5);
      }

      if(ObjectFind("M4 label") != 0)
      {
      ObjectCreate("M4 label", OBJ_TEXT, 0, Time[20], M4);
      ObjectSetText("M4 label", " M4", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("M4 label", 0, Time[20], M4);
      }

      if(ObjectFind("M3 label") != 0)
      {
      ObjectCreate("M3 label", OBJ_TEXT, 0, Time[20], M3);
      ObjectSetText("M3 label", " M3", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("M3 label", 0, Time[20], M3);
      }

      if(ObjectFind("M2 label") != 0)
      {
      ObjectCreate("M2 label", OBJ_TEXT, 0, Time[20], M2);
      ObjectSetText("M2 label", " M2", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("M2 label", 0, Time[20], M2);
      }

      if(ObjectFind("M1 label") != 0)
      {
      ObjectCreate("M1 label", OBJ_TEXT, 0, Time[20], M1);
      ObjectSetText("M1 label", " M1", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("M1 label", 0, Time[20], M1);
      }

      if(ObjectFind("M0 label") != 0)
      {
      ObjectCreate("M0 label", OBJ_TEXT, 0, Time[20], M0);
      ObjectSetText("M0 label", " M0", 8, "Arial", EMPTY);
      }
      else
      {
      ObjectMove("M0 label", 0, Time[20], M0);
      }
     

      if(ObjectFind("M5 line") != 0)
      {
      ObjectCreate("M5 line", OBJ_HLINE, 0, Time[40], M5);
      ObjectSet("M5 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("M5 line", OBJPROP_COLOR, DarkOrange);
      }
      else
      {
      ObjectMove("M5 line", 0, Time[40], M5);
      }

      if(ObjectFind("M4 line") != 0)
      {
      ObjectCreate("M4 line", OBJ_HLINE, 0, Time[40], M4);
      ObjectSet("M4 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("M4 line", OBJPROP_COLOR, DarkOrange);
      }
      else
      {
      ObjectMove("M4 line", 0, Time[40], M4);
      }

      if(ObjectFind("M3 line") != 0)
      {
      ObjectCreate("M3 line", OBJ_HLINE, 0, Time[40], M3);
      ObjectSet("M3 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("M3 line", OBJPROP_COLOR, DarkOrange);
      }
      else
      {
      ObjectMove("M3 line", 0, Time[40], M3);
      }

      if(ObjectFind("M2 line") != 0)
      {
      ObjectCreate("M2 line", OBJ_HLINE, 0, Time[40], M2);
      ObjectSet("M2 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("M2 line", OBJPROP_COLOR, DarkOrange);
      }
      else
      {
      ObjectMove("M2 line", 0, Time[40], M2);
      }

      if(ObjectFind("M1 line") != 0)
      {
      ObjectCreate("M1 line", OBJ_HLINE, 0, Time[40], M1);
      ObjectSet("M1 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("M1 line", OBJPROP_COLOR, DarkOrange);
      }
      else
      {
      ObjectMove("M1 line", 0, Time[40], M1);
      }

      if(ObjectFind("M0 line") != 0)
      {
      ObjectCreate("M0 line", OBJ_HLINE, 0, Time[40], M0);
      ObjectSet("M0 line", OBJPROP_STYLE, STYLE_DASHDOTDOT);
      ObjectSet("M0 line", OBJPROP_COLOR, DarkOrange);
      }
      else
      {
      ObjectMove("M0 line", 0, Time[40], M0);
      }
}
//---- done
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments