Take second order on same bar
7 replies
ryanbrignac9764
8 years ago #114680
i tried looking through the forums but couldn’t find the answer to the question i have.
At the top of my RULES i always put “Is bar open is true” and then list out my rules.
Then i either enter at market or limit order..
So if i enter at market order when bar open is true and on that same bar it reaches my profit target and exits out trade with profit.. How do i then tell it that if during that same bar the price goes back to what my entry price was on the same bar just a couple seconds ago that it exited with profit to THEN enter back into position at that same price in the same direction it just was??
But once the bar is over and moves to next bar then i don’t want it taking the trade..
I only want it to take the 2nd trade if it reaches back to my entry price after the 1st entry price was a success.
R.B.
tomas262
8 years ago #135263
When you enter a position using market order you can set a variable waitForLimit = 1 and save your profit-target price.
EA then waits if market reaches that price and market position is NOT flat until bar closes and places limit order.
Add condition that “if isBarOpen = true AND waitForLimit = 1” you set to waitForLimit = 0 to avoid placing limit order after bar closes.
Beware that this requires precise backtesting to get meaningful results
Let me know if you need an example for this in WIzard
Fx Mena
8 years ago #135825
SAME problem
i Need Function to check last Order Closed ( most orders closed manually the EA Open new trade ).
what i need :
BUY if only last closed order was SELL
SELL if only last closed order was BUY
How to add to EA ?
tomas262
8 years ago #135835
This could do the job. There are two functions: Last Order & Last Order Today … depends on which you prefer most
Fx Mena
8 years ago #135847
This could do the job. There are two functions: Last Order & Last Order Today … depends on which you prefer most
Good, that’s solved a Part of system, if i pur SL=0, and activate Reverse trading CloseSell/OpenBuy vs CLoseBuy openSell , after some trades, EA will stop making Reset/Set traded=0 or 1, and continue with one trade (short/long) can not be closed if TP not reached
The problem of : Last Order & Last Order Today that return us the current ACTIVE Trade , not the closed trades, Right ?
How to modify the following custom Function and extract Strategy Rules as : || or && To return rules if last closed position was SELL or BUY .
Source :
http://forum.mt5.com/showthread.php?434-Mql4-useful-functions&p=1547&viewfull=1#post1547
int sqGetLastOrderHist(int type = -1) { int ticket = -1; datetime dt = 0; int cnt = HistoryTotal(); for (int i=0; i dt) { dt = OrderCloseTime(); ticket = OrderTicket(); } } return (ticket); }
tomas262
8 years ago #135885
Last Order function returns what was the last order. As I made an example, EA waits for position equals flat and evaluates what was the last trade. The it trades the opposite.
tomas262
8 years ago #136135
Tried to edit your file. See attached Wizard project.
Basically I removed “Market Position is Flat” condition and replaced “Last Order Was” with my own variable.
Let me know if that helped
Fx Mena
8 years ago #136154
Thank You very much, Now all mysteries & Problem solved with EA wizard.
that example include all necessary action and rules needed for the complete strategies,.
🙂 I’m very happy, 1 year try to solve this problem, you deserve all the best Mr Tomas
Viewing 7 replies - 1 through 7 (of 7 total)