Limit Trade / Orders On Each Pair

To add comments, please log in or register
Muhammad Sibtain Zaffar
122
Muhammad Sibtain Zaffar  

I want to limit the number or trades/orders in MT4 using my EA in MQL4. I want the limit on each pair not on all Pairs, like: If the condition / logic match then 5 trades will be executed on Each currency where the EA is attached.

This is the code i tried, but it limits the trades on all pairs where EA has been attached.


//+------------------------------------------------------------------+
//|                                                         psar.mq4 |
//|                                                              MSZ |
//|                                                             nill |
//+------------------------------------------------------------------+
#property copyright "MSZ"
#property link      "nill"
#property version   "1.00"
#property strict
#define MAX_ORDERS 5
input int TP=10;
input int SL=30;
input double lot=1;
void OnTick()
  {
//---
   double SAR;
static int Ticket=0;
SAR=iSAR(Symbol(),0,0.02,0.2,0);
if(OrdersTotal()<=MAX_ORDERS)
{
    if(SAR>Open[0])
    {
    Ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,10,Ask+SL*Point,Ask-TP*Point,"Done By MSZ.Inc");
         if(Ticket<0)
         {
         Alert("Error In Opening Order");
         }
         else
         {
      Alert("Sell Order Executed");
     }
      //Alert("Its Sell Signal");

    }

   else if(SAR<Open[0])
    {
     Ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,10,Bid-SL*Point,Bid+TP*Point,"Done By MSZ.Inc");
         if(Ticket<0)
         {
         Alert("Error In Opening Order");
         }
         else
         {
      Alert("Buy Order Executed");
     }
    }
    }
    else
    {
    Alert("Orders Limits reached");
    }
  }
//+------------------------------------------------------------------+

I want that it will execute 5 orders on Each Chart where the EA is attached.

William Roeder
20233
William Roeder  
Muhammad Sibtain Zaffar: I want to limit the number or trades/orders in MT4 using my EA in MQL4. I want the limit on each pair not on all Pairs,
if(OrdersTotal()<=MAX_ORDERS){
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
          Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
          MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
To add comments, please log in or register