I'm trying to create a scanner which should met 2 criteria
(i) Last price should be HIGH or LOW of lat 10 bars
(ii) Breakout should occur only by 3 continuous up or down bars
I've written following code for it (see below)
Now problem is that ideally it should work on every bar but it stop after generating a signal, will anyone have a look and sometimes it even respond even if conditions are met
//+------------------------------------------------------------------+//| //| Akshay Jain |//| |//+------------------------------------------------------------------+#property copyright"Akshay Jain"#property link""#property version"1.00"#property strict//--- input parametersbool New_Bar=false; // Flag of a new barbool RefreshRates();
//--------------------------------------------------------------------int start() // Special funct. start()
{
double Minimum1;
double Maximum1; // Minimal price//--------------------------------------------------------------------
Fun_New_Bar(); // Function callif (New_Bar==false) // If bar is not new..return(0); // ..return//--------------------------------------------------------------------int S_Bars=10; // Amount of barsint upbars, downbars;
if (Close[0] > Open[0] && Close[1] > Open[1] && Close[2] > Open[2])
upbars = 3;
if (Close[0] < Open[0] && Close[1] < Open[1] && Close[2] < Open[2])
downbars = 3;
int Ind_max1 =ArrayMaximum(High,S_Bars,1);// Bar index of max. price int Ind_min1 =ArrayMinimum(Low, S_Bars,1);// Bar index of min. price
Maximum1=High[Ind_max1]; // Desired max. price
Minimum1=Low[Ind_min1]; // Desired min. price ObjectCreate("BuyLine1",OBJ_HLINE,0,iTime(NULL,0,0),Maximum1,0,0,0,0);
ObjectSet("BuyLine1",OBJPROP_COLOR,LimeGreen);
ObjectCreate("SellLine1",OBJ_HLINE,0,iTime(NULL,0,0),Minimum1,0,0,0,0);
ObjectSet("SellLine1",OBJPROP_COLOR,Red);
//----Looping through subject and Alertif ( New_Bar == true)
{
if(Bid >= Maximum1 && upbars == 3 ) // Buy Alert 1
{
Alert(Symbol()," Last 10 Bars High " , Maximum1 ," is crossed at " ,TimeToStr(TimeLocal(),TIME_SECONDS));
SendNotification (Symbol()+ " Last 10 Bars High " + Maximum1 + " is crossed at " + TimeToStr(TimeLocal(),TIME_SECONDS));
string subject = (Symbol()+ " Last 10 Bars High " + Maximum1 + " is crossed at " + TimeToStr(TimeLocal(),TIME_SECONDS));
string some_text = "";
SendMail( subject, some_text);
}
if(Bid <= Minimum1 && downbars == 3 ) // Sell Alert 1
{
Alert(Symbol()," Last 10 Bars Low " , Minimum1 ," is crossed at " ,TimeToStr(TimeLocal(),TIME_SECONDS));
SendNotification (Symbol()+ " Last 10 Bars Low " + Minimum1 + " is crossed at " + TimeToStr(TimeLocal(),TIME_SECONDS));
string subject = (Symbol()+ " Last 10 Bars Low " + Minimum1 + " is crossed at " + TimeToStr(TimeLocal(),TIME_SECONDS));
string some_text = "";
SendMail( subject, some_text);
}
Comment(upbars," UP Bars","\n", downbars," DOWN Bars ");
}
return(0); // Exit start()
}
//--------------------------------------------------------------------void Fun_New_Bar() // Funct. detecting ..
{ // .. a new barstaticdatetime New_Time=0; // Time of the current bar
New_Bar=false; // No new barif(New_Time!=Time[0]) // Compare time
{
New_Time=Time[0]; // Now time is so
New_Bar=true; // A new bar detected
}
return;
}
//--------------------------------------------------------------------
See the image, ideally it should generate a signal on new bar, i.e; below the low of next bar but it is not happening. Alert is generated only on the previous bar low
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.
Hello Guys,
I'm trying to create a scanner which should met 2 criteria
(i) Last price should be HIGH or LOW of lat 10 bars
(ii) Breakout should occur only by 3 continuous up or down bars
I've written following code for it (see below)
Now problem is that ideally it should work on every bar but it stop after generating a signal, will anyone have a look and sometimes it even respond even if conditions are met
See the image, ideally it should generate a signal on new bar, i.e; below the low of next bar but it is not happening. Alert is generated only on the previous bar low