Download MetaTrader 5
To add comments, please log in or register
Register as a seller and start offering your signals!
Hongming Huo
25
Hongming Huo 2014.03.01 23:41 

I made up a Indicator with 12,26 MA lines

I want filled up with color in two MA lines

What should I do

Here is the code, adapted from bands...

poor eng. sorry

//+------------------------------------------------------------------+
//| |
//| Copyright 2005-2014, MetaQuotes Software Corp. |
//| https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "2005-2014, MetaQuotes Software Corp."
#property link "https://www.mql4.com"
#property description "Bollinger Bands"
#property strict

#include <MovingAverages.mqh>

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Magenta
#property indicator_color2 MediumSpringGreen
//--- indicator parameters

input int FasterMA = 12;
input int SlowerMA = 26;

//--- buffers
double Fast_MA[];
double Slow_MA[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- 1 additional buffer used for counting.
IndicatorBuffers(2);
IndicatorDigits(Digits);
//--- middle line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Fast_MA);
SetIndexShift(0,0);
SetIndexLabel(0,"Fast_MA");
//--- upper band
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Slow_MA);
SetIndexShift(1,0);
SetIndexLabel(1,"Slow_MA");
//--- work buffer

//--- check for input parameter
if(SlowerMA<=0)
{
Print("Wrong input parameter Bands Period=",FasterMA);
return(INIT_FAILED);
}
//---
SetIndexDrawBegin(0,SlowerMA);

//--- initialization done
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Bollinger Bands |
//+------------------------------------------------------------------+
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=rates_total-prev_calculated;
//--- main loop
for(int i=0; i<limit; i++)
{
//--- ma_shift set to 0 because SetIndexShift called abowe
Fast_MA[i]=iMA(NULL,0,FasterMA,0,MODE_EMA,PRICE_CLOSE,i);
Slow_MA[i]=iMA(NULL,0,SlowerMA,0,MODE_EMA,PRICE_CLOSE,i);
}

//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
Alain Verleyen
Moderator
28627
Alain Verleyen 2014.03.02 01:09  

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

/
To add comments, please log in or register