指标: Trailing_Stop_Level

 

Trailing_Stop_Level:

一款止损价位的指标。


作者: Scriptor

 
Automated-Trading:

跟踪止损水平

作者脚本

你好,脚本家

请在趋势变化时添加 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:

使用按钮

感谢弗拉基米尔