problem with MA Slope custom indicator

 

Hi everyone,

this is my first time creating custom indicator. Here's my code:

//+------------------------------------------------------------------+
//|                                                      MASlope.mq4 |
//|                                                      EzraLuandre |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "EzraLuandre"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Slope
#property indicator_label1  "Slope"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      MAPeriod = 50;
//--- indicator buffers
double         SlopeBuffer[];

extern ENUM_MA_METHOD MA_Method;
extern ENUM_APPLIED_PRICE MA_Price;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,SlopeBuffer);
   
//---
   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 uncalculated_bar = rates_total-prev_calculated;
   for(int i=0; i<uncalculated_bar; i++)
     {      
      SlopeBuffer[i] = (iMA(Symbol(),PERIOD_CURRENT,MAPeriod,i,MA_Method,MA_Price,0) - iMA(Symbol(),PERIOD_CURRENT,MAPeriod,i-MAPeriod,MA_Method,MA_Price,0))/MAPeriod;
      
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Here I create a simple MA slope. I want it to be like CCI indicator where the Y axis is bound to max 100 and min -100. This code generate a MA slope with price as Y axis, how can I change it into a number instead of price?

Files:
Capture.PNG  6 kb
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Your code
  Documentation
SlopeBuffer[i] = (iMA(
Symbol(),
PERIOD_CURRENT,
MAPeriod,
i,                     
MA_Method,
MA_Price,
0
)
iMA(
Symbol(),
PERIOD_CURRENT,
MAPeriod,
i-MAPeriod,
MA_Method,
MA_Price,
0
))/
double  iMA(
   string symbol,        // symbol
   int    timeframe,     // timeframe
   int    ma_period,     // MA averaging period
   int    ma_shift,      // MA shift
   int    ma_method,     // averaging method
   int    applied_price, // applied price
   int    shift          // shift
   );
You have confused shift (which bar you are looking at) with a Displaced Moving Average.
 
William Roeder:
You have confused shift (which bar you are looking at) with a Displaced Moving Average.

Yes, I forgot that iMA only has one buffer and thinking that last shift is for buffer already changed it. But still the Y axis still in price 0.0003 etc, is there a way to change it into bound range like 100 to -100? Tried using indicator_minimum and indicator_maximum and still no result.