← К каталогу
Исходный код · ID 255

lsma_anytimeframe_ea_v1.1.mq4

Вы автор или правообладатель?

Сообщите нам, если считаете, что материал размещён без разрешения.

Получить полный код

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

#include <stdlib.mqh>

extern string  Expert_Name    = "LSMA_AnyTF";
extern int     MagicNumberBase = 200000;
extern string  UserComment = "LSMA_EA";
extern string  in="---Indicator settings---";
extern int     LSMAShortPeriod=7;
extern int     LSMALongPeriod=16;
extern int     MonthStart = 1;
extern int     MonthEnd = 12;
extern bool    UseFreshCross = true;

extern string  mm = "---Money Management---";
extern double  Lots=1.0;
extern double  MaxLots = 100;
extern bool    UseMoneyManagement = true; // Change to false to shutdown money management controls.
extern bool    BrokerIsIBFX = false;
extern string  m1="Set mini and micro to false for standard account";
extern bool    AccountIsMini = false;
extern bool    AccountIsMicro = false;
extern string  fm="UseFreeMargin = false to use Account Balance";
extern bool    UseFreeMargin = false;
extern double  TradeSizePercent = 10;  // Change to whatever percent of equity you wish to risk.
extern bool    BrokerPermitsFractionalLots = true;

extern string  st6 = "--Profit Controls--";
extern double  StopLoss=0;
extern double  TakeProfit=0;
extern int     Slippage=3;
extern string  db0="---Flag to run start once per bar---";
extern string  db1=" Set to false when using stoploss";
extern string  db2=" takeprofit or trailing stop";
extern bool    UseOncePerBar = true;

int            MagicNumber=0;
string         setup;
int            TradesInThisSymbol = 0;
double         mLots=0;
datetime       timeprev = 0;

int init()
{
      // код доступен только после оплаты
   }

int deinit()
{
 return(0);
}

double LSMADaily(int Rperiod, int shift)
{
   int i;
   double sum;
   int length;
   double lengthvar;
   double tmp;
   double wt;

     length = Rperiod;

     sum = 0;
     for(i = length; i >= 1  ; i--)
     {
       lengthvar = length + 1;
       lengthvar /= 3;
       tmp = 0;
       tmp = ( i - lengthvar)*iClose(NULL,0,length-i+shift);
       sum+=tmp;
      }
      wt = sum*6/(length*(length+1));

    return(wt);
}

bool CheckExitCondition(int TradeType)
{
   bool YesClose;
   double L_Fast,L_Slow;

   YesClose = false;
   L_Fast=LSMADaily(LSMAShortPeriod,1);
   L_Slow=LSMADaily(LSMALongPeriod,1);

   if (TradeType == OP_BUY)
   {
      if (L_Fast < L_Slow) YesClose = true;
   }
   if (TradeType == OP_SELL)
   {
    if (L_Fast > L_Slow) YesClose = true;
   }

   return (YesClose);
}

bool CheckEntryCondition(int TradeType)
{
   bool YesTrade;
   double L_Fast,L_Slow;
   double L_FastPrev,L_SlowPrev;

   L_Fast=LSMADaily(LSMAShortPeriod,1);
   L_Slow=LSMADaily(LSMALongPeriod,1);

   YesTrade = false;

   if (TradeType == OP_BUY)
   {
    if ( L_Fast > L_Slow)
    {
       if (UseFreshCross == true)
       {
         L_FastPrev=LSMADaily(LSMAShortPeriod,2);
         L_SlowPrev=LSMADaily(LSMALongPeriod,2);
         if (L_FastPrev < L_SlowPrev) YesTrade = true; else YesTrade = false;
       }
       else
         YesTrade = true;
     }
   }

   if (TradeType == OP_SELL)
   {
     if ( L_Fast < L_Slow)
     {
       if (UseFreshCross == true)
       {
         L_FastPrev=LSMADaily(LSMAShortPeriod,2);
         L_SlowPrev=LSMADaily(LSMALongPeriod,2);
         if (L_FastPrev > L_SlowPrev) YesTrade = true; else YesTrade = false;
       }
       else
         YesTrade = true;
     }
   }

   return (YesTrade);
}

int start()
{
      // код доступен только после оплаты
   }

double GetLots()
{
   double lot;

   if(UseMoneyManagement == true)
   {
     lot = LotsOptimized();
   }
   else
   {
      lot = Lots;
   }

   if (AccountIsMicro == true)
   {
      if (lot < 0.01) lot = 0.01;
      if (lot > MaxLots) lot = MaxLots * 100;
      if (BrokerIsIBFX == true) lot = lot * 10;
      return(lot);
   }

   if(AccountIsMini == true)
   {
      if (lot < 0.1) lot = 0.1;
      if (lot > MaxLots) lot = MaxLots;
      if (BrokerIsIBFX == true) lot = lot * 10;
      return(lot);
   }

   if( BrokerPermitsFractionalLots == false)
   {
      if (lot >= 1.0) lot = MathFloor(lot); else lot = 1.0;
   }

   if (lot > MaxLots) lot = MaxLots;

   return(lot);
}

double LotsOptimized()
  {
   double lot=Lots;

   if (UseFreeMargin == true)
        lot=NormalizeDouble(MathFloor(AccountFreeMargin()*TradeSizePercent/10000)/10,1);
   else
        lot=NormalizeDouble(MathFloor(AccountBalance()*TradeSizePercent/10000)/10,1);

  if(AccountIsMini == true)
  {
    lot = MathFloor(lot*10)/10;
  }

   return(lot);
} 

int OpenBuyOrder(double mLots, double mStopLoss, double mTakeProfit, int mSlippage, string mComment, int mMagic, color mColor)
{
   int err,ticket;
   double myPrice, myStopLoss = 0, myTakeProfit = 0;

   RefreshRates();
   myStopLoss = StopLong(Bid,mStopLoss);
   myTakeProfit = TakeLong(Bid,mTakeProfit);

   if (Digits > 0) 
   {
     myPrice = NormalizeDouble( Ask, Digits);
     myStopLoss = NormalizeDouble( myStopLoss, Digits);
     myTakeProfit = NormalizeDouble( myTakeProfit, Digits); 
   }
   ticket=OrderSend(Symbol(),OP_BUY,mLots,myPrice,mSlippage,myStopLoss,myTakeProfit,mComment,mMagic,0,mColor); 
   if (ticket > 0)
   {

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

Что вы получите после оплаты

На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.

Чтобы оформить заказ, введите email и перейдите к оплате.

Стоимость полного кода
857₽