help!!

 
extern double Lots=0.1;
extern double Stoploss=20;
extern double Takeprofit=40;
extern double Factor=3;

//----
   
//----
  
//+------------------------------------------------------------------+
//| Calculate open position                                          |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double price1, price2;
   int res; 
   price1=Bid;
  
   Sleep(10000);
  
   
   price2=Bid;
  
   if(price1>price2 && price1-price2>=Factor*Point)
      {   
       
       res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+Stoploss*Point,Bid-Takeprofit*Point,"",0,0,Red);
       return;
      
      }
   if(price1<price2 && price2-price1>=Factor*Point)
      {
       
       res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-Stoploss*Point,Ask+Takeprofit*Point,"",0,0,Blue);
       
       return;
       
      }
   
   else
      {
       
       return;
       
      }
      
   
  } 

int start()
  {
   CheckForOpen();
   Alert (GetLastError());
   return;
  }
When I test it, price1 and price2 all always are same. Therefore, it never trade once successly. Could someone tell me why? Thanks so much!! 
 

P

The Sleep() function isn't processed in backtesting, use TimeCurrent() and add seconds to get next price check time

Even if you used Sleep() in live trading you would need to use a RefreshRates() to get a price difference on the same tick...

-BB-

 

hello


after Sleep(10000); add additional line:

RefreshRates();

after this Price2 will have a new Bid value.


regards

oromek

Reason: