Use the same logic used to calculate the range bars to determine how many bars back a_particular deal is.
If that sounds complicated to you, then perhaps you don't know how your range bars are being calculated and perhaps shouldn't be using it.
Anyways, another simpler method you could possibly use is this.
Store information about the orders using something static like different Magic_Numbers || OrderComment().
Store information about the orders using something dynamic like different OrderStopLoss() || OrderTakeProfit().
example:
Order#1 gets modified to the OrderTakeProfit() of 111111111.0
Order#2 gets modified to the OrderTakeProfit() of 222222222.0
These are pretty high values which may_never get hit.
Obvious downside is this takes up your TakeProfit, and you'll have to [check and close] orders in profit.
Why not. Just find the bar the order was opened on
int iBar = iBarShift( NULL,0, OrderOpenTime() );
@Ubzen : Thanks, I can write simple EA but i'm not an expert :) With your second method, i'm not sure how you count the bars ? What i can do when i place an order is to save in a variable the amount of bars on the chart, and when this amount increases by 1, i know it's the next bar... That would be all fine if i have only one order at the same time, but my issue is that if i have 3 orders open, i dont know at which additional bars they are all at... I should be able to assign that figure to a order.
@WHRoeder : thanks, i should check this, might help. I thought that this would only work with standard timeframes (5,10 min etc)
@Ubzen : Thanks, I can write simple EA but i'm not an expert :) With your second method, i'm not sure how you count the bars ? What i can do when i place an order is to save in a variable the amount of bars on the chart, and when this amount increases by 1, i know it's the next bar... That would be all fine if i have only one order at the same time, but my issue is that if i have 3 orders open, i dont know at which additional bars they are all at... I should be able to assign that figure to a order.
@WHRoeder : thanks, i should check this, might help. I thought that this would only work with standard timeframes (5,10 min etc)
When you said OpenTime won't work, I assumed that BarShift() wouldn't work on off_line charts :). So yeah, try BarShift() thats your easiest path.
Should that not work, should you have the ability to determine when a new_bar appears or when the count of bars increases, then simply OrderModify() your existing orders. Something like if( OrderProfit()==111111111 ) OrderModify( New_OrderProfit()=222222222 ). Thats what I had in mind, hopefully you wouldn't need it.
OK great i got your logic now !
Yes i dont know if BarShift() works on offline charts, i need to test. But i now have a backup solution.
Thanks!
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
My EA would require that once a trade is initiated, it follows some specific exit rules for the 5 next bars... After that, if the trades is not exited, there is a trailing stop. My problem is that you may have 2 or 3 orders open during those 5 next bars (one at each bar)... Each order should follow the same rules for the 5 next bars... I dont know how to manage that, i mean how would you know that the first order has still 3 bars left to be managed, another one 4 bars left and the last open order 5 bars left ?
So basically i should know how much bars there are after each open orders until the current bar. Any way to calculate this ?
Bear in mind that i dont use 5 min or 10 min timeframes but i use non time charts (constant range bars)... So using the order open time won't work.
Thank you very much
Gregory