Download MetaTrader 5
To add comments, please log in or register
MQL5 Reference is available in 8 languages. Learn MQL5 in the language that suits you best!
Tempestshade David
69
Tempestshade David 2014.04.08 14:27 

Hello guys,

I have the following code. Which works great and does what I want it to - sort of. I am using an indicator that repaints, and as such I want to be able to make it wait 2-3 bars and then recheck the logic to see if cnb < 100 or > 0. If after X amt of bars the logic is still true I would like to act upon it.

Any help would be great. I have looked at the Sleep() function, but have no idea how I would implement it.

   if(ltradecount > 0 && cnb < 100 && stradecount < MaximumOrders)
   {
               for(int x=OrdersTotal()-1;x>=0;x--){
               OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
               if(OrderType()==OP_BUY){
               OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),666,CLR_NONE);
               }}
         double price = nd(Bid);
         int ticket = OrderSend(Symbol(), OP_SELL, Lotsize, price, Slippage, NULL, NULL, EAComment, MagicNumber);
         ltradecount = 0;
         stradecount++;
   }
   else if (stradecount > 0 && cnb > 0 && ltradecount < MaximumOrders)
   {
                for(int x=OrdersTotal()-1;x>=0;x--){
               OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
               if(OrderType()==OP_SELL){
               OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),666,CLR_NONE);
               }}
         double price = nd(Ask);
         int ticket = OrderSend(Symbol(), OP_BUY, Lotsize, price, Slippage, NULL, NULL, EAComment, MagicNumber);
         stradecount = 0;
         ltradecount++;
   }
qjol
3243
qjol 2014.04.08 15:12  
use iCustom to check the bar X's position
Tempestshade David
69
Tempestshade David 2014.04.09 12:57  

Ahh, so you are saying instead of doing what I am doing now and checking on current vs previous bar, check how ever many bars back I want to check? Good idea actually.... I was thinking some sort of sleep/loop function would have to be made.

I will come back with how it went.

/
To add comments, please log in or register