Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
Donch_pos
ÿþ#property strict



#property indicator_separate_window

#property indicator_level1  50

#property indicator_level2  50

#property indicator_level3  0

#property indicator_buffers 2

#property  indicator_color1  clrWhite

#property  indicator_color2  clrGreen

#property  indicator_width2  2



//--- input parameters

enum MODE

{

PTS,    //Points

PARTS,  //Parts

PRC,    //Percents

};



extern MODE               Output=PRC;

extern bool               Close_Price_Based = false;

extern int                iPeriod = 60;

input ENUM_APPLIED_PRICE  Signal  = PRICE_CLOSE;

extern int                Smooth  = 0;

extern int                Level_up    = 61;

extern int                Level_down  = -61;

extern int                LIMIT   = 2000;



double result[],MA[];



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   

   if(iPeriod < 2) iPeriod=2;

   if(LIMIT<10) LIMIT=Bars-iPeriod-Smooth;



   SetIndexBuffer(0,result);   

   SetIndexStyle (0,DRAW_LINE);// Line style

   

   SetIndexBuffer(1,MA);   

   SetIndexStyle (1,DRAW_LINE);// Line style

   

   SetLevelValue(0,Level_up);

   SetLevelValue(1,Level_down);

   

   IndicatorSetString(INDICATOR_LEVELTEXT,2,"   Zero");

   

   if(Output==PARTS)

    {

     IndicatorSetDouble(INDICATOR_MAXIMUM,+1.1);

     IndicatorSetDouble(INDICATOR_MINIMUM,-1.1);

    }

   if(Output==PRC)

    {

     IndicatorSetDouble(INDICATOR_MAXIMUM,+105);

     IndicatorSetDouble(INDICATOR_MINIMUM,-105);

    }

 /*  if(Output==PTS)

    {

     IndicatorSetDouble(INDICATOR_MAXIMUM,0,0);

     IndicatorSetDouble(INDICATOR_MINIMUM,0,0);

    }*/



   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator iteration function                              |

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

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

  {



   int limit;



   if(prev_calculated>rates_total || prev_calculated<=0) {

      limit=rates_total-1;

   }

   else limit=rates_total-prev_calculated;

   

   if(limit>LIMIT) limit=LIMIT;

   

   double hst,lst,curr;

   

   if(Output!=PTS)

   for (int i=limit; i>=0 && !IsStopped(); i--) 

    {

      hst  = Close_Price_Based?Close[iHighest(NULL, 0, MODE_CLOSE, iPeriod, i)]:High[iHighest(NULL, 0, MODE_HIGH, iPeriod, i)];

      lst  = Close_Price_Based?Close[iLowest (NULL, 0, MODE_CLOSE, iPeriod, i)]:Low [iLowest (NULL, 0, MODE_LOW , iPeriod, i)];

      curr = iMA(NULL,0,1,0,MODE_SMA,Signal,i);

      if(hst!=lst) result[i] = (curr-lst)/(hst-lst)*200-100;

      if(Output==PARTS) result[i]/=100;

      if(Smooth<2) continue;

      MA[i]=0;//iMAOnArray(result,0,Smooth,0,Mode,i);

      for (int k=i; k<i+Smooth; k++) MA[i]+=result[k];

       MA[i]/=Smooth;

    }

   else

   for (int i=limit; i>=0 && !IsStopped(); i--) 

    {

      hst  = Close_Price_Based?Close[iHighest(NULL, 0, MODE_CLOSE, iPeriod, i)]:High[iHighest(NULL, 0, MODE_HIGH, iPeriod, i)];

      lst  = Close_Price_Based?Close[iLowest (NULL, 0, MODE_CLOSE, iPeriod, i)]:Low [iLowest (NULL, 0, MODE_LOW , iPeriod, i)];

      curr = iMA(NULL,0,1,0,MODE_SMA,Signal,i);

      result[i]=(curr-(hst+lst)/2)/Point;//((curr-hst)+(curr-lst))/Point;

      

      if(Smooth<2) continue;

      MA[i]=0;//iMAOnArray(result,0,Smooth,0,Mode,i);

      for (int k=i; k<i+Smooth; k++) MA[i]+=result[k];

       MA[i]/=Smooth;

    }



//--- return value of prev_calculated for next call

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