Need help coding a limit criteria

 

Hi,

I'm trying to code for a limit criteria to close an order, however the criteria needs only to be relevant when the 4th bars appears following a marker order. I would like to code to assess the characteristics of all bars (already have coded this), subsequent to the 4th bar of an order. I am struggling how to code this so any help would be greatly appreciated

 
And where is the code so far ?
 

Code is a bit of a mess at the moment. I have defined a bar that signals a change in market direction but need this to only be effective when n=4 bars have passed from the order.

//+-------------------------------------------------------------------------------------------------------------------------------------------------

extern double buystoploss   =0;                                                             //SL for a buy open order

extern double buytakeprofit =??;                                                             //ТР for a buy opened order

extern int    buycount      =0;                                                             //Number of buy market orders placed within 24 hours

extern int    sellcount     =0;                                                             //Number of sell market orders placed within 24 hours                

//+------------------------------------------------------------------------------------------------------------------------------------------------

int start()

{

   int 

   spinningtop         =  33,                                                                       //percentage parameter of spinning candle top

   currentorder        =  OrdersTotal();                                                            //total number of open market orders 

   double 

   totalcandlelength   =  MathAbs((iHigh("EURUSD",PERIOD_M1,1))-((iLow("EURUSD",PERIOD_M1,1)))),     //total length of a single individual candle

   candlelength        =  MathAbs((iOpen("EURUSD",PERIOD_M1,1))-((iClose("EURUSD",PERIOD_M1,1)))),   //length of open and close position of each candle

   price               =  Ask;                                                                       //Price of market entry

   bool

   spinningtoprule     =  false;                                                                     // 33% rule for opening an order

//+------------------------------------------------------------------------------------------------------------------------------------------------

 if (currentorder<1 && (((candlelength/totalcandlelength)*100) <= spinningtop))                   //Limit market order at any time to n=1 & implement 33% rule                  

      {

      spinningtoprule = true;                                    

      OrderSend("EURUSD",OP_BUY,1,Ask,10,buystoploss,buytakeprofit,NULL,0,0,clrGreen);

      buycount++;

      Alert("Buy Order No.",buycount,"  Price=",price);  

      }

return;

}

 
int barcount=0;
datetime time;
if(time!=iTime(_Symbol,PERIOD_M1,0))
 {
  barcount++;
  time=iTime(_Symbol,PERIOD_M1,0);
 }

if(barcount==4)
 {
  // Do Something...
  barcount=0;
 }
 

Thank you very much. Worked a treat!

Reason: