Dolly_v-0.4

Author:
Dolly_v-0.4
Price Data Components
Series array that contains open time of each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Dolly_v-0.4
//+------------------------------------------------------------------+
//|                                         Dolly (the famous sheep) |
//|               original indicator is called valasholic13 v2.5.mq4 |
//|                                                                  |
//|                  and the original author is valasholic@yahoo.com |
//|                                                                  |         
//|                        mods and stuff by Linuxser for Forex-TSD  |
//|                      (there is a lot of usefull code inside here)|
//|Credits: hulahula (traslation from original indonesian language)  |
//|ign... in collaboration with Linuxser (with mods and improvments  |
//+------------------------------------------------------------------+

/*
Changelog v0.4.1:
   - Modifications over the pivot points drawing: I think now is better
     and more clean code in that section. With this mod, also the
     pivots, supports and resistances are only calculated if and only
     if the flag pivotlines is set true.
     Other modifications here are about the object creation. With this
     improve the objects are created at init time and isn't necessary
     to create them at any time.
   - User experience: this is a conflictive point... I've modified some
     graphics issues to get a more readeable indicator.
       * "Unions" between zones of diferent days.
       * Realistic font size.
   - Corrections in the source coude... now it's a little more beauty (sorry for
     the little spanish comments)     
*/
#property copyright ""
#property link      ""

#define IND_NAME "Dolly v0.4.1"
#define LEVEL_1 20
#define LEVEL_2 40
#define LEVEL_3 55

#property indicator_chart_window
//#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1  Snow
#property indicator_width1 0
#property indicator_color2  Red
#property indicator_width2 2
#property indicator_color3  Blue
#property indicator_width3 2
#property indicator_color4  Orange
#property indicator_width4 2
#property indicator_color5  SteelBlue
#property indicator_width5 2
#property indicator_color6  Yellow
#property indicator_width6 1
#property indicator_color7  Aqua
#property indicator_width7 1
//---- input parameters

extern bool pivotlines = false;
extern bool onscreen = true;
extern color lineletters = LimeGreen;

//---- buffers
double PBuffer[];
double J1Buffer[];
double B1Buffer[];
double J2Buffer[];
double B2Buffer[];
double J3Buffer[];
double B3Buffer[];
string Pivot = "Pivot Point", Jual1 = "S 1", Beli1 = "R 1";
string Jual2="S 2", Beli2="R 2", Jual3="S 3", Beli3="R 3";
extern int fontsize = 8;
double P, J1, B1, J2, B2, J3, B3;
double LastHigh, LastLow, x;
double D4=0.55;

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{

   ObjectDelete("Pivot");
	ObjectDelete("Jual1");
	ObjectDelete("Beli1");
	ObjectDelete("Jual2");
	ObjectDelete("Beli2");
	ObjectDelete("Jual3");
	ObjectDelete("Beli3");   

	ObjectDelete("r1 Label");
	ObjectDelete("r1_Line");
	ObjectDelete("r2 Label");
	ObjectDelete("r2_Line");
	ObjectDelete("r3 Label");
	ObjectDelete("r3_Line");
	ObjectDelete("r1 Label");
	ObjectDelete("r1_Line");
	ObjectDelete("r2 Label");
	ObjectDelete("r2_Line");
	ObjectDelete("r3 Label");
	ObjectDelete("r3_Line");
	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");
	
	deinit_pivots();
	//----
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	//---- indicator line
	SetIndexStyle(0, DRAW_LINE);
	SetIndexStyle(1, DRAW_LINE);
	SetIndexStyle(2, DRAW_LINE);
	SetIndexStyle(3, DRAW_LINE);
	SetIndexStyle(4, DRAW_LINE);
	SetIndexStyle(5, DRAW_LINE);
	SetIndexStyle(6, DRAW_LINE);
	SetIndexBuffer(0, PBuffer);
	SetIndexBuffer(1, J1Buffer);
	SetIndexBuffer(2, B1Buffer);
	SetIndexBuffer(3, J2Buffer);
	SetIndexBuffer(4, B2Buffer);
	SetIndexBuffer(5, J3Buffer);
	SetIndexBuffer(6, B3Buffer);
	//---- name for DataWindow and indicator subwindow label
	IndicatorShortName(IND_NAME);
	//SetIndexLabel(0, "Pivot Point");
	//----
	SetIndexDrawBegin(0,1);
	IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
	
	ObjectCreate("Pivot", OBJ_TEXT, 0, 0, 0);
	ObjectSetText("Pivot", "PIVOT/SL+SP", fontsize, "Arial", lineletters);
	ObjectCreate("Jual1", OBJ_TEXT, 0, 0, 0);
	ObjectSetText("Jual1", "SELL AREA", fontsize, "Arial", lineletters);
	ObjectCreate("Beli1", OBJ_TEXT, 0, 0, 0);
	ObjectSetText("Beli1", "BUY AREA", fontsize, "Arial", lineletters);
	ObjectCreate("Jual2", OBJ_TEXT, 0, 0, 0); 
	ObjectSetText("Jual2", "1st SELL TARGET (take profit), BREAK LOW, ", fontsize, "Arial", lineletters);
	ObjectCreate("Beli2", OBJ_TEXT, 0, 0, 0);
	ObjectSetText("Beli2", "1st BUY TARGET (take profit) BREAK HIGH", fontsize, "Arial", lineletters);
	ObjectCreate("Jual3", OBJ_TEXT, 0, 0, 0);
	ObjectSetText("Jual3", "2nd TARGET", fontsize, "Arial", lineletters);
	ObjectCreate("Beli3", OBJ_TEXT, 0, 0, 0); 
	ObjectSetText("Beli3", "2nd TARGET", fontsize, "Arial", lineletters);


   init_pivots();
	//----
	return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
	int counted_bars = IndicatorCounted();
	int limit, i;

	//---- indicator calculation
	if(counted_bars == 0)
	{
		x = Period();
		if(x > 240) 
			return(-1);

		///////////To Make a Line for SELL/BUY \\\\\\\\\\\\\

	}
	if(counted_bars < 0) 
		return(-1);
	//---- last counted bar will be recounted
	//   if(counted_bars>0) counted_bars--;
	limit = (Bars - counted_bars) - 1;
	//----
	for(i = limit; i >= 0; i--)
	{ 
		if(High[i+1] > LastHigh) 
			LastHigh = High[i+1];
		//----
		if(Low[i+1] < LastLow) 
			LastLow=Low[i+1];
		if(TimeDay(Time[i]) != TimeDay(Time[i+1]))
		{
		   PBuffer[i+1] = EMPTY_VALUE;
		   J1Buffer[i+1] = EMPTY_VALUE;
		   B1Buffer[i+1] = EMPTY_VALUE;
		   J2Buffer[i+1] = EMPTY_VALUE;
		   B2Buffer[i+1] = EMPTY_VALUE;
		   J3Buffer[i+1] = EMPTY_VALUE;
		   B3Buffer[i+1] = EMPTY_VALUE;
			//////////// Logic for determinate Momentum Break \\\\\\\\\\\\\\\\\\\\\

			P = (LastHigh + LastLow + Close[i+1]) / 3; // Logic for determinating pivot
			B1 = P + LEVEL_1 * Point; // Logic to determinate Buy Area (Can be change as you analize)
			J1 = P - LEVEL_1 * Point; // Logic to determinate Sell Area (Can be change as you analize)
			B2 = P + LEVEL_2 * Point; // Logic to determinate High Break Area (Can be change as you analize)
			J2 = P - LEVEL_2 * Point; // Logic to determinate Low Break Area (Can be change as you analize)
			B3 = P + LEVEL_3 * Point; // Logic to determinate High Target Area (Can be change as you analize)
			J3 = P - LEVEL_3 * Point; // Logic to determinate Low Target Area (Can be change as you analize)
			
			//Lo usa para calcular los pivotes... no deberia ser Low[] y High[]???
			LastLow = Open[i]; 
			LastHigh = Open[i];
			
         ObjectMove("Pivot", 0, Time[i-2], P);
         ObjectMove("Jual1", 0, Time[i-2], J1);
         ObjectMove("Beli1", 0, Time[i-2], B1);
         ObjectMove("Jual2", 0, Time[i-2], J2);
         ObjectMove("Beli2", 0, Time[i-2], B2);
         ObjectMove("Jual3", 0, Time[i-2], J3);
         ObjectMove("Beli3", 0, Time[i-2], B3);
		}
		PBuffer[i] = P;
		J1Buffer[i] = J1;
		B1Buffer[i] = B1;
		J2Buffer[i] = J2;
		B2Buffer[i] = B2;
		J3Buffer[i] = J3;
		B3Buffer[i] = B3;



		if (pivotlines==true)
		{
		    //---- Saca maximos y minimos para calcular los pivotes.
		    //-- Despues tengo que leer bien esto ya que es lo que se deberia usar en un principio
		    double rates[1][6],yesterday_close,yesterday_high,yesterday_low;
		    ArrayCopyRates(rates, Symbol(), PERIOD_D1);

		    if(DayOfWeek() == 1)
		    {
			    if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,1)) == 5)
			    {
				    yesterday_close = rates[1][4];
				    yesterday_high = rates[1][3];
				    yesterday_low = rates[1][2];
			    }
			    else
			    {
				    for(int d = 5;d>=0;d--)
				    {
					    if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,d)) == 5)
					    {
						    yesterday_close = rates[d][4];
						    yesterday_high = rates[d][3];
						    yesterday_low = rates[d][2];
						    break;
					    }
				    }  
			    }
		    }
		    else
		    {
			    yesterday_close = rates[1][4];
			    yesterday_high = rates[1][3];
			    yesterday_low = rates[1][2];
		    }
			//---- Calculate Pivots
			double R = yesterday_high - yesterday_low;//range
			double p = ( yesterday_high + yesterday_low + yesterday_close ) / 3;// Standard Pivot
			double r3 = ( 2 * p ) + ( yesterday_high - ( 2 * yesterday_low ));
			double r2 = p + ( yesterday_high - yesterday_low );
			double r1 = ( 2 * p ) - yesterday_low;
			double s1 = ( 2 * p ) - yesterday_high;
			double s2 = p - ( yesterday_high - yesterday_low );
			double s3 = ( 2 * p ) - ( ( 2 * yesterday_high ) - yesterday_low );

         set_pivots(p, r1, r2, r3, s1, s2, s3);
		}

		if (onscreen==true) 

			Comment ("\n        " + IND_NAME + " ( BREAKOUT STRATEGY ) "
					+"\n -------------------------------------------------------------------"
					+"\n :::::::::::: DURING AROUND 2 BREAK :::::::::::"
					+"\n -------------------------------------------------------------------"
					+"\n BUY AREA (break) :"
					+"\n # BUY STOP1  "+Symbol()+" TO "+(DoubleToStr (B1Buffer[i],Digits))
					+"\n Set TP "+(DoubleToStr (B2Buffer[i],Digits))+" and SL TO "+(DoubleToStr(J1Buffer[i],Digits))
					+"\n # BUY STOP2  "+Symbol()+" TO "+(DoubleToStr(B2Buffer[i],Digits))
					+"\n Set TP "+(DoubleToStr ((B2Buffer[i]+(10*Point)),Digits))+" and SL TO "+(DoubleToStr (B1Buffer[i],Digits))
					+"\n \n SELL AREA (break) :"
					+"\n # SELL STOP  "+Symbol()+" TO "+(DoubleToStr (J1Buffer[i],Digits))
					+"\n Set TP "+(DoubleToStr (J2Buffer[i],Digits))+" and SL to "+(DoubleToStr (B1Buffer[i],Digits))
					+"\n # SELL STOP2  "+Symbol()+" TO "+(DoubleToStr (J2Buffer[i],Digits))
					+"\n Set TP "+(DoubleToStr ((J2Buffer[i]-(10*Point)),Digits))+" and SL TO "+(DoubleToStr(J1Buffer[i],Digits))
					+"\n -------------------------------------------------------------------"
					+"\n :::::::::::: CONSERVATIVE TRADERS :::::::::::"
					+"\n -------------------------------------------------------------------"
					+"\n Set BUY SL "+(DoubleToStr (PBuffer[i],Digits))+" minor SPREAD"
					+"\n Set SELL SL "+(DoubleToStr (PBuffer[i],Digits))+" plus SPREAD"
					+"\n -------------------------------------------------------------------"
					+"\n ::::: POSSIBLE PROJECTION AND REVERSAL LEVELS (USE WITH CAUTION) :::::"
					+"\n -------------------------------------------------------------------"
					+"\n LOWER CORRECTION :"

					+"\n # 1st TARGET/BUY LIMIT  "+Symbol()+" TO "+(DoubleToStr(PBuffer[i]-(89*Point),Digits))
					+"\n # 2nd TARGET/BUY LIMIT  "+Symbol()+" TO "+(DoubleToStr(PBuffer[i]-(144*Point),Digits))
					+"\n Set TP "+(DoubleToStr(B1Buffer[i],Digits))+" and SL TO "+(DoubleToStr(J3Buffer[i],Digits))
					+"\n \n UPPER CORRECTION :"

					+"\n # 1st TARGET/SELL LIMIT  "+Symbol()+" TO "+(DoubleToStr(PBuffer[i]+(89*Point),Digits))
					+"\n # 2nd TARGET/SELL LIMIT  "+Symbol()+" TO "+(DoubleToStr(PBuffer[i]+(144*Point),Digits))
					+"\n Set TP "+(DoubleToStr(J1Buffer[i],Digits))+" and SL TO "+(DoubleToStr(B3Buffer[i],Digits))
					+"\n -------------------------------------------------------------------");


		//HOW TO MAKE THE PRICE LINE OF THE SUPPORT & RESISTANT APPEAR?
		//WAITING FOR NEXT TIP & UP DATE


	}

	//----
	return(0);

}
//+------------------------------------------------------------------+

void init_pivots()
{
	ObjectCreate("p_Line", OBJ_HLINE,0, 0,0);
	ObjectSet("p_Line",OBJPROP_COLOR,DeepPink);
	ObjectSet("p_Line",OBJPROP_STYLE,STYLE_SOLID);

	ObjectCreate("r1_Line", OBJ_HLINE,0, 0, 0);
	ObjectSet("r1_Line",OBJPROP_COLOR,Yellow);
	ObjectSet("r1_Line",OBJPROP_STYLE,STYLE_SOLID);

	ObjectCreate("r2_Line", OBJ_HLINE,0, 0, 0);
	ObjectSet("r2_Line",OBJPROP_COLOR,Orange);
	ObjectSet("r2_Line",OBJPROP_STYLE,STYLE_SOLID);

	ObjectCreate("r3_Line", OBJ_HLINE,0, 0, 0);
	ObjectSet("r3_Line",OBJPROP_COLOR,Red);
	ObjectSet("r3_Line",OBJPROP_STYLE,STYLE_SOLID);

	ObjectCreate("s1_Line", OBJ_HLINE,0, 0, 0);
	ObjectSet("s1_Line",OBJPROP_COLOR,Yellow);
	ObjectSet("s1_Line",OBJPROP_STYLE,STYLE_SOLID);

	ObjectCreate("s2_Line", OBJ_HLINE,0, 0, 0);
	ObjectSet("s2_Line",OBJPROP_COLOR,Orange);
	ObjectSet("s2_Line",OBJPROP_STYLE,STYLE_SOLID);

	ObjectCreate("s3_Line", OBJ_HLINE,0, 0, 0);
	ObjectSet("s3_Line",OBJPROP_COLOR,Red);
	ObjectSet("s3_Line",OBJPROP_STYLE,STYLE_SOLID);

	// --- Typing Labels
	if(ObjectFind("R3 label") != 0)
	{
		ObjectCreate("R3 label", OBJ_TEXT, 0, 0, 0);
		ObjectSetText("R3 label", " R3 ", 8, "Arial", Red);
	}

	if(ObjectFind("S3 label") != 0)
	{
		ObjectCreate("S3 label", OBJ_TEXT, 0, 0, 0);
		ObjectSetText("S3 label", " S3 ", 8, "Arial", Red);
	}

	if(ObjectFind("R2 label") != 0)
	{
		ObjectCreate("R2 label", OBJ_TEXT, 0, 0, 0);
		ObjectSetText("R2 label", " R2 ", 8, "Arial", Orange);
	}

	if(ObjectFind("S2 label") != 0)
	{
		ObjectCreate("S2 label", OBJ_TEXT, 0, 0, 0);
		ObjectSetText("S2 label", " S2 ", 8, "Arial", Orange);
	}

	if(ObjectFind("R1 label") != 0)
	{
		ObjectCreate("R1 label", OBJ_TEXT, 0, 0, 0);
		ObjectSetText("R1 label", " R1 ", 8, "Arial", Yellow);
	}

	if(ObjectFind("S1 label") != 0)
	{
		ObjectCreate("S1 label", OBJ_TEXT, 0, 0, 0);
		ObjectSetText("S1 label", " S1 ", 8, "Arial", Yellow);
	}

	if(ObjectFind("P label") != 0)
	{
		ObjectCreate("P label", OBJ_TEXT, 0, 0, 0);
		ObjectSetText("P label", " Pivot ", 8, "Arial", DeepPink);
	}
	return;
}

void set_pivots(double p, double r1, double r2, double r3, double s1, double s2, double s3)
{
   ObjectSet("p_Line",OBJPROP_PRICE1, p);   ObjectMove("P label",  0, Time[0], p);
   ObjectSet("r1_Line",OBJPROP_PRICE1, r1); ObjectMove("R1 label", 0, Time[0], r1);
   ObjectSet("r2_Line",OBJPROP_PRICE1, r2); ObjectMove("R2 label", 0, Time[0], r2);
   ObjectSet("r3_Line",OBJPROP_PRICE1, r3); ObjectMove("R3 label", 0, Time[0], r3);
   ObjectSet("s1_Line",OBJPROP_PRICE1, s1); ObjectMove("S1 label", 0, Time[0], s1);
   ObjectSet("s2_Line",OBJPROP_PRICE1, s2); ObjectMove("S2 label", 0, Time[0], s2);
   ObjectSet("s3_Line",OBJPROP_PRICE1, s3); ObjectMove("S3 label", 0, Time[0], s3);
   
}

void deinit_pivots()
{
	ObjectDelete("p_Line");
	ObjectDelete("r1_Line");
	ObjectDelete("r2_Line");
	ObjectDelete("r3_Line");
	ObjectDelete("s1_Line");
	ObjectDelete("s2_Line");
	ObjectDelete("s3_Line");
}

Comments