you have to code that yourself.
The TP is triggered while the condition to open the trade is still true: wait a) for some time b) for a trade in the other direction c) ...
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);
- nope
- The 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.
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
F7 > Common > Allow live trading
Something like that.
Thank you, I feel so stupid.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I've programmed a really simple expert advisor. 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?
Thanks in advance,
Thierry