Download MetaTrader 5

MT4 Scanner need a further look..!!

To add comments, please log in or register
Do you keep a blog? Place a link to MQL5.community there and make money!
Akshay
48
Akshay 2016.01.05 11:59 

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

//+------------------------------------------------------------------+
//|                                       
//|                                                      Akshay Jain |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Akshay Jain"
#property link      ""
#property version   "1.00"
#property strict

//--- input parameters

bool New_Bar=false;                             // Flag of a new bar
bool RefreshRates();
//--------------------------------------------------------------------
int start()                                     // Special funct. start()
  {
   
   double Minimum1;
   double Maximum1;                              // Minimal price
   
//--------------------------------------------------------------------
   Fun_New_Bar();                               // Function call
   if (New_Bar==false)                          // If bar is not new..
      return(0);                                   // ..return
//--------------------------------------------------------------------

  int S_Bars=10;                       // Amount of bars
   int 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 Alert

if (  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 bar
   static datetime New_Time=0;                  // Time of the current bar
   New_Bar=false;                               // No new bar
   if(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

Scan

To add comments, please log in or register