how to open multiple trades.

 

hello there i am facing some problem 
my expert adviser are opening infinite trade till the margin become zero .
i used OrderTotal== 0   but i want to open multiple trades with the difference of 100 pip 


example : 
if my condition become true EA should open buy trade 
but if condition become true again EA should open 2 buy trade .

what should i do ??


//+------------------------------------------------------------------+
//|                                                 stastosticEA.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"


extern distance = 100;

double RealPoint;
int init()
  {

   RealPoint = RealPipPoint(Symbol());
  }



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   string single = "";

   double k0 = iStochastic(_Symbol, _Period,15,5,5,MODE_SMA,0,MODE_MAIN,0);
   double d0 = iStochastic(_Symbol, _Period,15,5,5,MODE_SMA,0,MODE_SIGNAL,0);
   double k1 = iStochastic(_Symbol, _Period,15,5,5,MODE_SMA,0,MODE_MAIN,1);
   double d1 = iStochastic(_Symbol, _Period,15,5,5,MODE_SMA,0,MODE_SIGNAL,1);
   double m21 = iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE,0);
   double m10 = iMA(_Symbol,_Period,10,0,MODE_EMA,PRICE_CLOSE,0);


// Print("the value is " +RealPoint);




//for buy entry
   if(m21 < m10)
     {
      if(k0 > d0 && k1 < d1  OrdersTotal()==0)
        {
         int buy = OrderSend(Symbol(),OP_BUY, 0.01, Ask, 0, 0,0,NULL,0,0,Green);
        }
     }

  }

// Pip Point Function
double RealPipPoint(string Currency)
  {
   double CalcPoint;
   int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
   if(CalcDigits == 2 || CalcDigits == 3)
      CalcPoint = 0.01;
   else
      if(CalcDigits == 4 || CalcDigits == 5)
         CalcPoint = 0.0001;
   return(CalcPoint);
  }

//+------------------------------------------------------------------+
 

Search in the codebase for some MT4 Stochastic EA and study it. Your EA needs at least a Magic number (unique identifier) to count the number of open orders correctly.

If you want to limit the number of open trades, test against a maximum value like MaxBuys or so:

input int InpMaxBuys=1; // max open buy orders

and

if(k0 > d0 && k1 < d1 && MyOpenBuys<InpMaxBuys)

If you want to have a difference of X pips between the orders you need to find the open order which is nearest to the Ask.

You can combine it with the loop that counts your open orders.

int MyOpenBuys(double &nearest)
  {
   int count=0;
   nearest=999999;

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==_Symbol && OrderMagicNumber()==MagicID)
        {
         if(OrderType()==OP_BUY)
           {
            count++;
            if(MathAbs(OrderOpenPrice()-Ask)<MathAbs(nearest-Ask)) nearest=OrderOpenPrice();
           }
        }
     }
   return count;
  }

and

double nearestBuy;
if(k0 > d0 && k1 < d1 && MyOpenBuys(nearestBuy)<InpMaxBuys && Ask-nearestBuy>=distance*RealPipPoint(_Symbol))
 
That's Work Thankx Mate 
Appreciated