← Назад к списку файлов

another martingale fix.mq4

Поиск по коду файла

extern int MagicNumber=1;               // use for identifing order 
extern double StartLot=0.1;             // basic lot
extern int StopLoss=30;                 // stop loss
extern int TakeProfit=30;               // take profit
extern int TrailingStop=0;              // to moving out stoploss into

extern bool MoveToBreakEvent=false;     // to moving stoploss into

extern int LockedPips=1;                // small amount of pips profit

extern int RSIPeriod=9;                 // amount of bar to calculate

extern int UpperLevel=70;               // a level to determine market

extern int LowerLevel=30;               // same as above but for 

extern bool Martingale=true;            // false to deactivated this feature
extern double Multiplier=2.5;           // previous lotsize will multiplied

extern int DeepLevel=10;                // how many continue losses

extern int StartHour=0;                 // time for EA start trading
extern int EndHour=20;                  // time for EA stop trading 
       double pt,                       // custom point
       stoplevel,                       // stop level
       minlot,                          // minimal lot
       maxlot;                          // maximal lot

int ordercount()                        // we counting our order here
{
   int total=0;                         // total of our order 
   int i;                               // pos of our order 
   for(i=0; i<OrdersTotal(); i++)       // looping to count our order 

   {
       if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;  // is it right our order?
       if(OrderSymbol()!=Symbol() ||    // if symbol of order didn't match 
       OrderMagicNumber()!=MagicNumber) // with current chart symbol 
       continue;                        // or the magic numb of order 

       total++;                         // count if all criteria matched
   }
   return(total);                       // this function returned total of

}

bool checkforlosses()                   // we check our last closed order 
{                                       // from losses here 
   int losses=0;                        // total of losses
   int i;                               // pos of our order 
   for(i=0; i<OrdersHistoryTotal(); i++) // looping to check all of our
   {                                     // order history from pos 0 until

       if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue; // is it right our order?
       if(OrderSymbol()!=Symbol() ||    // if symbol of order didn't match 
       OrderMagicNumber()!=MagicNumber) // with current chart symbol 
       continue;                        // or the magic numb of order 

       if(OrderProfit()<0) losses++;    // so we count it as a losses 'cause negative profit
       else                losses=0;    // otherwise we leave it as is 
   }
   if(losses>0)  return(true);          // if last of our order is in losses

   return(false);                       // when there is no losses false will returned
}

double lastlot()                        // we will find last lot size 
{                                       // order with this function
  double lot=0;                         // lot size
  int i;                                // pos of our order 
  for(i=0; i<OrdersHistoryTotal(); i++) // looping to check all of our
   {                                     // order history from pos 0 until

       if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue; // is it right our order?
       if(OrderSymbol()!=Symbol() ||    // if symbol of order didn't match 
       OrderMagicNumber()!=MagicNumber) // with current chart symbol 
       continue;                        // or the magic numb of order 

       lot=OrderLots();                 // last lot
  }
  return(lot);                          // last lot size returned
}

double mylot()                          // we calculate for next lot here
{                                       // when a loss occured or not 
  int prec=0;                           // precision value 
  double lot,                           // lot size
         maxlotX;                       // maximal size of martingale lot 
  minlot=MarketInfo(Symbol(),MODE_MINLOT); // get brokers minimal lot size
  maxlot=MarketInfo(Symbol(),MODE_MAXLOT); // get brokers maximal lot size
  if(minlot==0.01) prec=2;              // get precision value
  if(minlot==0.1)  prec=1;              // get precision value
  maxlotX=NormalizeDouble(StartLot*MathPow(Multiplier,DeepLevel), prec); //get max.

  if(Martingale)                        // if martingale activated
  {
     if(checkforlosses())               // if last order is in losses
     {
        lot=NormalizeDouble(lastlot()*Multiplier,prec); // martingale lot
     }
     else
     {
        lot=StartLot;                   // normal lot
     }
  }  
  else
  {
     lot=StartLot;                      // normal lot
  }

  if(lot>maxlot)  return(StartLot);     // if lot size is bigger than broker rules,

  if(lot>maxlotX) return(StartLot);     // if lot size is bigger than martingale level,

  if(lot<minlot)  return(minlot);       // if lot size smaller than minlot, we change

  return(lot);                          // lot size returned
}

string getsignal()                      // we calculate trading signal here
{
   double rsi=iRSI(Symbol(),0,RSIPeriod,0,0);  // we use RSI to get signal
   if(rsi<LowerLevel) return("buy");    // buy signal returned when

   if(rsi>UpperLevel) return("sell");   // sell signal returned when

   return("wait and see");              // no signal returned
} 

int sendorder(int cmd,double lots,double prc,double sl,double tp,color warna)
{
   return(OrderSend(Symbol(),cmd,lots,prc,2,sl,tp,"",MagicNumber,0,warna));
}  

void trailingstop()                     // we check our opened order to see 
{    

Показано первые 50% кода (символов: 7093)

Как получить полную версию?

Введите ваш email и нажмите кнопку, чтобы перейти к оплате.