This is an EA with attempt to open positions on ma-crosses with a certain level when to increase the volume, but I can´t run it in the strategytester
- Always test return codes, so you find out WHY
res = OrderSend(...); if (res < 0) Alert("OrderSend failed: ", GetLastError());
void CheckForOpen(){ ... OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY); orderprofit=OrderProfit(); : if((Open[1]>=ma && Close[1]<=ma && Close[2]>=ma)||(Close[2]>ma && Open[1]<ma)){ OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
How can you close an already closed order. OrderTicket is from the OrderSelect(HISTORY). Always test return codes.OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
At the start of the ST, there are no history orders, so the select fails and everything below is bogus. Always test return codes.- That orderSelect also makes the EA incompatible with every other including itself on other charts and manual trading. Always filter by MN
- Always test return codes, so you find out WHY
- How can you close an already closed order. OrderTicket is from the OrderSelect(HISTORY). Always test return codes.
- At the start of the ST, there are no history orders, so the select fails and everything below is bogus. Always test return codes.
- That orderSelect also makes the EA incompatible with every other including itself on other charts and manual trading. Always filter by MN
1. One order opens then runing the tester. So there can not be any error messages. But the ea will not close it, i think. Since the first order can´t be closed another can´t be opened. I just want one order to be open at the same time.
2. That close method shall not be there, it is there because I tried with flags earlier to remember opened positions.
3. I have programed so that if there are no history orders the volume will be 0.1. The volume start value is 0.1 (the variable is decleard in the begining at the fifth row)
4. Don´t understand what you meen.
4. Don´t understand what you meen.
for(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 https://www.mql5.com/en/forum/126192 ){ orderprofit=OrderProfit(); : break; // Last closed order only }
Have used some of the methods that are already in the EA "Moving averages" that is in the demo version of mt4, then I have just typed in the code for when to open and close, and how to calculate the volume. Thanks i advance.