Momentum_Histo

Author: Yuriy Tokman (YTG)
Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
Momentum_Histo
//+------------------------------------------------------------------+
//|                                               Momentum_Histo.mq4 |
//|                                               Yuriy Tokman (YTG) |
//|                                               https://ytg.com.ua |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman (YTG)"
#property link      "https://ytg.com.ua"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrGreen
#property indicator_color2 clrRed
#property indicator_width1 3
#property indicator_width2 3
#property indicator_level1 0
#property indicator_levelcolor clrBlue
#property indicator_levelwidth 2
//--- input parameter
input int MPeriod = 14;//Momentum Period
input double MLevel = 100.0;//Level indicator
//--- buffers
double BU0[],BU1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   string short_name;
   short_name="Momentum_Histo("+IntegerToString(MPeriod)+") ";
   IndicatorShortName(short_name);   
   
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,BU0);
   SetIndexLabel(0,"UP");
      
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,BU1);   
   SetIndexLabel(1,"DN");

   if(MPeriod<=0)
     {
      Print("Wrong input parameter Momentum Period=",MPeriod);
      return(INIT_FAILED);
     }
//---
   SetIndexDrawBegin(0,MPeriod);
   SetIndexDrawBegin(1,MPeriod);   
//---
   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 i,limit;
   double par =0;
   if(rates_total<=MPeriod || MPeriod<=0)return(0);
   ArraySetAsSeries(BU0,false);
   ArraySetAsSeries(BU1,false);  
   ArraySetAsSeries(close,false);

   if(prev_calculated<=0){
    for(i=0; i<MPeriod; i++){
     BU0[i]=0.0;BU1[i]=0.0;}
     limit=MPeriod;
    }
  else
   limit=prev_calculated-1;
   for(i=limit; i<rates_total; i++){
    par =close[i]*100/close[i-MPeriod] - MLevel;
    if(par>0)BU0[i]=par;
    else BU1[i]=par;
   }   
//--- 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 ---