TRADE ONLY ONCE ON BAR
Up at the top where you declare your variables put
static bool ITradedOnThisBar;
then where you send your order put
if(
Your Critera && ITradedOnThisBar!=Bars)
{
ticket=OrderSend(Symbol(),OP_BUY,... );
ITradedOnThisBar = Bars;
}
Doing This will keep you from opening a trade on the same bar that you already opened a trade on, but more importantly you want to keep it from closing on the same bar so I would also add this code where you close your trade, for example:
if(
Your Criteria && ITradedOnThisBar != Bars)
{
OrderClose(OrderTicket(),... ); // close position
}
This is probably the most simple way to do what you are trying to do.
This works if you can find the places to add these statements.