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

mqlta mt4 high low trailing stop.mq4

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

#property version       "1.01"
#property strict

#property description   "This Expert Advisor will Trail the Stop Loss Price" 
#property description   "setting it to a recent High Or Low."
#property description   " "
#property description   "WARNING : You use this software at your own risk."
#property description   "The creator of these plugins cannot be held responsible for any damage or loss."
#property description   " "
#property description   "Find More on EarnForex.com"
#property icon          "\\Files\\EF-Icon-64x64px.ico"

#include <MQLTA ErrorHandling.mqh>
#include <MQLTA Utils.mqh>

enum ENUM_CONSIDER{
   All=-1,        //ALL ORDERS
   Buy=OP_BUY,    //BUY ONLY
   Sell=OP_SELL,  //SELL ONLY
};

enum ENUM_CUSTOMTIMEFRAMES{
   CURRENT=PERIOD_CURRENT,             //CURRENT PERIOD
   M1=PERIOD_M1,                       //M1
   M5=PERIOD_M5,                       //M5
   M15=PERIOD_M15,                     //M15
   M30=PERIOD_M30,                     //M30
   H1=PERIOD_H1,                       //H1
   H4=PERIOD_H4,                       //H4
   D1=PERIOD_D1,                       //D1
   W1=PERIOD_W1,                       //W1
   MN1=PERIOD_MN1,                     //MN1
};

input string Comment_1="====================";     //Expert Advisor Settings
input int BarsToScan=5;                                //Bars To Scan (5=Last Five Candles)
input string Comment_2="====================";           //Orders Filtering Options
bool OnlyCurrentSymbol=true;                       //Apply To Current Symbol Only
input ENUM_CONSIDER OnlyType=All;                        //Apply To
input bool UseMagic=false;                               //Filter By Magic Number
input int MagicNumber=0;                                 //Magic Number (if above is true)
input bool UseComment=false;                             //Filter By Comment
input string CommentFilter="";                           //Comment (if above is true)
input bool EnableTrailingParam=false;                    //Enable Trailing Stop
input string Comment_3="====================";     //Notification Options
input bool EnableNotify=false;                    //Enable Notifications feature
input bool SendAlert=true;                        //Send Alert Notification
input bool SendApp=true;                          //Send Notification to Mobile
input bool SendEmail=true;                        //Send Notification via Email
input string Comment_3a="====================";           //Graphical Window
input bool ShowPanel=true;                              //Show Graphical Panel
input string IndicatorName="MQLTA-HLTS";          //Indicator Name (to name the objects)
input int Xoff=20;                                //Horizontal spacing for the control panel
input int Yoff=20;                                //Vertical spacing for the control panel

int OrderOpRetry=5;
int SuperTrendShift=0;

double TrendUpTmp[], TrendDownTmp[];
int changeOfTrend;
int MaxBars=BarsToScan+1;
bool EnableTrailing=EnableTrailingParam;

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

void OnDeinit(const int reason){
   CleanPanel();

}

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

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam){

   if(id==CHARTEVENT_OBJECT_CLICK){
      if(sparam==PanelEnableDisable){
         ChangeTrailingEnabled();
      }
   }
   if(id==CHARTEVENT_KEYDOWN){
      if(lparam==27){
         if(MessageBox("Are you sure you want to close the EA?","EXIT ?",MB_YESNO)==IDYES){
            ExpertRemove();
         }
      }
   }

}

double GetStopLossBuy(){
   double SLValue=iLow(Symbol(),PERIOD_CURRENT,iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,BarsToScan,0));
   return SLValue;
}

double GetStopLossSell(){
   double SLValue=iHigh(Symbol(),PERIOD_CURRENT,iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,BarsToScan,0));
   return SLValue;
}

void TrailingStop(){
   for(int i=0;i<OrdersTotal();i++) {
      if(OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) {
         int Error=GetLastError();
         string ErrorText=GetLastErrorText(Error);
         Print("ERROR - Unable to select the order - ",Error);
         Print("ERROR - ",ErrorText);
         break;
      }
      if(OnlyCurrentSymbol && OrderSymbol()!=Symbol()) continue;
      if(UseMagic && OrderMagicNumber()!=MagicNumber) continue;
      if(UseComment && StringFind(OrderComment(),CommentFilter)<0) continue;
      if(OnlyType!=All &&OrderType()!=OnlyType) continue;

      double NewSL=0;
      double NewTP=0;
      string Instrument=OrderSymbol();
      double SLBuy=GetStopLossBuy();
      double SLSell=GetStopLossSell();
      if(SLBuy==0 || SLSell==0){
         Print("Not enough historical data, please load more candles for The selected timeframe");
         return;
      }

      int eDigits = (int)MarketInfo(Instrument,MODE_DIGITS);
      double SLPrice=NormalizeDouble(OrderStopLoss(),eDigits);
      double TPPrice=NormalizeDouble(OrderTakeProfit(),eDigits);
      double Spread=MarketInfo(Instrument,MODE_SPREAD)*MarketInfo(Instrument,MODE_POINT);
      double StopLevel=MarketInfo(Instrument,MODE_STOPLEVEL)*MarketInfo(Instrument,MODE_POINT);

      if(OrderType()==OP_BUY && SLBuy<MarketInfo(Instrument,MODE_BID)-StopLevel){
         NewSL=NormalizeDouble(SLBuy,eDigits);
         NewTP=TPPrice;

         if(NewSL>SLPrice+StopLevel || SLPrice==0){
            ModifyOrder(OrderTicket(),OrderOpenPrice(),NewSL,NewTP);
         }
      }
      if(OrderType()==OP_SELL &

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

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

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