Help me, problem with indicator.

Back to topics list To post a new topic, please log in or register
avatar
5
bluborja75 2015.10.28 22:26
 
Hi, I need help, this below is an indicator that is used to recognize certain patterns, the problem is that only recognizes the patterns that form the previous candle, but I wish that the scope of its action was around the time that take into account all the candles.
Simply put, instead of 1, in the "LOOPBACK" What should I put on making sure that the indicator takes into account all the candles?

Thank you.


//+------------------------------------------------------------------+
//|                                        Oracle - L'Impiccione.mq4 |
//|                                                Peperlizio - 2012 |
//|                                   Multicross Pattern Recognition |
//+------------------------------------------------------------------+
#property copyright "Peperlizio"
#property indicator_chart_window



//+------------------------------------------------------------------+
//| Extern Variables                                                 |
//+------------------------------------------------------------------+
extern string A_________     = "How many bars to check? 1=last one, 2=last 2 bars, etc.";
extern int    Loopback       = 1;
extern string B_________     = "Considers only Best Patterns";
extern bool   The_Best       = false;
extern string C_________     = "Bollinger Settings";
extern int    period         = 20;
extern int    Deviation      = 2;
extern int    Applied_Price  = 0;
extern string D_________     = "Text Settings";
extern int    Text_Size      = 8;
extern color  Text_Color     = Gray;
extern color  Bullish_Color  = LimeGreen;
extern color  Bearish_Color  = Red;

//+------------------------------------------------------------------+
//| Internal Variables                                               |
//+------------------------------------------------------------------+
int    Rods = 3;         //Numbers of Rods for each Cross Pair                                     //Setta il numero di righe per casella
string symbol[20];       //Cross Symbol Array
string symbolsec[20];    //Second Cross Symbol Array
int    Xdist[10];        //X distance Array
int    Ydist[50];        //Y distance Array
int    Timeframe[10];    //Timframe Array

//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
int    i, ii, X1, X2, X3, X4, X5, X6, X7, X8, X9, Y, CurrNum;
int    X_Adjust = 0;
int    S_Adjust = 16;
string Separator = "_______________________________________________________________";
bool   flag;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
 
//---symbol Array definition                                                                       //Inserire i Cross da esaminare in questo Array
   symbol[1]  = "EURUSD";
   symbol[2]  = "GBPUSD";
   symbol[3]  = "AUDUSD";
   symbol[4]  = "USDCAD";
   symbol[5]  = "USDJPY";
   symbol[6]  = "EURGBP";
   symbol[7]  = "";
   symbol[8]  = "";
   symbol[9]  = "";
   symbol[10] = "";
   symbol[11] = "";
   symbol[12] = "";
   symbol[13] = "";
   symbol[14] = "";
   symbol[15] = "";
   symbol[16] = "";
   symbol[17] = "";
   symbol[18] = "";
   symbol[19] = "";
   symbol[20] = "";

//---Timeframe Array definition
   Timeframe[1] = 1;
   Timeframe[2] = 5;
   Timeframe[3] = 15;
   Timeframe[4] = 30;
   Timeframe[5] = 60;
   Timeframe[6] = 240;
   Timeframe[7] = 1440;
   Timeframe[8] = 10080;
   Timeframe[9] = 43200;
  
//---Set adjust text variables
   if (Text_Size<6)  Text_Size=6;
   if (Text_Size>15) Text_Size=15;
   X_Adjust = (Text_Size-10)*10;
   S_Adjust = ((Text_Size-1)*2.5)-3;
   X1 = 100 + Text_Size * 0  + X_Adjust;
   X2 = 100 + Text_Size * 10  + X_Adjust;
   X3 = 100 + Text_Size * 20 + X_Adjust;
   X4 = 100 + Text_Size * 30 + X_Adjust; 
   X5 = 100 + Text_Size * 40 + X_Adjust;
   X6 = 100 + Text_Size * 50 + X_Adjust;
   X7 = 100 + Text_Size * 60 + X_Adjust;
   X8 = 100 + Text_Size * 70 + X_Adjust;
   X9 = 100 + Text_Size * 80 + X_Adjust;
  
//---Xdist Array definition
   Xdist[1] = X1;
   Xdist[2] = X2;
   Xdist[3] = X3;
   Xdist[4] = X4;
   Xdist[5] = X5;
   Xdist[6] = X6;
   Xdist[7] = X7;
   Xdist[8] = X8;
   Xdist[9] = X9;  
  
//---Write first Column  
   ii=0;
   for (i=1; i<=20; i++)                                                                            //i<=20  Modificare con il numero Array!
    {
     if (MarketInfo(symbol[i],MODE_BID)!=0)
      {
       symbolsec[ii]=symbol[i];
       Ydist[ii]=(40+Text_Size+S_Adjust*ii)*(Rods+1)-(600/Text_Size);
       Set_Label("txt"+ii, 0, Ydist[ii], 5, symbolsec[ii], Text_Color, Text_Size, "");
       Set_Label("separator1"+ii, 0, Ydist[ii]-Text_Size*1.5, 5, Separator, Text_Color, Text_Size, "");        //3 lines cause Label length limitation
       Set_Label("separator2"+ii, 0, Ydist[ii]-Text_Size*1.5, X2, Separator, Text_Color, Text_Size, "");
       Set_Label("separator3"+ii, 0, Ydist[ii]-Text_Size*1.5, X5+Text_Size*2, Separator, Text_Color, Text_Size, "");      
       ii++;
      }
    }
   CurrNum=ii;                                                                                                 //CurrNum - Number of valid Cross

//---Write first Rod
   Set_Label("txtm1" , 0, Ydist[1]-S_Adjust*2*Rods, X1, "M1" , Text_Color, Text_Size, "");
   Set_Label("txtm5" , 0, Ydist[1]-S_Adjust*2*Rods, X2, "M5" , Text_Color, Text_Size, "");
   Set_Label("txtm15", 0, Ydist[1]-S_Adjust*2*Rods, X3, "M15", Text_Color, Text_Size, "");
   Set_Label("txtm30", 0, Ydist[1]-S_Adjust*2*Rods, X4, "M30", Text_Color, Text_Size, "");
   Set_Label("txth1" , 0, Ydist[1]-S_Adjust*2*Rods, X5, "H1" , Text_Color, Text_Size, "");
   Set_Label("txth4" , 0, Ydist[1]-S_Adjust*2*Rods, X6, "H4" , Text_Color, Text_Size, "");
   Set_Label("txtd1" , 0, Ydist[1]-S_Adjust*2*Rods, X7, "D1" , Text_Color, Text_Size, "");
   Set_Label("txtw1" , 0, Ydist[1]-S_Adjust*2*Rods, X8, "W1" , Text_Color, Text_Size, "");
   Set_Label("txtmn" , 0, Ydist[1]-S_Adjust*2*Rods, X9, "MN" , Text_Color, Text_Size, "");

//---Draw vertical line
  flag=false;
  for(i=1; i<=CurrNum*Text_Size; i++)
   {
    for(ii=1; ii<=9; ii++)
     {
      Y = Ydist[1]-S_Adjust*2*Rods-Text_Size*2+i*10;
      if (Y > Ydist[CurrNum-1]+Text_Size*4) flag=true;
      Set_Label("vert"+i+ii , 0, Y, Xdist[ii]-Text_Size/2, "|" , Text_Color, Text_Size, "");
     }
    if (flag==true) break;
   }
  
   return(0);
  } 


 
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll();
   return(0);
  }
 
 
 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   Draw_Rod(Rods, CurrNum);
   return(0);
  }
//+------------------------------------------------------------------+









//+------------------------------------------------------------------+
//| Functions                                                        |
//+------------------------------------------------------------------+




//+------------------------------------------------------------------+
//| Set_Label                                                        |
//+------------------------------------------------------------------+
void Set_Label(string Name, int Corner, int Ycoord, int Xcoord, string Text, color Coltxt, int Fonsize, string Fontz)
  { 
   int Txtsize=Text_Size;
   if (Text_Size<11) Fonsize=11;
   if (Fontz=="") Fontz="Arial";
   if (ObjectFind(Name)<0)
    {
     ObjectCreate(Name, OBJ_LABEL, 0, 0, 0);
     ObjectSet(Name, OBJPROP_CORNER, Corner);
     ObjectSet(Name, OBJPROP_YDISTANCE, Ycoord);
     ObjectSet(Name, OBJPROP_XDISTANCE, Xcoord);
     ObjectSetText(Name, Text, Txtsize, Fontz, Coltxt);
    }
   else
    {
     ObjectSet(Name, OBJPROP_CORNER, Corner);
     ObjectSet(Name, OBJPROP_YDISTANCE, Ycoord);
     ObjectSet(Name, OBJPROP_XDISTANCE, Xcoord);
     ObjectSetText(Name, Text, Txtsize, "Arial", Coltxt);
    }
   return;
  }


 
//+------------------------------------------------------------------+
//| Draw_Rod                                                         |
//+------------------------------------------------------------------+
void Draw_Rod(int Rods_, int CurrNum_)
  {
   int i, i2, i3,b;
   for (i=1; i<=CurrNum_; i++)
    {
     for (i2=1; i2<=Rods_; i2++)
      {
       for (i3=1; i3<=9; i3++)
        {
         GetPattern(i,i2,i3);
        }
      }
    }
   return;
  }
 
 

//+------------------------------------------------------------------+
//| GetPattern                                                       |
//+------------------------------------------------------------------+
int GetPattern(int Cross, int Rod, int TFrame)
  {
   double O0, O1, O2, O3, C0, C1, C2, C3, L0, L1, L2, L3, H0, H1, H2, H3, BBUP, BBDW, Step, Multiplier;
   bool   Flag;
  
//---Initialization
   for (int shift = 0; shift < Loopback; shift++)
    {     
     O0   = iOpen  (symbol[Cross],Timeframe[TFrame],shift+1);
     O1   = iOpen  (symbol[Cross],Timeframe[TFrame],shift+2);
     O2   = iOpen  (symbol[Cross],Timeframe[TFrame],shift+3);
     O3   = iOpen  (symbol[Cross],Timeframe[TFrame],shift+4);
     H0   = iHigh  (symbol[Cross],Timeframe[TFrame],shift+1);
     H1   = iHigh  (symbol[Cross],Timeframe[TFrame],shift+2);
     H2   = iHigh  (symbol[Cross],Timeframe[TFrame],shift+3);
     H3   = iHigh  (symbol[Cross],Timeframe[TFrame],shift+4);
     L0   = iLow   (symbol[Cross],Timeframe[TFrame],shift+1);
     L1   = iLow   (symbol[Cross],Timeframe[TFrame],shift+2);
     L2   = iLow   (symbol[Cross],Timeframe[TFrame],shift+3);
     L3   = iLow   (symbol[Cross],Timeframe[TFrame],shift+4);
     C0   = iClose (symbol[Cross],Timeframe[TFrame],shift+1);
     C1   = iClose (symbol[Cross],Timeframe[TFrame],shift+2);
     C2   = iClose (symbol[Cross],Timeframe[TFrame],shift+3);
     C3   = iClose (symbol[Cross],Timeframe[TFrame],shift+4);
     BBUP = iBands (symbol[Cross],Timeframe[TFrame],period,Deviation,0,Applied_Price,1,shift+1);
     BBDW = iBands (symbol[Cross],Timeframe[TFrame],period,Deviation,0,Applied_Price,2,shift+1);    
     Flag = false;
     Step = (Ydist[2]-Ydist[1])/Rods;
     Multiplier = Rod-1;
                   
//---Rod 1    
     if (Rod==1)
      {
       //---Bullish Harami
       if ((O1>C1)&&(C0>O0) && (C0<O1)&&(C1<=O0) && ((C0-O0)<(O1-C1)/2))
        {
         Flag=true;
         if (The_Best==true && L0<L1) Flag=false;                                           //Precision Control - Absolute MIN on Bearish Bar
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Harami", Bullish_Color, Text_Size/1.5, "");
        }
                              
       //---Bullish Piercing - Piercing Line
       if ((O1>C1)&&(C0>O0) && O1-(O1-C1)/2<=C0 && (C0<O1) && ((C0-O0)/(0.001+(H0-L0))>0.6))
        {
         Flag=true;
         if (The_Best==true && L0>L1) Flag=false;                                           //Precision Control - Absolute MIN on Bullish Bar
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Piercing", Bullish_Color, Text_Size/1.5, "");
        }
                      
       //---Bullish Engulfing
       if ((O1>C1)&&(C0>O0) && (C0>=O1)&&(C1>=O0))
        {
         Flag=true;
         if (The_Best==true && L0>L1) Flag=false;                                           //Precision Control - Absolute MIN on Bullish Bar
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Engulfing", Bullish_Color, Text_Size/1.5, "");
        }
                 
       //---Bearish Harami
       if ((C1>O1)&&(O0>C0) && (C0>O1)&&(C1>=O0) && ((O0-C0)<(C1-O1)/2))
        {
         Flag=true;
         if (The_Best==true && H0>H1) Flag=false;                                           //Precision Control - Absolute MAX on Bullish Bar
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Harami", Bearish_Color, Text_Size/1.5, "");
        }
                 
       //---Bearish Piercing - Dark Cloud Cover
       if ((C1>O1)&&(O0>C0) && C1-(C1-O1)/2>=C0 && (C0>O1) && ((O0-C0)/(0.001+(H0-L0))>0.6))
        {
         Flag=true;
         if (The_Best==true && H0<H1) Flag=false;                                           //Precision Control - Absolute MAX on Bearish Bar
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Piercing", Bearish_Color, Text_Size/1.5, "");
        }
                
       //---Bearish Engulfing
       if ((C1>O1)&&(O0>C0) && (C0<=O1)&&(C1<=O0))
        {
         Flag=true;
         if (The_Best==true && H0<H1) Flag=false;                                           //Precision Control - Absolute MAX on Bearish Bar
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Engulfing", Bearish_Color, Text_Size/1.5, "");
        }
                     
       //---No Match
       if (Flag==false) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "", Bearish_Color, Text_Size/1.5, "");
      }
                      
//---Rod 2    
     if (Rod==2)
      {
       //---Hammer
       if ((L0<=L1)&&(L0<L2) && (H0-L0)>=3*MathAbs(O0-C0) && (C0-L0)/(0.001+H0-L0)>=0.6 && (O0-L0)/(0.001+H0-L0)>=0.6)
        {
         Flag=true;
         if (The_Best==true && O0>C0) Flag=false;                                           //Precision Control - Bullish Hammer Bar after Down Trend
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Hammer", Bullish_Color, Text_Size/1.5, "");
        }
       
       //---Inverted Hammer
       if ((L0<=L1)&&(L0<L2) && (H0-L0)>=3*MathAbs(O0-C0) && (H0-C0)/(0.001+H0-L0)>=0.6 && (H0-O0)/(0.001+H0-L0)>=0.6)
        {
         Flag=true;
         if (The_Best==true && O0>C0) Flag=false;                                           //Precision Control - Bullish Hammer Bar after Down Trend
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "In Hammer", Bullish_Color, Text_Size/1.5, "");
        }
       
       //---Shooting Star
       if ((H0>=H1)&&(H0>H2) && (H0-L0)>=3*MathAbs(O0-C0) && (H0-C0)/(0.001+H0-L0)>=0.6 && (H0-O0)/(0.001+H0-L0)>=0.6)
        {
         Flag=true;
         if (The_Best==true && O0>C0) Flag=false;                                           //Precision Control - Bearish Hammer Bar after Up Trend
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Shoot Star", Bearish_Color, Text_Size/1.5, "");
        }
       
       //---Hanging Man
       if ((H0>=H1)&&(H0>H2) && (H0-L0)>=3*MathAbs(O0-C0) && (C0-L0)/(0.001+H0-L0)>=0.6 && (O0-L0)/(0.001+H0-L0)>=0.6)
        {
         Flag=true;
         if (The_Best==true && O0>C0) Flag=false;                                           //Precision Control - Bearish Hammer Bar after Up Trend
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Hang Man", Bearish_Color, Text_Size/1.5, "");
        }
       
       //---No Match
       if (Flag==false) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "", Bearish_Color, Text_Size/1.5, "");
      }
                
//---Rod 3    
     if (Rod==3)
      {
       //---Bullish Reversal Bar
       if ((L0<=L1)&&(L0<L2) && (O0-L0)<=(H0-L0)/4&&(H0-C0)<=(H0-L0)/4 && BBDW>=O0&&BBDW<=C0)
        {
         Flag=true;
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Reversal", Bullish_Color, Text_Size/1.5, "");
        }
       
       //---Bearish Reversal Bar
       if ((H0>=H1)&&(H0>H2) && (H0-O0)<=(H0-L0)/4&&(C0-L0)<=(H0-L0)/4 && BBUP<=O0&&BBUP>=C0)
        {
         Flag=true;
         if (Flag==true) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "Reversal", Bearish_Color, Text_Size/1.5, "");
        }
       
       //---No Match
       if (Flag==false) Set_Label(Rod+symbol[Cross]+TFrame, 0, Ydist[Cross-1]+Step*Multiplier, Xdist[TFrame], "", Bearish_Color, Text_Size/1.5, "");
      }
     
//---End of for loop         
    }
   return(0);
  }

avatar
3134
qjol 2015.10.29 04:05 #
 
WindowBarsPerChart()

but to be honest, i don't understand the purpose of using the entire chart

avatar
5
bluborja75 2015.10.29 11:08 #
 
Thank you for having responded to me, I tried to enter your suggestion but to me it reports the following error:
"WindowBarsPerChart - constant expected".
avatar
5
bluborja75 2015.10.29 11:36 #
 
In place of:
"// Initialization ---
    for (int shift = 0; shift <Loopback; shift ++)
     {"
What should I enter?
avatar
3134
qjol 2015.10.29 11:39 #
 
for (int shift = 0; shift <WindowBarsPerChart(); shift ++)

avatar
5
bluborja75 2015.10.29 12:27 #
 
I tried to enter but when load indicator mt4 crashes.
At this point, I ask another for help.
Simply put, it could use an indicator that recognizes patterns and on a separate window, the indicator shows which currencies, the pattern has been formed.

As well as the example below.



Back to topics list  

To add comments, please log in or register