One thing you could do, depending on the strategy, is make the EA check only on the first tick of every bar:
if(Volume[0]>1) return;
Another thing is you could put a marker when you make the trade and check to see if the value is the same.
So in the area before the start() function, declare this:
int BarsCheck;
(if you declare it within a function, it'll be a local variable and will reset each pass)
After you make a trade
BarsCheck=Bars();
Then put this in your trade logic for the next time your EA checks for a trade
if(BarsCheck<>Bars() && ...
(if you declare it within a function, it'll be a local variable and will reset each pass)
Declaring the variable as static will retain it's value between function calls (https://docs.mql4.com/basis/variables/static).

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How do i get the following code to check if it should close a trade on a bar different than the bar the order is opened?
int result,type;
result = OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
if(result == true) Print("OrderSelect Success");
if(result == false) Print("OrderSelect Fail");
if( OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)==true)
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol())// check for symbol
{
if (OrderType()==OP_BUY)
{
result = OrderClose(ticket, 0.1, Bid, 0, Lime);
if(result == true) Print("OrderClose Success");
if(result == false) Print("OrderClose Fail");
}
else
if(OrderType()==OP_SELL)
{
result = OrderClose(ticket, 0.1, Ask, 0, Red);
if(result == true) Print("OrderClose Success");
if(result == false) Print("OrderClose Fail");
}
}