I want to create a buffer to bring the result of the formed pattern, but it doesn't work.

 

Friends,

I want to create a buffer to bring the result of the formed pattern, I put the candlepadrao[], but it doesn't work.

help me?



//+------------------------------------------------------------------+
//|                                         Candlestick Patterns.mq5 |
//|                                                         VDV Soft |
//|                                                 vdv_2001@mail.ru |
//+------------------------------------------------------------------+
#property copyright "VDV Soft"
#property link      "vdv_2001@mail.ru"
#property version   "1.00"

#include <candlestickType.mqh>

#property indicator_chart_window
#property indicator_buffers 1
//--- plot 1
#property indicator_label1  ""
#property indicator_type1   DRAW_LINE
#property indicator_color1  Blue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_buffers 5
#property indicator_plots   1
//--- input parameters
input int   InpPeriodSMA   =10;         // Period of averaging
input bool  InpAlert       =false;       // Enable. signal
input int   InpCountBars   =1000;       // Amount of bars for calculation
input color InpColorBull   =DodgerBlue; // Color of bullish models
input color InpColorBear   =Tomato;     // Color of bearish models
input bool  InpCommentOn   =true;       // Enable comment
input int   InpTextFontSize=8;         // Font size
//---- indicator buffers
//--- indicator handles
//--- list global variable
string prefix="Patterns ";
datetime CurTime=0;
double  padraoVela[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,padraoVela,INDICATOR_CALCULATIONS);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- We wait for a new bar
   if(rates_total==prev_calculated)
     {
      return(rates_total);
     }

////--- delete object
   string objname,comment;
//   for(int i=ObjectsTotal(0,0,-1)-1;i>=0;i--)
//     {
//      objname=ObjectName(0,i);
//      if(StringFind(objname,prefix)==-1)
//         continue;
//      else
//         ObjectDelete(0,objname);
//     }
   int objcount=0;
//---
   int limit;
   if(prev_calculated==0)
     {
      if(InpCountBars<=0 || InpCountBars>=rates_total)
         limit=InpPeriodSMA*2;
      else
         limit=rates_total-InpCountBars;
     }
   else
      limit=prev_calculated-1;
   if(!SeriesInfoInteger(Symbol(),0,SERIES_SYNCHRONIZED))
      return(0);
// Variable of time when the signal should be given
   CurTime=time[rates_total-2];
// Determine the market (forex or not)
 
   bool _forex=false;
   if(SymbolInfoInteger(Symbol(),SYMBOL_TRADE_CALC_MODE)==(int)SYMBOL_CALC_MODE_FOREX) _forex=true;
   bool _language = (TerminalInfoString(TERMINAL_LANGUAGE)=="Russian") ? true : false; // Russian language of the terminal
//--- calculate Candlestick Patterns
   for(int i=limit;i<rates_total-1;i++)
     {
      CANDLE_STRUCTURE cand1;
      if(!RecognizeCandle(_Symbol,_Period,time[i],InpPeriodSMA,cand1))
         continue;
/* Check patterns on one candlestick */
 
      //------      
      // Inverted Hammer, the bullish model
      if(cand1.trend==DOWN && // check direction of trend
         cand1.type==CAND_INVERT_HAMMER) // the "Inverted Hammer" check
        {
         padraoVela[i]=1;
         comment=_language?"Inverted Hammer (Bull)":"Martelo INV(A) "+padraoVela[i];
         DrawSignal(prefix+"Invert Hammer the bull model"+string(objcount++),cand1,InpColorBull,comment);
        }
      // Hanging Man, the bearish model
      if(cand1.trend==UPPER && // check direction of trend
         cand1.type==CAND_HAMMER) // the "Hammer" check
        {
        padraoVela[i]=2;
         comment=_language?"Hanging Man (Bear)":"Enforcado(B) "+padraoVela[i];
         DrawSignal(prefix+"Hanging Man the bear model"+string(objcount++),cand1,InpColorBear,comment);
        }
      //------      
      // Hammer, the bullish model
      if(cand1.trend==DOWN && // check direction of trend
         cand1.type==CAND_HAMMER) // the "Hammer" check
        {
         padraoVela[i]=3;
         comment=_language?"Hammer (Bull)":"Martelo (A) "+padraoVela[i];
         DrawSignal(prefix+"Hammer, the bull model"+string(objcount++),cand1,InpColorBull,comment);
        }

/* Check of patters with two candlesticks */
 
      CANDLE_STRUCTURE cand2;
      cand2=cand1;
      if(!RecognizeCandle(_Symbol,_Period,time[i-1],InpPeriodSMA,cand1))
         continue;

      //------      
      // Shooting Star, the bearish model
      if(cand1.trend==UPPER && cand2.trend==UPPER && // check direction of trend
         cand2.type==CAND_INVERT_HAMMER) // the "Inverted Hammer" check
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close<=cand2.open) // close 1 is less than or equal to open 1
              {               
              padraoVela[i]=4;
         comment=_language?"Shooting Star (Bear)":"Estrela Disparo (B)"+padraoVela[i];
               DrawSignal(prefix+"Shooting Star the bear model"+string(objcount++),cand2,InpColorBear,comment);
              }
           }
         else
           {
            if(cand1.close<cand2.open && cand1.close<cand2.close) // 2 candlestick is cut off from 1
              {               
              padraoVela[i]=4;
         comment=_language?"Shooting Star (Bear)":"Estrela Disparo (B)"+padraoVela[i];
               DrawSignal(prefix+"Shooting Star the bear model"+string(objcount++),cand2,InpColorBear,comment);
              }
           }
        }
      // ------      
      // Belt Hold, the bullish
      if(cand2.trend==DOWN && cand2.bull && !cand1.bull && // check direction of trend and direction of candlestick
         cand2.type==CAND_MARIBOZU_LONG && // the "long Maribozu" check
         cand1.bodysize<cand2.bodysize && cand2.close<cand1.close) // body of the first candlestick is smaller than body of the second one, close price of the second candlestick is lower than the close price of the first one
        {
         
         if(!_forex)// if it's not forex
           {            
           padraoVela[i]=5;
         comment=_language?"Belt Hold (Bull)":"Cinto Seguro(A) "+padraoVela[i];
            DrawSignal(prefix+"Belt Hold the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
           }
        }
      // Belt Hold, the bearish model
      if(cand2.trend==UPPER && !cand2.bull && cand1.bull && // check direction of trend and direction of candlestick
         cand2.type==CAND_MARIBOZU_LONG && // the "long Maribozu" check
         cand1.bodysize<cand2.bodysize && cand2.close>cand1.close) // body of the first candlestick is lower than body of the second one; close price of the second candlestick is higher than that of the first one
        {
         
         if(!_forex)// if it's not forex
           {            
             padraoVela[i]=6;
         comment=_language?"Belt Hold (Bear)":"Cinto Seguro(B) "+padraoVela[i];
            DrawSignal(prefix+"Belt Hold the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
           }
        }
      //------      
      // Engulfing, the bullish model
      if(cand1.trend==DOWN && !cand1.bull && cand2.trend==DOWN && cand2.bull && // check direction of trend and direction of candlestick
         cand1.bodysize<cand2.bodysize) // body of the third candlestick is bigger than that of the second one
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close>=cand2.open && cand1.open<cand2.close) // body of the first candlestick is inside of body of the second one
              {               
              padraoVela[i]=7;
         comment=_language?"Engulfing (Bull)":"Engolfo (A) "+padraoVela[i];
               DrawSignal(prefix+"Engulfing the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
              }
           }
         else
           {
            if(cand1.close>cand2.open && cand1.open<cand2.close) // body of the first candlestick inside of body of the second candlestick
              {               
              padraoVela[i]=7;
         comment=_language?"Engulfing (Bull)":"Engolfo (A) "+padraoVela[i];
               DrawSignal(prefix+"Engulfing the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
              }
           }
        }
      // Engulfing, the bearish model
      if(cand1.trend==UPPER && cand1.bull && cand2.trend==UPPER && !cand2.bull && // check direction and direction of candlestick
         cand1.bodysize<cand2.bodysize) // body of the third candlestick is bigger than that of the second one
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close<=cand2.open && cand1.open>cand2.close) // body of the first candlestick is inside of body of the second one
              {               
              padraoVela[i]=8;
         comment=_language?"Engulfing (Bear)":"Engolfo (B) "+padraoVela[i];
               DrawSignal(prefix+"Engulfing the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
              }
           }
         else
           {
            if(cand1.close<cand2.open && cand1.open>cand2.close) // close 1 is lower or equal to open 2; or open 1 is higher or equal to close 2
              {               
              padraoVela[i]=8;
         comment=_language?"Engulfing (Bear)":"Engolfo (B) "+padraoVela[i];
               DrawSignal(prefix+"Engulfing the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
              }
           }
        }
      //------      
      // Harami Cross, the bullish model
      if(cand1.trend==DOWN && !cand1.bull && // check direction of trend and direction of candlestick
         (cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && cand2.type==CAND_DOJI) // check of "long" first candlestick and Doji candlestick
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close<=cand2.open && cand1.close<=cand2.close && cand1.open>cand2.close) // Doji is inside of body of the first candlestick
              {               
               padraoVela[i]=9;
               comment=_language?"Harami Cross (Bull)":"Bani Cruzado(A) "+padraoVela[i];
               DrawSignal(prefix+"Harami Cross the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
              }
           }
         else
           {
            if(cand1.close<cand2.open && cand1.close<cand2.close && cand1.open>cand2.close) // Doji is inside of body of the first candlestick
              {               
                padraoVela[i]=9;
               comment=_language?"Harami Cross (Bull)":"Bani Cruzado(A) "+padraoVela[i];
               DrawSignal(prefix+"Harami Cross the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
              }
           }
        }
      // Harami Cross, the bearish model
      if(cand1.trend==UPPER && cand1.bull && // check direction of trend and direction of candlestick
         (cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && cand2.type==CAND_DOJI) // check of "long" candlestick and Doji
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close>=cand2.open && cand1.close>=cand2.close && cand1.close>=cand2.close) // Doji is inside of body of the first candlestick
              {               
                  padraoVela[i]=10;
                  comment=_language?"Harami Cross (Bear)":"Bani Cruzado(B) "+padraoVela[i];
               DrawSignal(prefix+"Harami Cross the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
              }
           }
         else
           {
            if(cand1.close>cand2.open && cand1.close>cand2.close && cand1.open<cand2.close) // Doji is inside of body of the first candlestick
              {               
                  padraoVela[i]=10;
                  comment=_language?"Harami Cross (Bear)":"Bani Cruzado(B) "+padraoVela[i];
               DrawSignal(prefix+"Harami Cross the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
              }
           }
        }
      //------      
      // Harami, the bullish model
      if(cand1.trend==DOWN  &&  !cand1.bull  &&  cand2.bull &&// check direction of trend and direction of candlestick
         (cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) &&  // check of "long" first candlestick
         cand2.type!=CAND_DOJI && cand1.bodysize>cand2.bodysize) // the second candlestick is not Doji and body of the first candlestick is bigger than that of the second one
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close<=cand2.open && cand1.close<=cand2.close && cand1.open>cand2.close) // body of the second candlestick is inside of body of the first candlestick
              {  
                padraoVela[i]=11;
                comment=_language?"Harami (Bull)":"Harami (A) "+padraoVela[i];             
               DrawSignal(prefix+"Harami the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
              }
           }
         else
           {
            if(cand1.close<cand2.open && cand1.close<cand2.close && cand1.open>cand2.close) // body of the second candlestick is inside of body of the first one
              {               
                padraoVela[i]=11;
                comment=_language?"Harami (Bull)":"Harami (A) "+padraoVela[i];             
               DrawSignal(prefix+"Harami the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
              }
           }
        }
      // Harami, the bearish model
      if(cand1.trend==UPPER && cand1.bull && !cand2.bull && // check direction of trend and direction of candlestick
         (cand1.type==CAND_LONG|| cand1.type==CAND_MARIBOZU_LONG) && // check of "long" first candlestick
         cand2.type!=CAND_DOJI && cand1.bodysize>cand2.bodysize) // the second candlestick is not Doji and body of the first candlestick is bigger than that of the second one
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close>=cand2.open && cand1.close>=cand2.close && cand1.close>=cand2.close) // Doji is inside of body of the first candlestick
              {               
                 padraoVela[i]=12;
                 comment=_language?"Harami (Bear)":"Bani (B) "+padraoVela[i];
               DrawSignal(prefix+"Harami the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
              }
           }
         else
           {
            if(cand1.close>cand2.open && cand1.close>cand2.close && cand1.open<cand2.close) // Doji is inside of body of the first candlestick
              {               
                 padraoVela[i]=12;
                 comment=_language?"Harami (Bear)":"Bani (B) "+padraoVela[i];
               DrawSignal(prefix+"Harami the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
              }
           }
        }
      //------      
      // Doji Star, the bullish model
      if(cand1.trend==DOWN && !cand1.bull && // check direction of trend and direction of candlestick
         (cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && cand2.type==CAND_DOJI) // check first "long" candlestick and 2 doji
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close>=cand2.open) // Open price of Doji is lower or equal to close price of the first candlestick
              {               
              padraoVela[i]=13;
         comment=_language?"Doji Star (Bull)":"Doji Star (A) "+padraoVela[i];
               DrawSignal(prefix+"Doji Star the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);

              }
           }
         else
           {
            if(cand1.close>cand2.open && cand1.close>cand2.close) // Body of Doji is cut off the body of the first candlestick
              {               
              padraoVela[i]=13;
         comment=_language?"Doji Star (Bull)":"Doji Star (A) "+padraoVela[i];
               DrawSignal(prefix+"Doji Star the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);

              }
           }
        }
      // Doji Star, the bearish model
      if(cand1.trend==UPPER && cand1.bull && // check direction of trend and direction of candlestick
         (cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && cand2.type==CAND_DOJI) // check first "long" candlestick and 2 doji
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close<=cand2.open) // // open price of Doji is higher or equal to close price of the first candlestick
              {               
              padraoVela[i]=14;
         comment=_language?"Doji Star (Bear)":"Estrela Indecisa (B) "+padraoVela[i];
               DrawSignal(prefix+"Doji Star the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);

              }
           }
         else
           {
            if(cand1.close<cand2.open && cand1.close<cand2.close) // // body of Doji is cut off the body of the first candlestick
              {               
              padraoVela[i]=14;
         comment=_language?"Doji Star (Bear)":"Estrela Indecisa (B) "+padraoVela[i];
               DrawSignal(prefix+"Doji Star the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);

              }
           }
        }
      //------      
      // Piercing Line, the bull model
      if(cand1.trend==DOWN && !cand1.bull && cand2.trend==DOWN && cand2.bull && // check direction of trend and direction of candlestick
         (cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand2.type==CAND_LONG || cand2.type==CAND_MARIBOZU_LONG) && // check of "long" candlestick
         cand2.close>(cand1.close+cand1.open)/2)// close price of the second candle is higher than the middle of the first one
        {
         
         if(_forex)// if it's forex
           {
            if(cand1.close>=cand2.open && cand2.close<=cand1.open)
              {               
              padraoVela[i]=150;
         comment=_language?"Piercing Line (Bull)":"Perfuração (A) "+padraoVela[i];
               DrawSignal(prefix+"Piercing Line"+string(objcount++),cand1,cand2,InpColorBull,comment);
              }
           }
         else
           {
            if(cand2.open<cand1.low && cand2.close<=cand1.open) // open price of the second candle is lower than LOW price of the first one 
              {               
              padraoVela[i]=150;
         comment=_language?"Piercing Line (Bull)":"Perfuração (A) "+padraoVela[i];
               DrawSignal(prefix+"Piercing Line"+string(objcount++),cand1,cand2,InpColorBull,comment);
              }
           }
        }
      
      

     } // end of cycle of checks
//--- return value of prev_calculated for next call


   return(rates_total);
  }

Files:
 
  1. #property indicator_buffers 1#property indicator_buffers 5
    #property indicator_plots   1

    Make up your mind, one or five?

  2.    SetIndexBuffer(0,padraoVela,INDICATOR_CALCULATIONS);
       return(INIT_SUCCEEDED);

    Where are you creating those other buffers?

  3. kellyannecs Anne: I want to create a buffer to bring the result of the formed pattern, I put the candlepadrao[], but it doesn't work.

    “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

  4. What is this “candlepadrao” you mention? (See № 2)
 

Do you know that there are already 8 pages with 10 articles each about candlestick patterns?

And 7 pages of the CodeBase.

All with code to copy and paste :)

You just have to search: https://www.mql5.com/en/search#!keyword=candlestick%20pattern&module=mql5_module_articles

Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you - and searching is better than ChartGPT!