How to only allow one trade per bar in MetaTrader
When trading in MetaTrader you may find times when you only want to allow one trade to take place per bar. This can be accomplished with the code below.
datetime Time0 = 0; //Create a global variable Time0
void start() //This is your start function
{
if (Time0 != Time[0]) //If the Time0 variable we created does not equal the time of the current bar we can continue with our code
{
OrderSend(… //Here we send our order preferences
Time0 = Time[0]; //Then we set the Time0 variable to the current bars time. This way no more trades can be placed on this bar
}
}
Facebook comments: