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

lsma_ea.mq4

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

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

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

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

#include <stdlib.mqh>

extern string  Expert_Name    = "LSMA_EA";
extern int     MagicNumberBase = 200000;
extern string  UserComment = "LSMA_EA";
extern string  in="---Indicator settings---";
extern string  p = "--Applied Price Types--";
extern string  p0 = " 0 = close";
extern string  p1 = " 1 = open";
extern string  p2 = " 2 = high";
extern string  p3 = " 3 = low";
extern string  p4 = " 4 = median(high+low)/2";
extern string  p5 = " 5 = typical(high+low+close)/3";
extern string  p6 = " 6 = weighted(high+low+close+close)/4";
extern int     LSMA_Period=7;
extern int     LSMA_AppliedPrice = 0;
extern double  EntryDif_Threshold=10;   // What size angle to trigger a trade
extern double  ExitDif_Threshold=2;
extern int     PrevMAShift=3;
extern int     CurMAShift=1;

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 LSMA(int Rperiod, int prMode, int shift)
{
   int i, myShift;
   double sum, pr;
   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;
     myShift = length - i + shift;
     switch (prMode)
     {
     case 0: pr = iClose(NULL,0,myShift);break;
     case 1: pr = iOpen(NULL,0,myShift);break;
     case 2: pr = iHigh(NULL,0,myShift);break;
     case 3: pr = iLow(NULL,0,myShift);break;
     case 4: pr = (iHigh(NULL,0,myShift) + iLow(NULL,0,myShift))/2;break;
     case 5: pr = (iHigh(NULL,0,myShift) + iLow(NULL,0,myShift) + iClose(NULL,0,myShift))/3;break;
     case 6: pr = (iHigh(NULL,0,myShift) + iLow(NULL,0,myShift) + iClose(NULL,0,myShift) + iClose(NULL,0,myShift))/4;break;
     }
     tmp = ( i - lengthvar)*pr;
     sum+=tmp;
    }
    wt = sum*6/(length*(length+1));
    wt = MathFloor(wt/Point)*Point;

    return(wt);
}

double MA_Dif( int PrevShift, int CurShift)
{
   double fDif, mFactor;
   double fCurMA, fPrevMA;
   string Sym;
   int ShiftDif;

   mFactor = 100000.0;
   Sym = StringSubstr(Symbol(),3,3);
   if (Sym == "JPY") mFactor = 1000.0;
   ShiftDif = PrevShift-CurShift;
   mFactor /= ShiftDif; 
   fCurMA=LSMA(LSMA_Period,LSMA_AppliedPrice,CurShift);
   fPrevMA=LSMA(LSMA_Period,LSMA_AppliedPrice,PrevShift);

   fDif = mFactor * (fCurMA - fPrevMA)/2.0;

    return(fDif);
}

bool CheckExitCondition(int cmd)
{
	double maDif;

	maDif = MA_Dif(PrevMAShift, CurMAShift);
   switch (cmd)
   {
      case OP_BUY : if (maDif < ExitDif_Threshold) return(true);
                    break;
      case OP_SELL : if (maDif > -ExitDif_Threshold) return(true);
   }

   return(false);
}

bool CheckEntryCondition(int cmd)
{

	double maDif;

	maDif = MA_Dif(PrevMAShift, CurMAShift);
   switch (cmd)
   {
      case OP_BUY : if (maDif > EntryDif_Threshold) return(true);
                    break;
      case OP_SELL : if (maDif < -EntryDif_Threshold) return(true);
   }

   return(false);

}

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 (Dig

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

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

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

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

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