Search for a pattern within the last 20 bars - page 2

 

In your code, when you place the arrow, "i" is always equal to -1

 

I'm not sure I understand the significance. Are you saying because "i" is always equal to -1, it'll never show an arrow? I still don't know how to debug this thing to actually make it work then.

Sorry if I seem a little dense, still fairly new at mql.

btw - thanks for taking the time to help out.

 
Does anyone have any suggestions?
 

Here is a modification of your code, closer to what you think you want it to do.

However, your conditions are very rarely if ever acheived.


//+------------------------------------------------------------------+
//|                                           Multiple Force Cross   |
//+------------------------------------------------------------------+
 
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
 
double CrossUp[];
double CrossDown[];
 
extern    int BarsToProcess = 20;
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, 0,3);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, 0,3);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
  
 
   double PForce_2[];
   double PForce_13[];
   double PForce_26[];
   
   ArrayResize(PForce_2, BarsToProcess+3);
   ArrayResize(PForce_13, BarsToProcess+3);
   ArrayResize(PForce_26, BarsToProcess+3);
 
   // start 500 bars in the past
   for(int j = 500 - BarsToProcess-2; j >= 0; j--){
   
    // get some values
    for(int i = j+BarsToProcess+2; i >= j; i--){
    PForce_2[i]  = iForce(NULL, 0, 2, MODE_SMA,PRICE_CLOSE,i);
    PForce_13[i] = iForce(NULL, 0, 13,MODE_SMA,PRICE_CLOSE,i);
    PForce_26[i] = iForce(NULL, 0, 26,MODE_SMA,PRICE_CLOSE,i);
 
      
    }
 
    // Check conditions
   
    bool PForce2Buy = false, PForce13Buy = false, PForce26Buy = false;
    bool PForce2Sell = false, PForce13Sell = false, PForce26Sell = false;
    for( i = j+BarsToProcess; i >= j; i--){
   
   
       CrossDown[j] = EMPTY_VALUE;
       CrossUp[j]   = EMPTY_VALUE;
      
       if(  PForce_2[i+2]  < 350 && PForce_2[i+1] > 350 && PForce_2[i] < 350 ) PForce2Sell  = true;
 
       if(  PForce_13[i+2] < 200 && PForce_13[i+1] > 200 && PForce_13[i] < 200 ) PForce13Sell = true;
 
       if( (PForce_26[i+2] <= 100   &&  PForce_26[i+2] >= 50)   && (PForce_26[i+1] >  100 ) && (PForce_26[i]   <= 100   &&  PForce_26[i]   >= 50 )) PForce26Sell = true;
 
       if(  PForce_2[i+2]  > -350 && PForce_2[i+1] < -350 && PForce_2[i] > -350 ) PForce2Buy  = true;
 
       if(  PForce_13[i+2] > -200 && PForce_13[i+1] < -200 && PForce_13[i] > -200 ) PForce13Buy = true;
 
       if( (PForce_26[i+2] >= -100   &&  PForce_26[i+2] <= -50)   && (PForce_26[i+1] <  -100 ) && (PForce_26[i]   >= -100   &&  PForce_26[i]   <= -50 )) PForce26Buy = true;
      }
   
  if( PForce2Buy == true && PForce13Buy == true && PForce26Buy == true){
      Print("****************************Found an UP cross... J = ", j);
      CrossUp[j] = Low[j] - 25*Point;
  }    
  else if( PForce2Sell == true && PForce13Sell == true && PForce26Sell == true){
      Print("****************************Found a DOWN cross... J = ", j);
      CrossDown[j] = High[j] + 25*Point;
     }     
   }
   return(0);
}
Reason: