StdDev_Line_Upper

Author: Notta
Indicators Used
Moving average indicatorStandard Deviation indicator
1 Views
0 Downloads
0 Favorites
StdDev_Line_Upper
ÿþ//+------------------------------------------------------------------+

//|                                            StdDev_Line_Upper.mq5 |

//|                      https://www.mql5.com/ja/code/mt5/indicators |

//+------------------------------------------------------------------+

#property copyright "Notta"

#property link      "https://www.mql5.com/ja/code/mt5/indicators"

#property version   "1.02"

//---- cjn0-Šš[

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   1

//---- ColorLine ’0×0í0Ã0È0Y0‹0

#property indicator_label1 "StdDevUpperLine"

#property indicator_type1   DRAW_COLOR_LINE

#property indicator_color1 clrRed,clrGreen,clrBlue

#property indicator_style1 STYLE_SOLID

#property indicator_width1  3

//---- eQ›R

input int MomentumPeriod=20; // Š—{g“•

input int MomentumShift=0;   // 4ls^·0Õ0È0

input ENUM_MA_METHOD MomentumMethod=MODE_SMA;      // s^ÑnSn0.z^˜

input ENUM_APPLIED_PRICE MomentumApplied=PRICE_CLOSE; // ¡O<hn0.z^˜

input double MomentumDeviation=2;   // j–nOPî]ÿ·0°0Þ0	ÿ
P‡s



input int MomentumColorSpacing=100;// ÿr‚n0¤0ó0Ç0Ã0¯0¹0“•”–



//--- cjÐ0Ã0Õ0¡0

double         ColorLineBuffer[];

double         ColorBuffer[];

double         MABuffer[];

double         StdDevBuffer[];

//--- cjÏ0ó0É0ë0

int            MA_handle;

int            StdDev_handle;



//--- Š—{g“•,4ls^·0Õ0È0,s^ÑnSn0.z^˜,¡O<hn0.z^˜,j–nOPî]ÿ·0°0Þ0	ÿ
P‡s’0<h
}Y0‹0°0í0ü0Ð0ë0	Ype

int                  IntPeriod;

int                  IntShift;

ENUM_MA_METHOD       IntMethod;

ENUM_APPLIED_PRICE   IntApplied;

int                  IntColorSpacing;

double               Intdeviation;



//+------------------------------------------------------------------+

//| ûyÕRs^GWÚ}’0ؚ$PtPk0j–nOPî]g0܈ckW0_0«0¹0¿0à0cj           0                |

//| Ú}n03r‚Ú}’0Ïc;uY0‹0cjr‚o0 5 Æ0£0Ã0¯0T0h0k0	Y0Š0~0Y00 0 0                     |

//+------------------------------------------------------------------+

void OnInit()

 {

//--- eQ›RŠ—{g“•n0Ñ0é0á0ü0¿0’0ºxŠY0‹0

  if(MomentumPeriod<1)

    {

     IntPeriod=14;

    Print("Period parameter has an incorrect value. The following value is to be used for calculations ",IntPeriod);

    }

  else

     IntPeriod=MomentumPeriod;

//--- eQ›R4ls^·0Õ0È0n0Ñ0é0á0ü0¿0’0ºxŠY0‹0

  if(MomentumShift<0)

    {

     IntShift=0;

    Print("Shift parameter has an incorrect value. The following value is to be used for calculations ",IntShift);

    }

  else

     IntShift=MomentumShift;

//--- eQ›Rs^ÑnS.z^˜n0Ñ0é0á0ü0¿0’0ºxŠY0‹0

  if(MomentumMethod==NULL)

    {

     IntMethod=MODE_SMA;

    Print("Method parameter has an incorrect shurui. The following value is to be used for calculations ",IntMethod);

    }

  else

     IntMethod=MomentumMethod;

//--- eQ›R¡O<h.z^˜n0Ñ0é0á0ü0¿0’0ºxŠY0‹0

  if(MomentumApplied==NULL)

    {

     IntApplied=PRICE_CLOSE;

    Print("Applied parameter has an incorrect shurui. The following value is to be used for calculations ",IntApplied);

    }

  else

     IntApplied=MomentumApplied;

//--- eQ›Rj–nOPî]ÿ·0°0Þ0	ÿ
P‡sn0Ñ0é0á0ü0¿0’0ºxŠY0‹0

  if(MomentumDeviation<=0)

    {

     Intdeviation=2;

    Print("Shift parameter has an incorrect value. The following value is to be used for calculations ",Intdeviation);

    }

  else

     Intdeviation=MomentumDeviation;

//--- eQ›Rÿr‚n0¤0ó0Ç0Ã0¯0¹0“•”–n0Ñ0é0á0ü0¿0’0ºxŠY0‹0

  if(MomentumColorSpacing<1)

    {

     IntColorSpacing=100;

    Print("Period parameter has an incorrect value. The following value is to be used for calculations ",IntPeriod);

    }

  else

     IntColorSpacing=MomentumColorSpacing;



//--- cjÐ0Ã0Õ0¡0Þ0Ã0Ô0ó0°0

  SetIndexBuffer(0,ColorLineBuffer,INDICATOR_DATA);

  SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);



//--- ·0Õ0È0’0-Šš[

  PlotIndexSetInteger(0,PLOT_SHIFT,IntShift);  



//--- MAÊSs0StdDevÏ0ó0É0ë0n0ÖS—_

  MA_handle    =iMA(Symbol(),0,IntPeriod,IntShift,IntMethod,IntApplied);

  StdDev_handle=iStdDev(Symbol(),0,IntPeriod,IntShift,IntMethod,IntApplied);

//---

 }

//+------------------------------------------------------------------+

//| r‚¤0ó0Ç0Ã0¯0¹0’0ÖS—_                                                   |

//+------------------------------------------------------------------+

int getIndexOfColor(int i)

 {

  int j=i%(IntColorSpacing*3);

  if(j<IntColorSpacing) return(0);// 1 juîvn0¤0ó0Ç0Ã0¯0¹0

  if(j<(IntColorSpacing*2)) return(1);// 2 juîvn0¤0ó0Ç0Ã0¯0¹0

  return(2); // 3 juîvn0¤0ó0Ç0Ã0¯0¹0

 }

//+------------------------------------------------------------------+

//| «0¹0¿0à0cjn0ÍS©_¢•pe                                                |

//+------------------------------------------------------------------+

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[])

 {

//---

  static int ticks=0,modified=0;

  int limit;

//--- R0f0n0Š—{0~0_0o0Ð0ü0n0peL0	Y0c0_0

  if(prev_calculated==0)

    {

    //--- MA n0$P’0 MABuffer cjÐ0Ã0Õ0¡0k0‰ýˆY0‹0

    int copied_0 = CopyBuffer(MA_handle,0,-IntShift,rates_total,MABuffer);

    if(copied_0<=0) return(0);// ‰ýˆk01YWe0Ã^ÄhY0‹00

    //--- StdDev n0$P’0 StdDevBuffer cjÐ0Ã0Õ0¡0k0‰ýˆY0‹0

    int copied_1 = CopyBuffer(StdDev_handle,0,-IntShift,rates_total,StdDevBuffer);

    if(copied_1<=0) return(0);// ‰ýˆk01YWe0Ã^ÄhY0‹00

    //--- MA n0$Pk00StdDev n0$P’00ؚ$PtPg0܈ckW0f00hˆ:y(ucjÐ0Ã0Õ0¡0k0<h
}Y0‹0

    for(int i=0;i<rates_total;i++)

        ColorLineBuffer[i]=MABuffer[i]+(StdDevBuffer[i]*Intdeviation);

    //--- Ð0ü0hQèg0Ú}n0r‚’0-Šš[

    for(int i=0;i<rates_total;i++)

        ColorBuffer[i]=getIndexOfColor(i);

    }

  else

    {

    //--- MA n0$P’0 MABuffer cjÐ0Ã0Õ0¡0k0‰ýˆY0‹0

    int copied_0 = CopyBuffer(MA_handle,0,-IntShift,rates_total,MABuffer);

    if(copied_0<=0) return(0);// ‰ýˆk01YWe0Ã^ÄhY0‹00

    //--- StdDev n0$P’0 StdDevBuffer cjÐ0Ã0Õ0¡0k0‰ýˆY0‹0

    int copied_1 = CopyBuffer(StdDev_handle,0,-IntShift,rates_total,StdDevBuffer);

    if(copied_1<=0) return(0);// ‰ýˆk01YWe0Ã^ÄhY0‹00

    //--- MA n0$Pk00StdDev n0$P’00ؚ$PtPg0܈ckW0f00hˆ:y(ucjÐ0Ã0Õ0¡0k0<h
}Y0‹0

    for(int i=0;i<rates_total;i++)

        ColorLineBuffer[i]=MABuffer[i]+(StdDevBuffer[i]*Intdeviation);

 

     ticks++;// Æ0£0Ã0¯0’0peH0‹0

    if(ticks>=5)//úW,gM‘r‚’0	YôfY0‹0Bf

       {

        ticks=0; // «0¦0ó0¿0’0ê0»0Ã0È0

        modified++; // r‚	YÛcn0«0¦0ó0¿0

        if(modified>=3)modified=0;// «0¦0ó0¿0’0ê0»0Ã0È0

        ResetLastError();

        switch(modified)

          {

          case 0:// 1 juîvn0úW,gM‘r‚

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed);

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrBlue);

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrGreen);

              Print("Color scheme ",modified);

              break;

          case 1:// 2 juîvn0úW,gM‘r‚

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrYellow);

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrPink);

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLightSlateGray);

              Print("Color scheme ",modified);

              break;

          default:// 3 juîvn0úW,gM‘r‚

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrLightGoldenrod);

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrOrchid);

              PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLimeGreen);

              Print("Color scheme ",modified);

          }

       }

    else

       {

        //--- ‹•ËYMOn’0-Šš[

        limit=prev_calculated-1;

        //--- Ð0ü0hQèg0Ú}n0r‚’0-Šš[

        for(int i=limit;i<rates_total;i++)

           ColorBuffer[i]=getIndexOfColor(i);

       }

    }

//--- !kn0|Ts0úQW0n0_00k0 prev_calculated n0$P’0ԏY0

  return(rates_total);

 }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---