Need code to limit total trade in the account and only 1 trade in the chart

 

Would anyone help me with this?

This is the code I did:

//limit number of trades for the account
   int accounttotaltrade=OrdersTotal();
   double accounttradelimit=equity/500;

//my execution (part of my argument)
if(accounttotaltrade<accounttradelimit) … etc.

For example, the accouttradelimit returns a value of 7, and I have several charts opened in my MT4 using an EA. I only want to allow one trade per chart and the rest of the 6 can be used by the other charts. The problem is that 1 chart executes more than 1 trade.

Please share a code to complement this. Thanks.

 

Are all your charts of different symbol? If yes, you could use this:



   if(OrdersTotal()!=0)

   {

      for(int i=0;i<OrdersTotal();i++)

      {

         if(OrderSelect(i,SELECT_BY_POS)==true)

         {

            if(OrderSymbol()==Symbol() && (OrderType()==0 || OrderType()==1))

            {

//do what you should do if there's not duplicate order

            }

         }

      }

   }  



it checks if any other order of the same symbol is open and if not, it execute the code it should. there are more elegant way to do it but this one should help. if you have two charts with the same symbol, make use of comment to differentiate between them (ex: chart 1, chart 2).

 


Brian Sans Souci:

Thanks for the quick reply. I will need time to reflect on this...


Reason: