calculate the difference of Order #1 to trail Order #2
Samuel Akinbowale:
calculate the difference of Order #1 to trail Order #2
Thank you for the sugession.calculate the difference of Order #1 to trail Order #2
Order #1 will quit earlier than order #2 as my intention is to trail order #2 as much as possible if the market is moving in favor.
How to keep the calculated difference to pass into the trailing function on each new tick ?
keep the ticket before close and use
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==) {
Samuel Akinbowale:
keep the ticket before close and use
Thank you for the tip.keep the ticket before close and use
Following your comment i found the way to find last closed order... I can use this :)
int i =OrdersHistoryTotal()-1; OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); double closingPrice =OrderClosePrice();
imalkaiw: I can use this :)
- Do not assume history has only closed orders.
Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum -
Using OrdersTotal (OrdersHistoryTotal)
directly and/or no Magic number filtering on your
OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles - Why did you post your MT4 question in the Root / MT5
EA section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.
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
In my EA I open 2 orders at once.
Order #1 : set TakeProfit value ( TakeProfit value calculated based on ATR of the time of order placed )
Order #2 : do not set TakeProfit value at the opening
Later on I want to run trailing stop for the "Order #2" and I need to pass the TakeProfit value I used in the Order #1 as trailing value ( which means the ATR value of the order creation ).
Means the ATR of the time when both orders placed.
Please suggest your idea to achieve this.
Below is the content of OnTick() function
Order functions are defined in global area, above OnTick().
Below is sample order of BUY, where I calculate ATR to use in OrderSend() as TP.