Limit Trade / Orders On Each Pair

 

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.

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


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

Please guide me how to attach this coding to mt4 ?? 
 
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.


I want that it will execute 5 orders on Each Chart where the EA is 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;
double   ToplamLot=0;

void TakeProfitTakip()
  {
   ToplamLot=0;
      for(int it=0; it<OrdersTotal(); it++)
     {
      if(OrderSelect(it,SELECT_BY_POS,MODE_TRADES)==false)
         break;
      
      
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()<2 )
           {
            //TP+=OrderProfit()+OrderSwap()+OrderCommission();
            ToplamLot+=OrderLots();
           }
        }
     }
    // if(SymbolsTotalProfitTarget>0 && TP>=SymbolsTotalProfitTarget) TotalKapat(3);
  }
void OnTick()
  {
//---
   double SAR;
static int Ticket=0;
SAR=iSAR(Symbol(),0,0.02,0.2,0);
TakeProfitTakip();
if(ToplamLot<=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 Error Codes :",GetLastError());
         }
         else
         {
      Print("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  Error Codes :",GetLastError());
         }
         else
         {
      Print("Buy Order Executed");
     }
    }
    }
    else
    {
    Alert("Orders Limits reached");
    }
  }
//+------------------------------------------------------------------+
Reason: