for(int a = OrdersTotal(); a >= 0; a++) replace with for(int a = OrdersTotal()-1; a >= 0; a--)
thanks:D - didn't catch that earlier
it still takes only one trade for some reason, which closes normally(not close at stop that usually happens when its stuck).
Any clues?
Any clues?
Probably not connected to your issues . . but . . .
You aren't selecting Orders to be closed by Symbol and MagicNumber . . I'm sure you think you are, but you aren't.
You are trying to close Buy and Sell orders at the Bid price . . . if you have enough Slippage factored in that might work. Use OrderClosePrice() instead . . .
When you place a trade IsTrade is set = true . . . . when does it get set back to false so you can place a 2nd trade ?
Probably not connected to your issues . . but . . .
You aren't selecting Orders to be closed by Symbol and MagicNumber . . I'm sure you think you are, but you aren't.
You are trying to close Buy and Sell orders at the Bid price . . . if you have enough Slippage factored in that might work. Use OrderClosePrice() instead . . .
When you place a trade IsTrade is set = true . . . . when does it get set back to false so you can place a 2nd trade ?
Thanks lol - istrade was the culprit I had forgotten to declare it to false again. Thats why it never took any more trades.
I guess I shouldn't copy paste code;)
Thanks lol - istrade was the culprit I had forgotten to declare it to false again. Thats why it never took any more trades.
I guess I shouldn't copy paste code;)
Also - could you please point out what you meant by not selecting orders by symbols and magic numbers?
Also - could you please point out what you meant by not selecting orders by symbols and magic numbers?
Of course . . .
for(int a = OrdersTotal(); a >= 0; a++) { if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)){ if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) IsTrade = true; // <--- only this is done if Symbol & Magic Number match //Close Buy orders if(OrderType() == OP_BUY) { if(Close[1] < TwentySMA1 - Window * Point) OrderClose(OrderTicket(),OrderLots(),Bid,MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE); // <--- this happens if type == OP_BUY regardless // of Symbol & Magic Number }
Thanks again - I thought I had nested it under the first if(OrderSymbol().... statement.
So I changed the code now to this:
for(int a = OrdersTotal(); a >= 0; a--) { OrderSelect(a,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) //Close Buy orders { if(Close[1] < TwentySMA1 - Window * Point) OrderClose(OrderTicket(),OrderLots(),Bid,MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE); IsTrade = False; } //Close Sell Orders if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) { if(Close[1] > TwentySMA1 + Window * Point) OrderClose(OrderTicket(),OrderLots(),Ask,MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE); IsTrade = false; } }
I would add this amendment . . just to be sure . .
if(Close[1] < TwentySMA1 - Window * Point) if ( OrderClose(OrderTicket(),OrderLots(),Bid,MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE) ) IsTrade = False;

- 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,
I have coded this EA - for some reason, MT4 cannot backtest it - it says Using M1, then once that is finished, it gets stuck. Any suggestions?
Thank you in advance