TMLM-Channel-v2.2

Author: Copyright � 2004, Shurka & Kevin, ANG3110@latchess.com
TMLM-Channel-v2.2
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
TMLM-Channel-v2.2
//+------------------------------------------------------------------+
//|                                              TMLM_Channel-v1.mq4 |
//|                                 Copyright © 2007, Shurka & Kevin |
//|                            ANG3110@latchess.com, join frantacech |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, Shurka & Kevin, ANG3110@latchess.com"
#property link      ""
//----------------------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

double ExtMapBuffer1[];
//----------------------------------
extern bool ShowComments = true;
//---- input parameters for MainChannel
extern bool LongShortLogicBreakout = true;  // if true, trade breakout channel, false reverse
extern int Trigger = 50;
extern int   Hours=720;
extern color MainAlert=Red;
extern color MainUpper=Gold;
extern color MainLower=Gold;
extern color MainMiddle=Magenta;
//---- input parameters for SHI
extern int   AllBars=240;
extern int   BarsForFract=0;

//---- input parameters TSR
extern double  Risk_to_Reward_ratio =  3.0;
extern int P = 64;
extern int StepBack = 0;
double v1 = 0, v2 = 0;
int bn_v1   = 0, bn_v2   = 0;
double aSL_Long[];
double aSL_Short[];
double Top_Daily_Range[];
double Bottom_Daily_Range[];
int nDigits;


//---- internal parameters
string name = "WTL";
string entry = "";
bool OnlyLong = false, OnlyShort = false;

int CurrentBar=0;
double Step=0;
int B1=-1,B2=-1;
int UpDown=0;
double P1=0,P2=0,PP=0;
int i=0,AB=300,BFF=0;
int ishift=0;
double iprice=0;
datetime T1,T2;
//------------------
double lr,lr0,lrp;
double sx,sy,sxy,sx2,aa,bb;
int p,fs;
int f,f0,f1;
double dh,dl,dh_1,dl_1,dh_2,dl_2;
int ai_1,ai_2,bi_1,bi_2; 
double hai,lai,dhi,dli,dhm,dlm,ha0,hap,la0,lap;
double price_p1,price_p0,price_p2,price_01,price_00,price_02;
int p1,p0,p2,fp;

//*****************************************
int init() {
   p=Hours*60/Period();
   if (fs==0) {
       fs=1;
    }
//---- indicators SHI
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,164);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
//----
   if(Symbol()=="GBPJPY" || Symbol()=="EURJPY" || Symbol()=="USDJPY" || Symbol()=="CHFJPY" || Symbol()=="GOLD" || Symbol()=="_SP500")  nDigits = 2;
   else nDigits = 4;
   
   return(0);
}

//*******************************
int deinit() {
   ObjectDelete(name+"1");
   ObjectDelete(name+"0");
   ObjectDelete(name+"2"); 
   Comment("");
   ObjectDelete("HIDaily6");
   ObjectDelete("HIDaily7");
   return(0);
   }
   

//*******************************
int start() {
int i,n;
//------------------------------------------------------------------------------
if (f==1) { 
p1=iBarShift(Symbol(),Period(),ObjectGet(name+"1",OBJPROP_TIME1));
p0=iBarShift(Symbol(),Period(),ObjectGet(name+"0",OBJPROP_TIME1));
p2=iBarShift(Symbol(),Period(),ObjectGet(name+"2",OBJPROP_TIME1));
if (fp==0 && p!=p1) {p=p1; fp=1;}
if (fp==0 && p!=p0) {p=p0; fp=1;}
if (fp==0 && p!=p2) {p=p2; fp=1;}
}
//====================================================
sx=0; sy=0; sxy=0; sx2=0; 
for (n=0; n<=p; n++) {sx+=n; sy+=Close[n]; sxy+=n*Close[n]; sx2+=MathPow(n,2);}   
aa=(sx*sy-(p+1)*sxy)/(MathPow(sx,2)-(p+1)*sx2); bb=(sy-aa*sx)/(p+1);
//----------------------------------------------------
for (i=0; i<=p; i++) {
lr=bb+aa*i;
dh=High[i]-lr; dl=Low[i]-lr;
//----------------------------------------------------
if (i<p/2) {if (i==0) {dh_1=0.0; dl_1=0.0; ai_1=i; bi_1=i;} 
if (dh>=dh_1) {dh_1=dh; ai_1=i;}
if (dl<=dl_1) {dl_1=dl; bi_1=i;}}  
//----------------------------------------------------
if (i>=p/2) {if (i==p/2) {dh_2=0.0; dl_2=0.0; ai_2=i; bi_2=i;} 
if (dh>=dh_2) {dh_2=dh; ai_2=i;}
if (dl<=dl_2) {dl_2=dl; bi_2=i;}}} 
//-------------------------------------
lr0=bb; lrp=bb+aa*(i+p);
//===================================================
if (MathAbs(ai_1-ai_2)>MathAbs(bi_1-bi_2)) f=1;
if (MathAbs(ai_1-ai_2)<MathAbs(bi_1-bi_2)) f=2;
if (MathAbs(ai_1-ai_2)==MathAbs(bi_1-bi_2)) {if (MathAbs(dh_1-dh_2)<MathAbs(dl_1-dl_2)) f=1; if (MathAbs(dh_1-dh_2)>=MathAbs(dl_1-dl_2)) f=2;} 
//=================================================
if (f==1) {
for (n=0; n<=20; n++) { f1=0;
for (i=0; i<=p; i++) {hai=High[ai_1]*(i-ai_2)/(ai_1-ai_2)+High[ai_2]*(i-ai_1)/(ai_2-ai_1);  
if (i==0 || i==p/2) dhm=0.0; 
if (High[i]-hai>dhm && i<p/2) {ai_1=i; f1=1;}
if (High[i]-hai>dhm && i>=p/2) {ai_2=i; f1=1;} }
if (f==0) break;} 
//----------------------------
for (i=0; i<=p; i++) {hai=High[ai_1]*(i-ai_2)/(ai_1-ai_2)+High[ai_2]*(i-ai_1)/(ai_2-ai_1);  
dli=Low[i]-hai; 
if (i==0) dlm=0.0; if (dli<dlm) dlm=dli;}   
ha0=High[ai_1]*(0-ai_2)/(ai_1-ai_2)+High[ai_2]*(0-ai_1)/(ai_2-ai_1); 
hap=High[ai_1]*(p-ai_2)/(ai_1-ai_2)+High[ai_2]*(p-ai_1)/(ai_2-ai_1);
//----------------------------
//i have changed the code so the name of the trend does not change // Fadi
price_p1=hap;      
price_p0=hap+dlm/2;
price_p2=hap+dlm;
price_01=ha0;
price_00=ha0+dlm/2;
price_02=ha0+dlm;
}
//=================================================
if (f==2) {
for (n=0; n<=20; n++) { f1=0;
for (i=0; i<=p; i++) {lai=Low[bi_1]*(i-bi_2)/(bi_1-bi_2)+Low[bi_2]*(i-bi_1)/(bi_2-bi_1); 
if (i==0 || i==p/2) dlm=0.0; 
if (Low[i]-lai<dlm && i<p/2) {bi_1=i; f1=1;}
if (Low[i]-lai<dlm && i>=p/2) {bi_2=i; f1=1;}} 
if (f==0) break;}
//----------------------------
for (i=0; i<=p; i++) {lai=Low[bi_1]*(i-bi_2)/(bi_1-bi_2)+Low[bi_2]*(i-bi_1)/(bi_2-bi_1); 
dhi=High[i]-lai;
if (i==0) dhm=0.0; if (dhi>dhm) dhm=dhi;}   
la0=Low[bi_1]*(0-bi_2)/(bi_1-bi_2)+Low[bi_2]*(0-bi_1)/(bi_2-bi_1); 
lap=Low[bi_1]*(p-bi_2)/(bi_1-bi_2)+Low[bi_2]*(p-bi_1)/(bi_2-bi_1);
//----------------------------------------------------------------
//i have changed the code so the name of the trend does not change // Fadi
price_p1=lap;
price_p0=lap+dhm/2;
price_p2=lap+dhm;
price_01=la0;
price_00=la0+dhm/2;
price_02=la0+dhm;
}
//===================================================================================

if (price_02 > price_01)
  {
   ObjectCreate(name+"1",2, 0,Time[p],price_p1,Time[0],price_01);
   ObjectCreate(name+"0",2, 0,Time[p],price_p0,Time[0],price_00);
   ObjectCreate(name+"2",2, 0,Time[p],price_p2,Time[0],price_02);
   //-----------------------------------------------------------------
  
  ObjectSet(name+"2",OBJPROP_COLOR,MainUpper);
  ObjectSet(name+"1",OBJPROP_COLOR,MainLower);
  entry = "LONG&SHORT";
  OnlyLong = false;
  OnlyShort = false;

  if (NormalizeDouble((price_02 - Ask)/Point,0) < Trigger )
  {
     ObjectSet(name+"2",OBJPROP_COLOR,MainAlert);
     entry = "Only SHORT";
     OnlyShort = true;
  } 

  if (NormalizeDouble((Bid - price_01)/Point,0) < Trigger )
  {
     ObjectSet(name+"1",OBJPROP_COLOR,MainAlert);
     entry = "Only LONG";
     OnlyLong = true;
  } 
 
   ObjectSet(name+"0",OBJPROP_COLOR,MainMiddle);
   ObjectSet(name+"0",OBJPROP_STYLE,STYLE_DOT);
   
   ObjectSet(name+"0",OBJPROP_WIDTH,2);  // these vaules control the width of the line 
   ObjectSet(name+"1",OBJPROP_WIDTH,2);
   ObjectSet(name+"2",OBJPROP_WIDTH,2);
   //---------------------------------------------
   ObjectSet(name+"1",OBJPROP_TIME1,Time[p]);
   ObjectSet(name+"1",OBJPROP_PRICE1,price_p1);
   ObjectSet(name+"1",OBJPROP_TIME2,Time[0]);
   ObjectSet(name+"1",OBJPROP_PRICE2,price_01);
   ObjectSet(name+"0",OBJPROP_TIME1,Time[p]);
   ObjectSet(name+"0",OBJPROP_PRICE1,price_p0);
   ObjectSet(name+"0",OBJPROP_TIME2,Time[0]);
   ObjectSet(name+"0",OBJPROP_PRICE2,price_00);
   ObjectSet(name+"2",OBJPROP_TIME1,Time[p]);
   ObjectSet(name+"2",OBJPROP_PRICE1,price_p2);
   ObjectSet(name+"2",OBJPROP_TIME2,Time[0]);
   ObjectSet(name+"2",OBJPROP_PRICE2,price_02);
   } else
   {
   ObjectCreate(name+"2",2, 0,Time[p],price_p1,Time[0],price_01);
   ObjectCreate(name+"0",2, 0,Time[p],price_p0,Time[0],price_00);
   ObjectCreate(name+"1",2, 0,Time[p],price_p2,Time[0],price_02);
   //-----------------------------------------------------------------

  ObjectSet(name+"2",OBJPROP_COLOR,MainUpper);
  ObjectSet(name+"1",OBJPROP_COLOR,MainLower);
  entry = "LONG&SHORT";
  OnlyLong = false;
  OnlyShort = false;

  if (NormalizeDouble((price_01 - Ask)/Point,0) < Trigger )
  {
     ObjectSet(name+"2",OBJPROP_COLOR,MainAlert);
     entry = "Only SHORT";
     OnlyShort = true;
  }

  if (NormalizeDouble((Bid - price_02)/Point,0) < Trigger )
  {
     ObjectSet(name+"1",OBJPROP_COLOR,MainAlert);
     entry = "Only LONG";
     OnlyLong = true;
  } 
 
   ObjectSet(name+"0",OBJPROP_COLOR,MainMiddle);
   ObjectSet(name+"0",OBJPROP_STYLE,STYLE_DOT);

   ObjectSet(name+"0",OBJPROP_WIDTH,2);  // these vaules control the width of the line 
   ObjectSet(name+"2",OBJPROP_WIDTH,2);
   ObjectSet(name+"1",OBJPROP_WIDTH,2);
   //---------------------------------------------
   ObjectSet(name+"2",OBJPROP_TIME1,Time[p]);
   ObjectSet(name+"2",OBJPROP_PRICE1,price_p1);
   ObjectSet(name+"2",OBJPROP_TIME2,Time[0]);
   ObjectSet(name+"2",OBJPROP_PRICE2,price_01);
   ObjectSet(name+"0",OBJPROP_TIME1,Time[p]);
   ObjectSet(name+"0",OBJPROP_PRICE1,price_p0);
   ObjectSet(name+"0",OBJPROP_TIME2,Time[0]);
   ObjectSet(name+"0",OBJPROP_PRICE2,price_00);
   ObjectSet(name+"1",OBJPROP_TIME1,Time[p]);
   ObjectSet(name+"1",OBJPROP_PRICE1,price_p2);
   ObjectSet(name+"1",OBJPROP_TIME2,Time[0]);
   ObjectSet(name+"1",OBJPROP_PRICE2,price_02);   
   }
//==================================================================
f=1; p1=p; p0=p; p2=p; fp=0; 
//*************************************************************************************
//----
   int    counted_bars=IndicatorCounted();
//---- 
	if ((AllBars==0) || (Bars<AllBars)) AB=Bars; else AB=AllBars; //AB-êîëè÷åñòâî îáñ÷èòûâàåìûõ áàðîâ
	if (BarsForFract>0) 
		BFF=BarsForFract; 
	else
	{
		switch (Period())
		{
			case 1: BFF=12; break;
			case 5: BFF=48; break;
			case 15: BFF=24; break;
			case 30: BFF=24; break;
			case 60: BFF=12; break;
			case 240: BFF=15; break;
			case 1440: BFF=10; break;
			case 10080: BFF=6; break;
			default: DelObj(); return(-1); break;
		}
	}
	CurrentBar=2; //ñ÷èòàåì ñ òðåòüåãî áàðà, ÷òîáû ôðàêòàë "çàêðåïèëñÿ
	B1=-1; B2=-1; UpDown=0;
	while(((B1==-1) || (B2==-1)) && (CurrentBar<AB))
	{
		//UpDown=1 çíà÷èò ïåðâûé ôðàêòàë íàéäåí ñâåðõó, UpDown=-1 çíà÷èò ïåðâûé ôðàêòàë
		//íàéäåí ñíèçó, UpDown=0 çíà÷èò ôðàêòàë åù¸ íå íàéäåí.
		//Â1 è Â2 - íîìåðà áàðîâ ñ ôðàêòàëàìè, ÷åðåç íèõ ñòðîèì îïîðíóþ ëèíèþ.
		//Ð1 è Ð2 - ñîîòâåòñòâåííî öåíû ÷åðåç êîòîðûå áóäåì ëèíèþ ïðîâîäèòü

		if((UpDown<1) && (CurrentBar==Lowest(Symbol(),Period(),MODE_LOW,BFF*2+1,CurrentBar-BFF))) 
		{
			if(UpDown==0) { UpDown=-1; B1=CurrentBar; P1=Low[B1]; }
			else { B2=CurrentBar; P2=Low[B2];}
		}
		if((UpDown>-1) && (CurrentBar==Highest(Symbol(),Period(),MODE_HIGH,BFF*2+1,CurrentBar-BFF))) 
		{
			if(UpDown==0) { UpDown=1; B1=CurrentBar; P1=High[B1]; }
			else { B2=CurrentBar; P2=High[B2]; }
		}
		CurrentBar++;
	}
	if((B1==-1) || (B2==-1)) {DelObj(); return(-1);} // Çíà÷èò íå íàøëè ôðàêòàëîâ ñðåäè 300 áàðîâ 8-)
	Step=(P2-P1)/(B2-B1);//Âû÷èñëèëè øàã, åñëè îí ïîëîæèòåëüíûé, òî êàíàë íèñõîäÿùèé
	P1=P1-B1*Step; B1=0;//ïåðåñòàâëÿåì öåíó è ïåðâûé áàð ê íóëþ
	//À òåïåðü îïîðíóþ òî÷êó ïðîòèâîïîëîæíîé ëèíèè êàíàëà.
	ishift=0; iprice=0;
	if(UpDown==1)
	{ 
		PP=Low[2]-2*Step;
		for(i=3;i<=B2;i++) 
		{
			if(Low[i]<PP+Step*i) { PP=Low[i]-i*Step; }
		}
		if(Low[0]<PP) {ishift=0; iprice=PP;}
		if(Low[1]<PP+Step) {ishift=1; iprice=PP+Step;}
		if(High[0]>P1) {ishift=0; iprice=P1;}
		if(High[1]>P1+Step) {ishift=1; iprice=P1+Step;}
	} 
	else
	{ 
		PP=High[2]-2*Step;
		for(i=3;i<=B2;i++) 
		{
			if(High[i]>PP+Step*i) { PP=High[i]-i*Step;}
		}
		if(Low[0]<P1) {ishift=0; iprice=P1;}
		if(Low[1]<P1+Step) {ishift=1; iprice=P1+Step;}
		if(High[0]>PP) {ishift=0; iprice=PP;}
		if(High[1]>PP+Step) {ishift=1; iprice=PP+Step;}
	}
	//Òåïåðü ïåðåñòàâèì êîíå÷íóþ öåíó è áàð íà ÀÂ, ÷òîáû ëèíèè êàíàëà ðèñîâàëèñü ïîäëèííåå
	P2=P1+AB*Step;
	T1=Time[B1]; T2=Time[AB];

	//Åñëè íå áûëî ïåðåñå÷åíèÿ êàíàëà, òî 0, èíà÷å ñòàâèì ïñèñó.
	if(iprice!=0) ExtMapBuffer1[ishift]=iprice;
	DelObj();
	//Comment (PP,P1);
	
	if (PP<P1)
	{
   if (OnlyShort == false)
     {
      if (LongShortLogicBreakout  && (OnlyLong == false))
      {
	   ObjectCreate("TL2",OBJ_TREND,0,T2,PP+Step*AB,T1,PP); 
		ObjectSet("TL2",OBJPROP_COLOR,Lime); 
		ObjectSet("TL2",OBJPROP_WIDTH,2); 
		ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID);       
      } else
      {
	   ObjectCreate("TL1",OBJ_TREND,0,T2,PP+Step*AB,T1,PP); 
		ObjectSet("TL1",OBJPROP_COLOR,Lime); 
		ObjectSet("TL1",OBJPROP_WIDTH,2); 
		ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID); 
		}
	  }
   
   if (OnlyLong == false)
     {
      if (LongShortLogicBreakout  && (OnlyShort == false))
      {
	   ObjectCreate("TL1",OBJ_TREND,0,T2,P2,T1,P1); 
		ObjectSet("TL1",OBJPROP_COLOR,Lime); 
		ObjectSet("TL1",OBJPROP_WIDTH,2); 
		ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID);      
      } else
      {
	   ObjectCreate("TL2",OBJ_TREND,0,T2,P2,T1,P1); 
		ObjectSet("TL2",OBJPROP_COLOR,Lime); 
		ObjectSet("TL2",OBJPROP_WIDTH,2); 
		ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID);
		} 
	  }

	   ObjectCreate("MIDL",OBJ_TREND,0,T2,(P2+PP+Step*AB)/2,T1,(P1+PP)/2);
		ObjectSet("MIDL",OBJPROP_COLOR,Lime); 
		ObjectSet("MIDL",OBJPROP_WIDTH,1); 
		ObjectSet("MIDL",OBJPROP_STYLE,STYLE_DOT);
		}
		if (PP>P1)
	{
   if (OnlyLong == false)
     {
      if (LongShortLogicBreakout && (OnlyShort == false))
      {
	   ObjectCreate("TL1",OBJ_TREND,0,T2,PP+Step*AB,T1,PP); 
		ObjectSet("TL1",OBJPROP_COLOR,Lime); 
		ObjectSet("TL1",OBJPROP_WIDTH,2); 
		ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID);     
      } else
      {
	   ObjectCreate("TL2",OBJ_TREND,0,T2,PP+Step*AB,T1,PP); 
		ObjectSet("TL2",OBJPROP_COLOR,Lime); 
		ObjectSet("TL2",OBJPROP_WIDTH,2); 
		ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID); 
		}
	  }

   if (OnlyShort == false)
     {
      if (LongShortLogicBreakout && (OnlyLong == false))
      {
	   ObjectCreate("TL2",OBJ_TREND,0,T2,P2,T1,P1); 
		ObjectSet("TL2",OBJPROP_COLOR,Lime); 
		ObjectSet("TL2",OBJPROP_WIDTH,2); 
		ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID);     
      } else
      {
	   ObjectCreate("TL1",OBJ_TREND,0,T2,P2,T1,P1); 
		ObjectSet("TL1",OBJPROP_COLOR,Lime); 
		ObjectSet("TL1",OBJPROP_WIDTH,2); 
		ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID); 
		}
	  }

   	ObjectCreate("MIDL",OBJ_TREND,0,T2,(P2+PP+Step*AB)/2,T1,(P1+PP)/2);
		ObjectSet("MIDL",OBJPROP_COLOR,Lime); 
		ObjectSet("MIDL",OBJPROP_WIDTH,1); 
		ObjectSet("MIDL",OBJPROP_STYLE,STYLE_DOT);
		}
		//Comment(" Channel size = ", DoubleToStr(MathAbs(PP - P1)/Point,0), " Slope = ", DoubleToStr(-Step/Point, 2));

//----TSR
   int      R1=0,R5=0,R10=0,R20=0,RAvg=0;
   int      RoomUp=0,RoomDown=0,StopLoss_Long=0,StopLoss_Short=0;
   double   SL_Long=0,SL_Short=0;
   double   low0=0,high0=0;
   string   Text="";
   //int      i=0;
   double   SwapShort=0, SwapLong=0;
   
   double curr_w1_EMA21, curr_d1_EMA21, curr_h4_EMA21;
   double curr_w1_SMA5, curr_d1_SMA5, curr_h4_SMA5;
   double prev_w1_EMA21, prev_d1_EMA21, prev_h4_EMA21;
   double prev_w1_SMA5, prev_d1_SMA5, prev_h4_SMA5;
   double WDiff_w1, WDiff_d1, WDiff_h4;
   string Direction_w1, Direction_d1, Direction_h4;
   string Filter;
   
   SwapLong = MarketInfo(Symbol(),MODE_SWAPLONG);
   SwapShort = MarketInfo(Symbol(),MODE_SWAPSHORT);
   int Spread = MarketInfo(Symbol(),MODE_SPREAD);
   int Leverage = AccountLeverage();

//---- Calculate the different weekly data
         curr_w1_EMA21=iMA(NULL,PERIOD_W1,21,0,MODE_EMA,PRICE_MEDIAN,0);
         curr_w1_SMA5=iMA(NULL,PERIOD_W1,5,0,MODE_SMA,PRICE_MEDIAN,0);
         prev_w1_EMA21=iMA(NULL,PERIOD_W1,21,0,MODE_EMA,PRICE_MEDIAN,1);
         prev_w1_SMA5=iMA(NULL,PERIOD_W1,5,0,MODE_SMA,PRICE_MEDIAN,1);
         WDiff_w1=((curr_w1_SMA5-curr_w1_EMA21) - (prev_w1_SMA5-prev_w1_EMA21));
         if (WDiff_w1 > 0.0) Direction_w1 = "^^ UP ^^";
         if (WDiff_w1 < 0.0) Direction_w1 = "vv DOWN vv";        
         
//---- Calculate the different daily data
         curr_d1_EMA21=iMA(NULL,PERIOD_D1,21,0,MODE_EMA,PRICE_MEDIAN,0);
         curr_d1_SMA5=iMA(NULL,PERIOD_D1,5,0,MODE_SMA,PRICE_MEDIAN,0);
         prev_d1_EMA21=iMA(NULL,PERIOD_D1,21,0,MODE_EMA,PRICE_MEDIAN,1);
         prev_d1_SMA5=iMA(NULL,PERIOD_D1,5,0,MODE_SMA,PRICE_MEDIAN,1);
         WDiff_d1=((curr_d1_SMA5-curr_d1_EMA21) - (prev_d1_SMA5-prev_d1_EMA21));
         if (WDiff_d1 > 0.0) Direction_d1 = "^^ UP ^^";
         if (WDiff_d1 < 0.0) Direction_d1 = "vv DOWN vv";    
         
//---- Calculate the different 4hour data
         curr_h4_EMA21=iMA(NULL,PERIOD_H4,21,0,MODE_EMA,PRICE_MEDIAN,0);
         curr_h4_SMA5=iMA(NULL,PERIOD_H4,5,0,MODE_SMA,PRICE_MEDIAN,0);
         prev_h4_EMA21=iMA(NULL,PERIOD_H4,21,0,MODE_EMA,PRICE_MEDIAN,1);
         prev_h4_SMA5=iMA(NULL,PERIOD_H4,5,0,MODE_SMA,PRICE_MEDIAN,1);
         WDiff_h4=((curr_h4_SMA5-curr_h4_EMA21) - (prev_h4_SMA5-prev_h4_EMA21));
         if (WDiff_h4 > 0.0) Direction_h4 = "^^ UP ^^";
         if (WDiff_h4 < 0.0) Direction_h4 = "vv DOWN vv";                     

   R1 =  (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/Point;
   for(i=1;i<=5;i++)    R5    =  R5  +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
   for(i=1;i<=10;i++)   R10   =  R10 +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
   for(i=1;i<=20;i++)   R20   =  R20 +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;

   R5    = R5/5;
   R10   = R10/10;
   R20   = R20/20;
   RAvg  =  (R5+R10+R20)/3;    

   low0  =  iLow(NULL,PERIOD_D1,0);
   high0 =  iHigh(NULL,PERIOD_D1,0);

   RoomUp         =  RAvg - (Bid - low0)/Point;
   RoomDown       =  RAvg - (high0 - Bid)/Point;
   StopLoss_Long  =  RoomUp/Risk_to_Reward_ratio;
   SL_Long        =  Bid - StopLoss_Long*Point;
   StopLoss_Short =  RoomDown/Risk_to_Reward_ratio;
   SL_Short       =  Bid + StopLoss_Short*Point;
   
     //price
   bn_v1 = Lowest(NULL,0,MODE_LOW,P+StepBack,0);
   bn_v2 = Highest(NULL,0,MODE_HIGH,P+StepBack,0); // changes when price exceeds hi/low

   v1 = Low[bn_v1];
   v2 = High[bn_v2];
   
  double HI2 = iHigh(NULL,1440,0);
  double LOW2 = iLow(NULL,1440,0); 
  double HI3 = iHigh(NULL,1440,1);
  double LOW3 = iLow(NULL,1440,1);
  double HI4 = iHigh(NULL,1440,0);
  double LOW4 = iLow(NULL,1440,0);
  double HI5 = iHigh(NULL,1440,2);
  double LOW5 = iLow(NULL,1440,2);
  double HI6 = iHigh(NULL,1440,3);
  double LOW6 = iLow(NULL,1440,3);
  double HI7 = iHigh(NULL,1440,4);
  double LOW7 = iLow(NULL,1440,4);
  double HI8 = iHigh(NULL,1440,5);
  double LOW8 = iLow(NULL,1440,5);
  double HI9 = iHigh(NULL,1440,6);
  double LOW9 = iLow(NULL,1440,6);
  double HI10 = iHigh(NULL,1440,7);
  double LOW10 = iLow(NULL,1440,7);
  double HI11 = iHigh(NULL,1440,8);
  double LOW11 = iLow(NULL,1440,8);
  double HI12 = iHigh(NULL,1440,9);
  double LOW12 = iLow(NULL,1440,9);
  double HI13 = iHigh(NULL,1440,10);
  double LOW13 = iLow(NULL,1440,10);
  double HI14 = iHigh(NULL,1440,11);
  double LOW14 = iLow(NULL,1440,11);
  double HI15 = iHigh(NULL,1440,12);
  double LOW15 = iLow(NULL,1440,12);
  double HI16 = iHigh(NULL,1440,13);
  double LOW16 = iLow(NULL,1440,13);
  double HI17 = iHigh(NULL,1440,14);
  double LOW17 = iLow(NULL,1440,14);
  double HI18 = iHigh(NULL,1440,15);
  double LOW18 = iLow(NULL,1440,15);
  double HI19 = iHigh(NULL,1440,16);
  double LOW19 = iLow(NULL,1440,16);
  double HI20 = iHigh(NULL,1440,17);
  double LOW20 = iLow(NULL,1440,17);
  double HI21 = iHigh(NULL,1440,18);
  double LOW21 = iLow(NULL,1440,18);
  double HI22 = iHigh(NULL,1440,19);
  double LOW22 = iLow(NULL,1440,19);
  double HI23 = iHigh(NULL,1440,20);
  double LOW23 = iLow(NULL,1440,20);
  
  double OPEN = iOpen(NULL,1440,0);
  double CLOSE = iClose(NULL,1440,0);
  
  double ONE = (HI3-LOW3)/2;
  
  double FIVE = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8))/10;
                   
                
  double TEN = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8)+
                  (HI9-LOW9)+(HI10-LOW10)+(HI11-LOW11)+(HI12-LOW12)+(HI13-LOW13))/20;
                    
  double TWENTY = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8)+
               (HI9-LOW9)+(HI10-LOW10)+(HI11-LOW11)+(HI12-LOW12)+(HI13-LOW13)+
               (HI14-LOW14)+(HI15-LOW15)+(HI16-LOW16)+(HI17-LOW17)+(HI18-LOW18)+
               (HI19-LOW19)+(HI20-LOW20)+(HI21-LOW21)+(HI22-LOW22)+(HI23-LOW23))/40; 
                                              
  // double AV = (ONE+FIVE+TEN+TWENTY)/4;// New Setting AV = (FIVE+TEN+TWENTY)/3;
  double AV = (FIVE+TEN+TWENTY)/3;
  
  double HIDaily = iHigh(NULL,1440,0)-(AV);
  double LOWDaily = iLow(NULL,1440,0)+(AV);
  double HIDaily1 = iHigh(NULL,1440,0); 
  double LOWDaily1 =iLow(NULL,1440,0); 
  double HIDaily2 = iHigh(NULL,1440,0)-(AV)*2; 
  double LOWDaily2 =iLow(NULL,1440,0)+(AV)*2; 
  double CURRPRICE = iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0);    

   Text =   "\nAverage Day  Range: " +  RAvg + "\n"  + 
            "Prev 01  Day  Range: " +  R1   + "\n" + 
            "Prev 05  Days Range: " +  R5   + "\n" + 
            "Prev 10  Days Range: " +  R10  + "\n" +
            "Prev 20  Days Range: " +  R20  + "\n";
   Text =   Text +
            "Room Up:     " + RoomUp              + "\n" +
            "Room Down: " + RoomDown            + "\n" +
            "Max. StopLosses should be :"  + "\n" +
            "Long:  " + StopLoss_Long  + " Pips at " + DoubleToStr(SL_Long,Digits)  + "\n" +
            "Short: " + StopLoss_Short + " Pips at " + DoubleToStr(SL_Short,Digits) + "\n";

//Bottom of Daily Range
 if(ObjectFind("HIDaily6") != 0)
{
ObjectCreate("HIDaily6", OBJ_TEXT, 0, Time[8],HIDaily2);
ObjectSetText("HIDaily6", "----------", 7, "Verdana",SandyBrown);
}
else
{
ObjectMove("HIDaily6", 0, Time[8], HIDaily2);
}
//TOP of Daily Range
 if(ObjectFind("HIDaily7") != 0)
{
ObjectCreate("HIDaily7", OBJ_TEXT, 0, Time[7],LOWDaily2);
ObjectSetText("HIDaily7", "----------", 7, "Verdana",SandyBrown);
}
else
{
ObjectMove("HIDaily7", 0, Time[7], LOWDaily2);
}

//----

if (ShowComments)
 {
 //Comment(" Main Channel size: ", DoubleToStr(MathAbs(price_02 - price_01)/Point,0), ", Entry: ",entry, ", Trigger: ", DoubleToStr(Trigger,0), "\n"," SHI Channel size: ", DoubleToStr(MathAbs(PP - P1)/Point,0), ", Slope: ", DoubleToStr(-Step/Point, 2));
 Comment( "Main Channel size: ", DoubleToStr(MathAbs(price_02 - price_01)/Point,0), ", Entry: ",entry, ", Trigger: ", DoubleToStr(Trigger,0), "\n","SHI Channel size: ", DoubleToStr(MathAbs(PP - P1)/Point,0), ", Slope: ", DoubleToStr(-Step/Point, 2)+
           "\nTunnel Weekly: ",Direction_w1,"\nTunnel Daily: ",Direction_d1,"\n","Tunnel 4hour: ",Direction_h4,"\n","Today Range = ",(v2-v1)/Point,"\n","Today HighClose = ",v2,"\n","Today LowClose = ",v1,"\n\n"+
           "Top Daily Range:  " + DoubleToStr(LOWDaily2,Digits)+ "\n" +
           "Bottom Daily Range: " + DoubleToStr(HIDaily2,Digits)+ "\n"+ 
           "50% Daily Average: " +DoubleToStr(AV/Point,0)+ "\n" +
           "\n"+ "SWAP Long: ",SwapLong," SWAP Short: ",SwapShort,"\n"+"Spread: ", Spread + ", Leverage: ", Leverage +"\n" +Text); 
 }
//if (ShowComments) Comment(" Main Channel size = ", DoubleToStr(MathAbs(price_02 - price_01)/Point,0), " Slope = ");
//Comment( "Ask:", Ask,", Bid:", Bid,"\n","price_02: ",price_02, "\n","price_01: ",price_01, "\n",entry);
//Sleep(10000);
//RefreshRates();
return(0);}
//=====================================================================================

void DelObj()
{
	ObjectDelete("TL1");
	ObjectDelete("TL2");
	ObjectDelete("MIDL");
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---