Aren't this
for (int pos = 0; pos >= Total_History; pos++)
supposed to be this
for (int pos = 0; pos <= Total_History; pos++)
...???
Please report back the result :)
Aren't this
supposed to be this
...???
Please report back the result :)
That did it Thanks. Question ( pos=0, pos <= Total_History ) will always be true
What happens after the highest pos is reached.
Did you mean ...
Question ( pos=0; pos <= Total_History; pos ++ ) will always be true
What happens after the highest pos is reached.
Did you mean ...
After the highest pos reached, the for loop terminates it self and the next code block get executed, in your case, it's the 'Moving Average Cross System' gets executed. :)
Ya I didnt add the increment thanks for the explanation,
trying to make my EA consistantly profitable difficult.
int Total_History = OrdersHistoryTotal(); for (int pos = 0; pos >= Total_History; pos++)
Always count down.if ( OrdersHistoryTotal() == 0) break;
This will never be true inside the for loop. It also makes the EA incompatible with every other including itself on other charts and manual trading.- Always filter by magic number and pair
bool hasHistory=false; for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderMagicNumber() == Magic.Number // my magic number && OrderSymbol() == chart.symbol // and my pair. && OrderType() <= OP_SELL//Avoid cr/bal forum.mql4.com/32363#325360 ){ hasHistory = true; Print ("We have the winner :) "); : break; // Process one only } if (!hasHistory){ //---- Moving Average Cross System : }
- See also Order History sort by closing date - MQL4 forum
if ( OrdersHistoryTotal() == 0 ){ PriceTP = Close[1]-1; } if ( Close[1] > bb && Close[1] > PriceTP ) { GoLong(); } if ( OrdersHistoryTotal() == 0 ){ PriceTP = Close[1]+1;} if ( Close[1] < cc && Close[1] < PriceTP ) { GoShrt(); }
So you can only ever have one trade for this system. As soon as you have done one trade you can never ever trade again. Shouldn't this test be OrdersTotal() rather than OrdersHistoryTotal()
Of course just using OrdersTotal() is pretty lame for a real EA due to the possible existence of other EAs trading this account, but it will work enough to test a strategy.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys, Im running my EA in tester and OrdersHistoryTotal(), OrderClosePrice() and OrderTakeProfit()
are all showing zeros even after orders are Open and Closed.Here is the code.
Thanks for your help.