Author: Copyright 2021, Roman Kiverin
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MSN Color
ÿþ//+------------------------------------------------------------------+

//|                                                      ProjectName |

//|                                      Copyright 2018, CompanyName |

//|                                       http://www.companyname.net |

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

#property version     "1.0"

#property copyright   "Copyright 2021, Roman Kiverin"

#property link        "https://www.mql5.com/ru/users/romankiverin/publications"

#property description "MSN Color"

#property strict



#include <MovingAverages.mqh>



//--- indicator settings

#property  indicator_separate_window

#property  indicator_buffers 7

#property  indicator_color1  clrNONE

#property  indicator_width1  2

#property  indicator_color2  clrNONE

#property  indicator_width2  2

#property  indicator_color3  clrGray

#property  indicator_width3  1

#property  indicator_color4  clrRed

#property  indicator_width4  2

#property  indicator_color5  clrMagenta

#property  indicator_width5  2

#property  indicator_color6  clrBlue

#property  indicator_width6  2

#property  indicator_color7  clrCornflowerBlue

#property  indicator_width7  2



//--- indicator parameters

input int MaPeriod = 10;                     // Moving Average Period

input ENUM_MA_METHOD Method = MODE_SMA;      // Moving Average Method

input ENUM_APPLIED_PRICE App = PRICE_CLOSE;  // Applied to

input int APeriod = 5;                       // Average Period

input double WaitLevel = 0.00015;            // Wait Level

input double StaleLevel = 0.000175;          // Stale Level

input int CBar = 1000;                       // Maximum Bar Calculate



#define iMa(index) iMA(NULL,PERIOD_CURRENT,MaPeriod,index,Method,App,0)

#define !83<0_$C=:F8O(i) (-1+2.0/(1.0+MathExp(-(i)))) //>@<8@>20=85 <>6=> A45;0BL A ?><>ILN A83<0-DC=:F88 2840: y[i] = 2/1+exp(-x[i]) .



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

//| Calculate Colors                                                 |

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

double iFin(double Position)

  {

   int i = int(Position);

   double dRet = iMAOnArray(Map, 0, APeriod, 0, MODE_EMA, i);

   FStale[i] = FUpGrow[i] = FUpFall[i] = FDnGrow[i] = FDnFall[i] = 2147483647.0;

   if(Fin[i+1] > dRet)

     {

      if(dRet > StaleLevel)

        {

         FUpGrow[i] = dRet;

         FUpGrow[i+1] = Fin[i+1];

        }

      else

        {

         if(dRet < - WaitLevel)

           {

            FDnFall[i] = dRet;

            FDnFall[i+1] = Fin[i+1];

           }

         else

           {

            FStale[i] = dRet;

            FStale[i+1] = Fin[i+1];

           }

        }

     }

   else

     {

      if(dRet < -StaleLevel)

        {

         FDnGrow[i] = dRet;

         FDnGrow[i+1] = Fin[i+1];

        }

      else

        {

         if(dRet >  WaitLevel)

           {

            FUpFall[i] = dRet;

            FUpFall[i+1] = Fin[i+1];

           }

         else

           {

            FStale[i] = dRet;

            FStale[i+1] = Fin[i+1];

           }

        }

     }

   return dRet;

  }



double    Map[], Fin[], FStale[], FUpGrow[], FUpFall[], FDnGrow[], FDnFall[], tmp;



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

//| Custom indicator initialization function                         |

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

int OnInit(void)

  {

   IndicatorDigits(Digits+1);

//--- drawing settings

   SetIndexStyle(0, DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(0, Map);

   SetIndexStyle(1, DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(1, Fin);



   SetIndexStyle(2, DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(2, FStale);



   SetIndexStyle(3, DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(3, FUpGrow);



   SetIndexStyle(4, DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(4, FUpFall);



   SetIndexStyle(5, DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(5, FDnGrow);



   SetIndexStyle(6, DRAW_LINE);

//--- indicator buffers mapping

   SetIndexBuffer(6, FDnFall);



   IndicatorShortName("MSN Color");

   return(INIT_SUCCEEDED);

  }

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

//| Ma Speed Main Draw                                               |

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

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(prev_calculated < 1)

      for(double i = (tmp = rates_total - prev_calculated - APeriod - 2), prev = iMa(1 + (int(tmp = tmp > CBar? CBar: tmp))); i > 1;

          i--, Map[(int)i] = - prev, Map[(int)i] += prev = iMa((int)i), Map[int(i)] = !83<0_$C=:F8O(Map[int(i)]), Fin[int(i)] = iFin(i));



   Map[0] = !83<0_$C=:F8O(iMa(0) - iMa(1));

   Fin[0] = iFin(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 ---