AnchoredMomentum_x10

Author: Copyright © 2018, Nikolay Kositsin
Price Data Components
0 Views
0 Downloads
0 Favorites
AnchoredMomentum_x10
ÿþ//+------------------------------------------------------------------+

//|                                         AnchoredMomentum_x10.mq5 |

//|                               Copyright © 2018, Nikolay Kositsin |

//|                              Khabarovsk,   farria@mail.redcom.ru | 

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

#property copyright "Copyright © 2018, Nikolay Kositsin"

#property link      "farria@mail.redcom.ru"

#property description "=48:0B>@ >B>1@0605B ?>;>65=85 >AF8;;OB>@0 AnchoredMomentum A @07=KE B09<D@59<>2"

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.00"

//---- >B@8A>2:0 8=48:0B>@0 2 3;02=>< >:=5

#property indicator_chart_window

//---- :>;8G5AB2> 8=48:0B>@=KE 1CD5@>2 0

#property indicator_buffers 0 

//---- =5 8A?>;L7>20=> =8 >4=>3> 3@0D8G5A:>3> ?>AB@>5=8O

#property indicator_plots   0

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

//|  >1JO2;5=85 :>=AB0=B              |

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

#define RESET 0          // >=AB0=B0 4;O 2>72@0B0 B5@<8=0;C :><0=4K =0 ?5@5AGQB 8=48:0B>@0

#define INDTOTAL 10      // >=AB0=B0 4;O :>;8G5AB20 >B>1@0605<KE 8=48:0B>@>2

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

// ?8A0=85 ?5@5G8A;5=8O type_font               |

// ?8A0=85 :;0AA0 CFontName                     | 

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

#include <GetFontName.mqh>

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

//| E>4=K5 ?0@0<5B@K 8=48:0B>@0                 |

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

input ENUM_TIMEFRAMES TimeFrame0=PERIOD_H1;           //?5@8>4 3@0D8:0 1

input ENUM_TIMEFRAMES TimeFrame1=PERIOD_H2;           //?5@8>4 3@0D8:0 2

input ENUM_TIMEFRAMES TimeFrame2=PERIOD_H3;           //?5@8>4 3@0D8:0 3

input ENUM_TIMEFRAMES TimeFrame3=PERIOD_H4;           //?5@8>4 3@0D8:0 4

input ENUM_TIMEFRAMES TimeFrame4=PERIOD_H6;           //?5@8>4 3@0D8:0 5

input ENUM_TIMEFRAMES TimeFrame5=PERIOD_H8;           //?5@8>4 3@0D8:0 6

input ENUM_TIMEFRAMES TimeFrame6=PERIOD_H12;          //?5@8>4 3@0D8:0 7

input ENUM_TIMEFRAMES TimeFrame7=PERIOD_D1;           //?5@8>4 3@0D8:0 8

input ENUM_TIMEFRAMES TimeFrame8=PERIOD_W1;           //?5@8>4 3@0D8:0 9

input ENUM_TIMEFRAMES TimeFrame9=PERIOD_MN1;          //?5@8>4 3@0D8:0 10 

//---- 0@0<5B@K AnchoredMomentum

input uint MomPeriod=8; //?5@8>4 SMA 

input uint SmoothPeriod=6; //?5@8>4 EMA

input ENUM_APPLIED_PRICE IPC=PRICE_CLOSE;//F5=>20O :>=AB0=B0, ?> :>B>@>9 ?@>872>48BAO @0AGQB 8=48:0B>@0

input double UpLevel=+0.025; //C@>25=L ?5@5:C?;5==>AB8

input double DnLevel=-0.025; //C@>25=L ?5@5?@>40==>AB8

//----

input color  CpColor=clrBlueViolet;                   //F25B =0720=8O 8=48:0B>@0

input color  UpColor=clrTeal;                         //F25B ?5@5:C?;5==>AB8 8=48:0B>@0

input color  ZrColor=clrGray;                         //F25B 157 87<5=5=8O

input color  DnColor=clrViolet;                       //F25B ?5@5?@>40==>AB8 8=48:0B>@0

input int    FontSize=11;                             //@07<5@ H@8DB0

input type_font FontType=Font14;                      //B8? H@8DB0

input ENUM_BASE_CORNER  WhatCorner=CORNER_LEFT_LOWER; //C3>; @0A?>;>65=8O

input uint Y_=20;                                     //@0A?>;>65=85 ?> 25@B8:0;8

input uint X_=5;                                      //@0A?>;>65=85 ?> 3>@87>=B0;8

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

string sFontType;

int min_rates_total;

uint xshift,shift[11];

string sPer[10],sPerA[10],sPerB[10],Cap;

ENUM_TIMEFRAMES ePer[10];

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

//| >;CG5=85 B09<D@59<0 2 2845 AB@>:8                               |

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

string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)

  {return(StringSubstr(EnumToString(timeframe),7,-1));}

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

//|  ;0AA <0AA82>2                                                  |

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

class CIndArrow

  {

   //----

public:

   double            m_Ind[1];

   int               m_Handle;

   ENUM_TIMEFRAMES   m_TimeFrame;

   //---- 

  };

//---- >1JO2;5=85 <0AA82>2, :>B>@K5 1C4CB 2 

// 40;L=59H5< 8A?>;L7>20=K 4;O ?>;CG5=8O 8=48:0B>@=KE 7=0G5=89

CIndArrow Ind[INDTOTAL];

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

//| Custom indicator initialization function                         | 

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

int OnInit()

  {

//----  

   ePer[0]=TimeFrame0;

   ePer[1]=TimeFrame1;

   ePer[2]=TimeFrame2;

   ePer[3]=TimeFrame3;

   ePer[4]=TimeFrame4;

   ePer[5]=TimeFrame5;

   ePer[6]=TimeFrame6;

   ePer[7]=TimeFrame7;

   ePer[8]=TimeFrame8;

   ePer[9]=TimeFrame9;

   for(int poz=0; poz<INDTOTAL; poz++) Ind[poz].m_TimeFrame=ePer[poz];

//---- >;CG5=85 E5=4;>2 8=48:0B>@>2

   for(int poz=0; poz<INDTOTAL; poz++)

     {

      Ind[poz].m_Handle=iCustom(Symbol(),Ind[poz].m_TimeFrame,"AnchoredMomentum",MomPeriod,SmoothPeriod,IPC,UpLevel,DnLevel,0);



      if(Ind[poz].m_Handle==INVALID_HANDLE)

        {

         Print("OnInit()(",poz,"): 5 C40;>AL ?>;CG8BL E5=4; 8=48:0B>@0 AnchoredMomentum");

         return(false);

        }

     }

//----   

   CFontName FONT;

   sFontType=FONT.GetFontName(FontType);

   Deinit();

   min_rates_total=int(MomPeriod)+1;

   min_rates_total++;

//----  

   xshift=int(X_+8.3*FontSize);

   Cap="AnchoredMomentum_x10";

//----

   switch(WhatCorner)

     {

      case CORNER_RIGHT_LOWER:

        {

         for(int poz=0; poz<=INDTOTAL; poz++) shift[10-poz]=Y_+22*poz;

         break;

        }



      case CORNER_LEFT_LOWER:

        {

         for(int poz=0; poz<=INDTOTAL; poz++) shift[10-poz]=Y_+22*poz;

         break;

        }

      default:

        {

         for(int poz=0; poz<=INDTOTAL; poz++) shift[poz]=Y_+22*poz;

        }

     }



   for(int poz=0; poz<INDTOTAL; poz++)

     {

      sPer[poz]=GetStringTimeframe(ePer[poz]);

      sPerA[poz]=sPer[poz]+"Stat+";

      sPerB[poz]=sPer[poz]+"Stat_";

     }

//--- 7025@H5=85 8=8F80;870F88

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//----

   Deinit();

//----

   ChartRedraw(0);

  }

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

//| Custom indicator deinitialization function                       |

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

void Deinit()

  {

//----

   for(int poz=0; poz<INDTOTAL; poz++)

     {

      ObjectDelete(0,sPerA[poz]);

      ObjectDelete(0,sPerB[poz]);

     }

   ObjectDelete(0,Cap);

//----

  }

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

//|  !>740=85 B5:AB>2>9 ;591K                                        |

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

void CreateTLabel

(

 long   chart_id,         // 845=B8D8:0B>@ 3@0D8:0

 string name,             // 8<O >1J5:B0

 int    nwin,             // 8=45:A >:=0

 ENUM_BASE_CORNER corner,// ?>;>65=85 C3;0 ?@82O7:8

 ENUM_ANCHOR_POINT point, // ?>;>65=85 B>G:8 ?@82O7:8

 int    X,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 X >B C3;0 ?@82O7:8

 int    Y,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 Y >B C3;0 ?@82O7:8

 string text,             // B5:AB

 color  Color,            // F25B B5:AB0

 string Font,             // H@8DB B5:AB0

 int    Size              // @07<5@ H@8DB0

 )

//---- 

  {

//----

   ObjectCreate(chart_id,name,OBJ_LABEL,0,0,0);

   ObjectSetInteger(chart_id,name,OBJPROP_CORNER,corner);

   ObjectSetInteger(chart_id,name,OBJPROP_ANCHOR,point);

   ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,X);

   ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,Y);

   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

   ObjectSetString(chart_id,name,OBJPROP_FONT,Font);

   ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,Size);

   ObjectSetInteger(chart_id,name,OBJPROP_BACK,false);

//----

  }

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

//|  5@5CAB0=>2:0 B5:AB>2>9 ;591K                                   |

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

void SetTLabel

(

 long   chart_id,         // 845=B8D8:0B>@ 3@0D8:0

 string name,             // 8<O >1J5:B0

 int    nwin,             // 8=45:A >:=0

 ENUM_BASE_CORNER corner,// ?>;>65=85 C3;0 ?@82O7:8

 ENUM_ANCHOR_POINT point, // ?>;>65=85 B>G:8 ?@82O7:8

 int    X,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 X >B C3;0 ?@82O7:8

 int    Y,                // 48AB0=F8O 2 ?8:A5;OE ?> >A8 Y >B C3;0 ?@82O7:8

 string text,             // B5:AB

 color  Color,            // F25B B5:AB0

 string Font,             // H@8DB B5:AB0

 int    Size              // @07<5@ H@8DB0

 )

//---- 

  {

//----

   if(ObjectFind(chart_id,name)==-1) CreateTLabel(chart_id,name,nwin,corner,point,X,Y,text,Color,Font,Size);

   else

     {

      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);

      ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,X);

      ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,Y);

      ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);

     }

//----

  }

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

//| Custom indicator iteration function                              | 

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

int OnCalculate(

                const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

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

                )

  {

//--- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AG5B0

   for(int poz=0; poz<INDTOTAL; poz++) if(Bars(Symbol(),ePer[poz])<min_rates_total) return(RESET);



//---- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K 

   for(int poz=0; poz<INDTOTAL; poz++) if(CopyBuffer(Ind[poz].m_Handle,MAIN_LINE,1,1,Ind[poz].m_Ind)<=0) return(RESET);

//----

   color ColorGain[INDTOTAL];

   ArrayInitialize(ColorGain,ZrColor);

//---- :>?8@C5< 2=>2L ?>O282H85AO 40==K5 2 <0AA82K 

   for(int poz=0; poz<INDTOTAL; poz++)

     {

      if(Ind[poz].m_Ind[0]>UpLevel) ColorGain[poz]=UpColor;

      if(Ind[poz].m_Ind[0]<DnLevel) ColorGain[poz]=DnColor;

     }

//----

   for(int poz=0; poz<INDTOTAL; poz++)

     {

      SetTLabel(0,sPerA[poz],0,WhatCorner,ENUM_ANCHOR_POINT(2*WhatCorner),X_,shift[poz+1],sPer[poz]+": ",ColorGain[poz],sFontType,FontSize);

      SetTLabel(0,sPerB[poz],0,WhatCorner,ENUM_ANCHOR_POINT(2*WhatCorner),xshift,shift[poz+1],"n",ColorGain[poz],"Wingdings",FontSize);

     }

   SetTLabel(0,Cap,0,WhatCorner,ENUM_ANCHOR_POINT(2*WhatCorner),X_,shift[0],Cap,CpColor,sFontType,FontSize);

//----

   ChartRedraw(0);

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