Building robots using MetaTrader to exploit the simplicity of the world

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
  }
}

Share

Facebook comments:

Leave a Comment

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>