Индикаторы: Trailing_Stop_Level

 

Trailing_Stop_Level:

Индикатор отображает на графике цены возможные уровни StopLoss. Отдельно для Long- и Short-позиций. По своей концепции похож на Mod_ATR_Trailing_Stop, но имеет иной расчет - в процентах.

Расчет:

  • Если Close[i] > TSL[i-1] и Close[i-1] > TSL[i-1]

    TSL[i] = Max(TSL[i-1], Close[i]-loss)
  • Если Close[i] < TSL[i-1] и Close[i-1] < TSL[i-1]

    TSL[i] = Min(TSL[i-1], Close[i]+loss)
  • Если Close[i] > TSL[i-1]

    TSL[i] = Close[i] - loss
  • Если Close[i] < TSL[i-1]

    TSL[i] = Close[i] + loss

где:

loss = Close[i]*Percent/100.

Автор: Scriptor

 
Automated-Trading:

Trailing_Stop_Level:

Автор: Scriptor

Привет Скриптор

можете ли вы добавить SendNotification при изменении тренда, пожалуйста.

Это было бы идеально для меня

Спасибо

Марио

 

Привет Скриптор

Не могли бы вы проверить код, что-то странное (см. изображение). Заранее спасибо. Neuch

Файлы:
Capture.JPG  149 kb
 
neuch:

Привет Скриптор

Не могли бы вы проверить код, что-то странное (см. изображение). Заранее спасибо. Neuch

// Trailing_Stop_Level_m03.mq5

***

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
The CLR_NONE constant is used to outline the absence of color, it means that the graphical object or graphical series of an indicator will not be plotted. This constant was not included into the Web-color constants list, but it can be applied everywhere where the color arguments are required. The EMPTY_VALUE constant usually corresponds to the...
 
Mario Trinchero :

// Trailing_Stop_Level_m03.mq5

***

Используйте кнопку Код

 
neuch:

Привет Скриптор

Не могли бы вы проверить код, что-то странное (см. изображение). Заранее спасибо. Neuch

// Trailing_Stop_Level_mod1.mq5

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   2
#property indicator_label1  "Level for short"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_label2  "Level for long"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

input double   InpPercent  =  0.5;

double BufferLevUP[],BufferLevDN[],BufferData[];
string IndicatorName, ShortName;

int OnInit()  {
   SetIndexBuffer(0,BufferLevUP,INDICATOR_DATA);
   SetIndexBuffer(1,BufferLevDN,INDICATOR_DATA);
   SetIndexBuffer(2,BufferData,INDICATOR_CALCULATIONS);
   IndicatorName=MQL5InfoString(MQL5_PROGRAM_NAME); 
   ShortName =IndicatorName+"("+DoubleToString(InpPercent,2)+")";
   IndicatorSetString(INDICATOR_SHORTNAME,ShortName);  
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
   ArraySetAsSeries(BufferLevUP,true);
   ArraySetAsSeries(BufferLevDN,true);
   ArraySetAsSeries(BufferData,true);
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) {
   if(rates_total<4) return 0;
   ArraySetAsSeries(close,true);
   int limit=rates_total-prev_calculated;
   if(limit>1) {
      limit=rates_total-2;
      ArrayInitialize(BufferLevUP,EMPTY_VALUE);
      ArrayInitialize(BufferLevDN,EMPTY_VALUE);
      ArrayInitialize(BufferData,0);
   }
   for(int i=limit; i>=0 && !IsStopped(); i--) {
      double loss=close[i]*InpPercent/100;
      if(close[i]>BufferData[i+1] && close[i+1]>BufferData[i+1]) {
         BufferData[i]=fmax(BufferData[i+1],close[i]-loss);
         BufferLevDN[i]=BufferData[i];
         BufferLevUP[i]=EMPTY_VALUE;
      }
      else {
         if(close[i]<BufferData[i+1] && close[i+1]<BufferData[i+1]) {
            BufferData[i]=fmin(BufferData[i+1],close[i]+loss);
            BufferLevUP[i]=BufferData[i];
            BufferLevDN[i]=EMPTY_VALUE;
         }
         else {
            if(close[i]>BufferData[i+1]) {
               BufferData[i]=close[i]-loss;
               BufferLevDN[i]=BufferData[i];
               BufferLevUP[i]=EMPTY_VALUE;
            }
            else {
               BufferData[i]=close[i]+loss;
               BufferLevUP[i]=BufferData[i];
               BufferLevDN[i]=EMPTY_VALUE;
            }
         }
      }
   }
   return(rates_total);
}
 
Vladimir Karputov:

Используйте кнопку

Спасибо Владимир