Distilled from 286 confusing lines to only 151 clear lines, and can also do more.
Now it is a very simple indicator that has a lot of potential in conjunction with, for example, an EMA 50 (Steven Primo's buy/sell line) and a suitable exit.
Distilled down from 286 confusing lines to just 151 clear lines, and can do more.
Now it is a very simple indicator which, in conjunction with an EMA 50 (Steven Primo's buy/sell line) and a suitable exit, for example, definitely has potential.
This indicator is a good candidate for my homepage, which will go online at the beginning of next year.
Super nice of you! I tried it out straight away and it works perfectly. Thank you very much!
Joseph Kisakye #: there are errors on compilation in meta editor. please fix if possible. thank you for the free offer of such a potentially great indicator concept
this is code modified for no error..
//+------------------------------------------------------------------+//| Indicator: reversal.mq5 |//| |//| |//+------------------------------------------------------------------+#property copyright"Sergey Vradiy"#property version"1.00"#property description""//--- indicator settings#property indicator_chart_window#property indicator_buffers2#property indicator_plots2#property indicator_type1DRAW_ARROW#property indicator_width13#property indicator_color10x0000FF#property indicator_label1"Sell"#property indicator_type2DRAW_ARROW#property indicator_width23#property indicator_color20xFFAA00#property indicator_label2"Buy"//--- indicator buffersdouble Buffer1[];
double Buffer2[];
inputint Interval=10;
datetime time_alert; //used when sending alertinputbool Send_Email=true;
double myPoint; //initialized in OnInit//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+void myAlert(string type,string message)
{
if(type=="print")
Print(message);
elseif(type=="error")
{
Print(type+" | reversal @ "+Symbol()+","+(string)Period()+" | "+message);
}
elseif(type=="indicator")
{
if(Send_Email)
SendMail("reversal",type+" | reversal @ "+Symbol()+","+(string)Period()+" | "+message);
}
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+void DrawLine(string objname,double price,int count,int start_index) //creates or modifies existing object if necessary
{
if((price<0) && ObjectFind(0,objname)>=0)
{
ObjectDelete(0,objname);
}
elseif(ObjectFind(0,objname)>=0 && ObjectGetInteger(0,objname,OBJPROP_TYPE)==OBJ_TREND)
{
datetime Time[];
ArraySetAsSeries(Time,true);
CopyTime(Symbol(),Period(),0,start_index+count,Time);
ObjectSetInteger(0,objname,OBJPROP_TIME,Time[start_index]);
ObjectSetDouble(0,objname,OBJPROP_PRICE,price);
ObjectSetInteger(0,objname,OBJPROP_TIME,1,Time[start_index+count-1]);
ObjectSetDouble(0,objname,OBJPROP_PRICE,1,price);
}
else
{
datetime Time[];
ArraySetAsSeries(Time,true);
CopyTime(Symbol(),Period(),0,start_index+count,Time);
ObjectCreate(0,objname,OBJ_TREND,0,Time[start_index],price,Time[start_index+count-1],price);
ObjectSetInteger(0,objname,OBJPROP_RAY_LEFT,0);
ObjectSetInteger(0,objname,OBJPROP_RAY_RIGHT,0);
ObjectSetInteger(0,objname,OBJPROP_COLOR,C'0x00,0x00,0xFF');
ObjectSetInteger(0,objname,OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,objname,OBJPROP_WIDTH,2);
}
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+double Support(int time_interval,bool fixed_tod,int hh,int mm,bool draw,int shift)
{
int start_index=shift;
int count=time_interval/PeriodSeconds();
if(fixed_tod)
{
datetime start_time;
datetime Time[];
ArraySetAsSeries(Time,true);
CopyTime(Symbol(),Period(),0,Bars(Symbol(),Period())-count,Time);
if(shift==0)
start_time=TimeCurrent();
else
start_time=Time[shift-1];
datetime dt=StringToTime(TimeToString(start_time,TIME_DATE)+" "+(string)hh+":"+(string)mm); //closest time hh:mmif(dt>start_time)
dt-=86400; //go 24 hours backint dt_index = iBarShift(Symbol(), Period(), dt, true);
datetime dt2 = dt;
while(dt_index<0 && dt>Time[Bars(Symbol(),Period())-1-count]) //bar not found => look a few days back
{
dt-=86400; //go 24 hours back
dt_index=iBarShift(Symbol(),Period(),dt,true);
}
if(dt_index<0) //still not found => find nearest bar
dt_index =iBarShift(Symbol(), Period(), dt2, false);
start_index=dt_index+1; //bar after S/R opens at dt
}
double _Low[];
ArraySetAsSeries(_Low,true);
CopyLow(Symbol(),Period(),start_index,count,_Low);
double ret=_Low[ArrayMinimum(_Low,0,count)];
if(draw) DrawLine("Support",ret,count,start_index);
return(ret);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+double Resistance(int time_interval,bool fixed_tod,int hh,int mm,bool draw,int shift)
{
int start_index=shift;
int count=time_interval/PeriodSeconds();
if(fixed_tod)
{
datetime start_time;
datetime Time[];
ArraySetAsSeries(Time,true);
CopyTime(Symbol(),Period(),0,Bars(Symbol(),Period())-count,Time);
if(shift==0)
start_time=TimeCurrent();
else
start_time=Time[shift-1];
datetime dt=StringToTime(TimeToString(start_time,TIME_DATE)+" "+(string)hh+":"+(string)mm); //closest time hh:mmif(dt>start_time)
dt-=86400; //go 24 hours backint dt_index = iBarShift(Symbol(), Period(), dt, true);
datetime dt2 = dt;
while(dt_index<0 && dt>Time[Bars(Symbol(),Period())-1-count]) //bar not found => look a few days back
{
dt-=86400; //go 24 hours back
dt_index=iBarShift(Symbol(),Period(),dt,true);
}
if(dt_index<0) //still not found => find nearest bar
dt_index =iBarShift(Symbol(), Period(), dt2, false);
start_index=dt_index+1; //bar after S/R opens at dt
}
double _High[];
ArraySetAsSeries(_High,true);
CopyHigh(Symbol(),Period(),start_index,count,_High);
double ret=_High[ArrayMaximum(_High,0,count)];
if(draw) DrawLine("Resistance",ret,count,start_index);
return(ret);
}
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
SetIndexBuffer(0,Buffer1);
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
PlotIndexSetInteger(0,PLOT_ARROW,242);
SetIndexBuffer(1,Buffer2);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
PlotIndexSetInteger(1,PLOT_ARROW,241);
//initialize myPoint
myPoint=Point();
if(Digits()==5 || Digits()==3)
{
myPoint*=10;
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
int limit=rates_total-prev_calculated;
if(limit<=0) return(rates_total);
//--- counting from 0 to rates_totalArraySetAsSeries(Buffer1,true);
ArraySetAsSeries(Buffer2,true);
//--- initial zeroif(prev_calculated<1)
{
ArrayInitialize(Buffer1,0);
ArrayInitialize(Buffer2,0);
}
else
limit++;
//--- main loopfor(int i=limit-1; i>=0; i--)
{
if(i>=MathMin(5000-1,rates_total-1-50)) continue; //omit old rates//Indicator Buffer 1 (Sell)if(high[i]==Resistance(Interval*PeriodSeconds(),false,00,00,false,i)
&& close[i]<open[i]) //Condition for Sell
{
Buffer1[i]=high[i]; //Set indicator value at Candlestick Highif(i==1 && time[1]!=time_alert)
myAlert("indicator","Sell"); //Alert on next bar open
time_alert=time[1];
}
else
{
Buffer1[i]=0;
}
//Indicator Buffer 2 (Buy)if(low[i]==Support(Interval*PeriodSeconds(),false,00,00,false,i)
&& close[i]>open[i]) //Condition for Buy
{
Buffer2[i]=low[i]; //Set indicator value at Candlestick Lowif(i==1 && time[1]!=time_alert)
myAlert("indicator","Buy"); //Alert on next bar open
time_alert=time[1];
}
else
{
Buffer2[i]=0;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
Thank you Razak, the updated code has successfully compiled. Let me test it and see whether it functions as explained in your introduction.
I have backtested the indicator using the default settings but don't see any buy and sell arrows on the chart. Please review the code if this error is confirmed. Thank you
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Breeding and order prevail here! :-)
...that was buttery soft with pre-Christmas charm ..at least I thought so
I took this Indi and reprogrammed it.
Distilled from 286 confusing lines to only 151 clear lines, and can also do more.
Now it is a very simple indicator that has a lot of potential in conjunction with, for example, an EMA 50 (Steven Primo's buy/sell line) and a suitable exit.
This indicator is a good candidate for my homepage, which will go online at the beginning of next year.
I took this Indi and reprogrammed it.
Distilled down from 286 confusing lines to just 151 clear lines, and can do more.
Now it is a very simple indicator which, in conjunction with an EMA 50 (Steven Primo's buy/sell line) and a suitable exit, for example, definitely has potential.
This indicator is a good candidate for my homepage, which will go online at the beginning of next year.
Super nice of you! I tried it out straight away and it works perfectly. Thank you very much!
there are errors on compilation in meta editor. please fix if possible. thank you for the free offer of such a potentially great indicator concept
this is code modified for no error..
this is code modified for no error..
Thank you Razak, the updated code has successfully compiled. Let me test it and see whether it functions as explained in your introduction.
I have backtested the indicator using the default settings but don't see any buy and sell arrows on the chart. Please review the code if this error is confirmed. Thank you