English

## EA opens 2 trades in one candle.

 9 xtractalpha 2014.10.13 17:01   Hi,I've programmed a really simple expert advisor. The EA opens a long position when the slow stochastics closes below the value 86. ``` extern double lot = 0.1; extern double tp = 60; //for EURUSD M5 extern double sl = 1000; //for EURUSD M5 int start()   {      double r1 = iStochastic(NULL,0,8,3,3,MODE_SMA,0,MODE_MAIN,1);      double r2 = iStochastic(NULL,0,8,3,3,MODE_SMA,0,MODE_MAIN,2);           {      if (r2>86 && r1<86 && OrdersTotal()<1)      {        OrderSend(Symbol(),OP_SELL,lot,Bid,0,Bid+sl*Point,Bid-tp*Point,"Stoch signal",0,0,clrRed);      }                   }     return(0);          }```The EA does it's job, but sometimes it opens a new position when the TP is hit inside the first candle. (check the image http://prntscr.com/4vrtlr )How should I add to my code to repair this problem. Is there a parameter who stores the amount of orders inside a candle?Thanks in advance,Thierry
 13124 WHRoeder 2014.10.13 18:22 #   xtractalpha: The EA opens a long position when the slow stochastics closes below the value 86. The EA does it's job, but sometimes it opens a new position when the TP is hit inside the first candle. (check the image http://prntscr.com/4vrtlr )How should I add to my code to repair this problem. Is there a parameter who stores the amount of orders inside a candle?```extern double tp = 60; //for EURUSD M5 extern double sl = 1000; //for EURUSD M5 OrderSend(Symbol(),OP_SELL,lot,Bid,0,Bid+sl*Point,Bid-tp*Point,"Stoch signal",0,0,clrRed);```nopeThe stops of a sell are relative to the Ask. So your actual TP is tp - spread. 60 - 20 = 4 pips.If you don't want to open in the same bar remember the bar time when you open (global/static) and check for new/same bar.
 9 xtractalpha 2014.10.13 19:18 #   ```     if (r2>86 && r1<86 && OrdersTotal()<1)      {        OrderSend(Symbol(),OP_SELL,lot,Ask,0,Ask+sl*Point,Ask-tp*Point,"Stoch signal",0,0,clrRed);      Sleep(300000); //milliseconds      }```Gooly & WHRoder thanks for your help!You are right about the Ask price, I've edited it in my EA. I've added a sleep function after my "ordersend" function. That should do the job too (In my eyes).Thanks
 1211 deysmacro 2014.10.15 13:14 #   `F7 > Common > Allow live trading`Something like that.