for(int i=OrdersHistoryTotal()-1; i < OrdersHistoryTotal(); i++) if((OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) && (OrderMagicNumber() == order_magic) && (OrderSymbol() == Symbol()))
What is the point of the loop?
There can only be one pass!
What is the point of the loop?
There can only be one pass!
Because the following functions are selecting previous closed order information that's why I place the for loop
I post the code down here
{ /* entry */ if(OrdersHistoryTotal() == 0) { int count_orders=0; if(entry>0) { if(entry==TRADE_SIGNAL_BUY) { if(exit_opposite_signal) exit_all_set(ORDER_SET_SELL,order_magic); count_orders=count_orders(-1,order_magic); if(maxtrades>count_orders) { if(!entry_new_bar || (entry_new_bar && is_new_bar(symbol,timeframe,wait_next_bar_on_load))) enter_order(OP_BUY); } } else if(entry==TRADE_SIGNAL_SELL) { if(exit_opposite_signal) exit_all_set(ORDER_SET_BUY,order_magic); count_orders=count_orders(-1,order_magic); if(maxtrades>count_orders) { if(!entry_new_bar || (entry_new_bar && is_new_bar(symbol,timeframe,wait_next_bar_on_load))) enter_order(OP_SELL); } } } } else if(OrdersHistoryTotal()>0) { static datetime time_open; for(int i=OrdersHistoryTotal()-1; i < OrdersHistoryTotal(); i++) if((OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) && (OrderMagicNumber() == order_magic) && (OrderSymbol() == Symbol())) { if((calculate_trigger()>=(OrderCloseTime()-OrderOpenTime())) && OrderProfit() < 0) { int count_orders=0; if(entry>0) { if(entry==TRADE_SIGNAL_BUY) { if(exit_opposite_signal) exit_all_set(ORDER_SET_SELL,order_magic); count_orders=count_orders(-1,order_magic); if(maxtrades>count_orders) { if(!entry_new_bar || (entry_new_bar && is_new_bar(symbol,timeframe,wait_next_bar_on_load))) if((OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)&& (OrderMagicNumber() == order_magic) && (OrderSymbol() == Symbol())) { time_open=OrderCloseTime()+(Bar_to_entry*Period()*60); if(time_open<Time[0]) { enter_martingale_order(OP_BUY); } } } } else if(entry == TRADE_SIGNAL_SELL) { if(exit_opposite_signal) exit_all_set(ORDER_SET_BUY,order_magic); count_orders=count_orders(-1,order_magic); if(maxtrades>count_orders ) { if(!entry_new_bar || (entry_new_bar && is_new_bar(symbol,timeframe,wait_next_bar_on_load))) if((OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)&& (OrderMagicNumber() == order_magic) && (OrderSymbol() == Symbol())) { time_open=OrderCloseTime()+(Bar_to_entry*Period()*60); if(time_open<Time[0]) { enter_martingale_order(OP_SELL); } } } } } } else if((calculate_trigger()<=(OrderCloseTime()-OrderOpenTime())) && OrderProfit() < 0 && OrderClosePrice() >= OrderOpenPrice() + breakeven_plus) { int count_orders=0; if(entry>0) { if(entry==TRADE_SIGNAL_BUY) { if(exit_opposite_signal) exit_all_set(ORDER_SET_SELL,order_magic); count_orders=count_orders(-1,order_magic); if(maxtrades>count_orders) { if(!entry_new_bar || (entry_new_bar && is_new_bar(symbol,timeframe,wait_next_bar_on_load))) enter_martingale_order(OP_BUY); } } else if(entry == TRADE_SIGNAL_SELL) { if(exit_opposite_signal) exit_all_set(ORDER_SET_BUY,order_magic); count_orders=count_orders(-1,order_magic); if(maxtrades>count_orders ) { if(!entry_new_bar || (entry_new_bar && is_new_bar(symbol,timeframe,wait_next_bar_on_load))) enter_martingale_order(OP_SELL); } } } } else if(OrderProfit()>=0) { int count_orders=0; if(entry>0) { if(entry==TRADE_SIGNAL_BUY) { if(exit_opposite_signal) exit_all_set(ORDER_SET_SELL,order_magic); count_orders=count_orders(-1,order_magic); if(maxtrades>count_orders) { if(!entry_new_bar || (entry_new_bar && is_new_bar(symbol,timeframe,wait_next_bar_on_load))) enter_order(OP_BUY); } } else if(entry==TRADE_SIGNAL_SELL) { if(exit_opposite_signal) exit_all_set(ORDER_SET_BUY,order_magic); count_orders=count_orders(-1,order_magic); if(maxtrades>count_orders) { if(!entry_new_bar || (entry_new_bar && is_new_bar(symbol,timeframe,wait_next_bar_on_load))) enter_order(OP_SELL); } } } } } } }
I still fail to see the point of the loop
for(int i=OrdersHistoryTotal()-1; i < OrdersHistoryTotal(); i++) if((OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) && (OrderMagicNumber() == order_magic) && (OrderSymbol() == Symbol()))
Is the same as
int i=OrdersHistoryTotal()-1; if((OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) && (OrderMagicNumber() == order_magic) && (OrderSymbol() == Symbol()))
I still fail to see the point of the loop
Is the same as
You mean to track back the previous closed order no need use the for loop?
Because I saw most of the code to track back the previous closed order they using for loop
For Example:
https://www.mql5.com/en/forum/224183

- 2018.01.08
- www.mql5.com
You mean to track back the previous closed order no need use the for loop?
Because I saw most of the code to track back the previous closed order they using for loop
For Example:
https://www.mql5.com/en/forum/224183
Yes, you would use a loop to find the last closed order, but you are not actually using a loop. You are just checking the single closed order that is last in the list.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have a question regrading on the OrderMagicNumber.
I knew that we can set a manual magic number in the EA settings to set our strategies. But I counter a problem which is during backtesting which I track down previous order by using
to complete certain function.
Yes it successfully do what what I expecting during backtesting without any errors.
But I don't know why, when I run it in my real trading account it do not open any orders and didn't came out any warnings and errors.
Also I already confirm that it is the problem when I place this function( highlighted ) because after I delete the highlighted function the EA can run and open orders
Because I wanted to place the same EA with different strategies in the same currency by changing the order magic number.
Am I doing some common mistake or something else?
Hope someone could kindly guide me on this.