hi guys Im trying to get the magic number of my most recent Take Profit trade on history with this code
but instead of giving me the most recent. It is giving me the earliest magic number.
int magicnumberclose() SHMagicNumberClosed = 0 ; for(int i=OrdersHistoryTotal()-1;i>= 0 ;i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)==true) { if(OrderProfit()>0 && OrderSymbol()==Symbol() ) SHMagicNumberClosed = OrderMagicNumber(); } }
Sorry Mehmet.
-
Your code continues selecting all orders. It does not stop once it finds one.
-
Do not assume history has only closed orders.
OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017.11.30) -
Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012.04.21)
Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020.06.08) -
Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
"balance" orders in account history - Day Trading Techniques - MQL4 programming forum (2017.11.01)Broker History FXCM Commission - <TICKET>
Rollover - <TICKET>>R/O - 1,000 EUR/USD @0.52 #<ticket> N/A OANDA Balance update
Financing (Swap: One entry for all open orders.)
Sorry Mehmet.
-
Your code continues selecting all orders. It does not stop once it finds one.
-
Do not assume history has only closed orders.
OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017.11.30) -
Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012.04.21)
Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020.06.08) -
Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
"balance" orders in account history - Day Trading Techniques - MQL4 programming forum (2017.11.01)Broker History FXCM Commission - <TICKET>
Rollover - <TICKET>>R/O - 1,000 EUR/USD @0.52 #<ticket> N/A OANDA Balance update
Financing (Swap: One entry for all open orders.)
hmm this is confusing
hi sir Mehmet sometimes it gives the right magic number sometime its not
hi sir Mehmet sometimes it gives the right magic number sometime its not
If there is no magic number, it is certain that it will return zero. You just look for orders with magic number that close with profit in EUR/USD (example) pair and it will close first in your code. If there are 10 orders to be taken with profit, you will get the magic number of the 10th order.
int magicnumberclose() SHMagicNumberClosed = 0 ; for(int i=OrdersHistoryTotal()-1;i>= 0 ;i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)==true) { if(OrderProfit()>0 && OrderSymbol()==Symbol() ) { SHMagicNumberClosed = OrderMagicNumber(); break; } } }
Sorry Mehmet.
-
Your code continues selecting all orders. It does not stop once it finds one.
-
Do not assume history has only closed orders.
OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017.11.30) -
Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012.04.21)
Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020.06.08) -
Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
"balance" orders in account history - Day Trading Techniques - MQL4 programming forum (2017.11.01)Broker History FXCM Commission - <TICKET>
Rollover - <TICKET>>R/O - 1,000 EUR/USD @0.52 #<ticket> N/A OANDA Balance update
Financing (Swap: One entry for all open orders.)
Sorry, no one cares about your ignorant answers, as your goal in this forum is just to score points. Please do not reply to my answers. You are not helping anyone, you are just mocking and writing confusing things that have no scientific value.
If there is no magic number, it is certain that it will return zero. You just look for orders with magic number that close with profit in EUR/USD (example) pair and it will close first in your code. If there are 10 orders to be taken with profit, you will get the magic number of the 10th order.
Oh i see it only gives the magic number of trade if its in profit.I think its not giving me the magic number sometimes because it closes with no profit. hmm what will i add on the code to give me also the last closed with or without profit. Thank you so much Sir Mehmet
int magicnumberclose() SHMagicNumberClosed = 0 ; for(int i=OrdersHistoryTotal()-1;i>= 0 ;i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)==true) { if(OrderProfit()=>0 && OrderSymbol()==Symbol() ) { SHMagicNumberClosed = OrderMagicNumber(); break; } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
but instead of giving me the most recent. It is giving me the earliest magic number.