Help with CandleStick Pattern Coding - page 2

 
Vladimir Karputov:

Picture 2:


That's not the part im having difficulties with, the bars between the two intersecting bars should be in a V pattern

 
Ahmad861 :

That's not the part im having difficulties with, the bars between the two intersecting bars should be in a V pattern

I solved the question this way: I simplified the search. I am NOT looking for the letter 'V' - I am looking for just two intersections.

Sample code: iBands Pattern V

And here you can insert your own pattern search algorithm 'V':

//+------------------------------------------------------------------+
//| Search trading signals                                           |
//+------------------------------------------------------------------+
bool SearchTradingSignals(void)
  {
   if(iTime(m_symbol.Name(),InpWorkingPeriod,0)==m_last_deal_in) // on one bar - only one deal
      return(true);
   double middle[],upper[],lower[];
   MqlRates rates[];
   ArraySetAsSeries(middle,true);
   ArraySetAsSeries(upper,true);
   ArraySetAsSeries(lower,true);
   ArraySetAsSeries(rates,true);
//---
   int start_pos=0,count=3;
   if(!iGetArray(handle_iBands,BASE_LINE,start_pos,count,middle) ||
      !iGetArray(handle_iBands,UPPER_BAND,start_pos,count,upper) ||
      !iGetArray(handle_iBands,LOWER_BAND,start_pos,count,lower) ||
      CopyRates(m_symbol.Name(),InpWorkingPeriod,start_pos,count,rates)!=count)
     {
      return(false);
     }
   int size_need_position=ArraySize(SPosition);
   if(size_need_position>0)
      return(true);
//---
   bool buy_signal=false,sell_signal=false;
//-- first start
   if(m_intersection_up==D'1970.01.01 00:00')
     {
      if(rates[m_bar_current].low<upper[m_bar_current] && rates[m_bar_current].high>upper[m_bar_current])
         m_intersection_up=rates[m_bar_current].time;
     }
   if(m_intersection_down==D'1970.01.01 00:00')
     {
      if(rates[m_bar_current].low<lower[m_bar_current] && rates[m_bar_current].high>lower[m_bar_current])
         m_intersection_down=rates[m_bar_current].time;
     }
//--- BUY Signal
   if(m_intersection_up<rates[m_bar_current].time)
     {
      if(rates[m_bar_current].low<upper[m_bar_current] && rates[m_bar_current].high>upper[m_bar_current])
        {
         double arr_upper[];
         MqlRates arr_rates[];
         ArraySetAsSeries(arr_upper,true);
         ArraySetAsSeries(arr_rates,true);
         if(!iGetArray(handle_iBands,UPPER_BAND,m_intersection_up,rates[m_bar_current].time,arr_upper))
            return(false);
         int size_arr_upper=ArraySize(arr_upper);
         if(CopyRates(m_symbol.Name(),InpWorkingPeriod,m_intersection_up,rates[m_bar_current].time,arr_rates)!=size_arr_upper)
            return(false);
         if(size_arr_upper-3>=InpMinPatternBars)
           {
            int d=0;
            for(int i=1; i<size_arr_upper-1; i++)
              {
               //--- here you can insert your algorithm
               //Print(arr_rates[i].time);
              }
            buy_signal=true;
           }
         m_intersection_up=rates[m_bar_current].time;
        }
     }
//--- SELL Signal
   if(m_intersection_down<rates[m_bar_current].time)
     {
      if(rates[m_bar_current].low<lower[m_bar_current] && rates[m_bar_current].high>lower[m_bar_current])
        {
         double arr_lower[];
         MqlRates arr_rates[];
         ArraySetAsSeries(arr_lower,true);
         ArraySetAsSeries(arr_rates,true);
         if(!iGetArray(handle_iBands,LOWER_BAND,m_intersection_down,rates[m_bar_current].time,arr_lower))
            return(false);
         int size_arr_lower=ArraySize(arr_lower);
         if(CopyRates(m_symbol.Name(),InpWorkingPeriod,m_intersection_down,rates[m_bar_current].time,arr_rates)!=size_arr_lower)
            return(false);
         if(size_arr_lower-3>=InpMinPatternBars)
           {
            int d=0;
            for(int i=1; i<size_arr_lower-1; i++)
              {
               //--- here you can insert your algorithm
               //Print(arr_rates[i].time);
              }
            sell_signal=true;
           }
         m_intersection_down=rates[m_bar_current].time;
        }
     }
//---
   if(buy_signal)
     {
      if(!InpReverse)
        {
         if(InpTradeMode!=sell)
           {
            ArrayResize(SPosition,size_need_position+1);
            SPosition[size_need_position].pos_type=POSITION_TYPE_BUY;
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY");
            return(true);
           }
        }
      else
        {
         if(InpTradeMode!=buy)
           {
            ArrayResize(SPosition,size_need_position+1);
            SPosition[size_need_position].pos_type=POSITION_TYPE_SELL;
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL");
            return(true);
           }
        }
     }
   if(sell_signal)
     {
      if(!InpReverse)
        {
         if(InpTradeMode!=buy)
           {
            ArrayResize(SPosition,size_need_position+1);
            SPosition[size_need_position].pos_type=POSITION_TYPE_SELL;
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL");
            return(true);
           }
        }
      else
        {
         if(InpTradeMode!=sell)
           {
            ArrayResize(SPosition,size_need_position+1);
            SPosition[size_need_position].pos_type=POSITION_TYPE_BUY;
            if(InpPrintLog)
               Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY");
            return(true);
           }
        }
     }
//---
   return(true);
  }
 
Vladimir Karputov:

I solved the question this way: I simplified the search. I am NOT looking for the letter 'V' - I am looking for just two intersections.

Sample code: iBands Pattern V

And here you can insert your own pattern search algorithm 'V':

this was really detailed, thanks