Creating New indicator from MA data

To add comments, please log in or register
Crays Loh
Crays Loh  

Dear all,

I hope you guys can point me in the right direction, i've search for quite sometime and trying to understand how do i use the data i got from Median price of a Moving Average Indicator. Yet to no avail.

I'm trying to get a Median Price Moving Average Indicator (successfully) and using the current bar price minus the previous bar price to get a difference in pricing chart (indicator).

But all i can do is only getting to Median Price Moving Average Indicator, i'm not sure how i can use that data in a timeseries format to gain what i had in mind, which is using current bar price - previous bar price.

Here is my code

//|                                              TestCopyBuffer1.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                     |
#property copyright "2009, MetaQuotes Software Corp."
#property link      ""
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot MA
#property indicator_label1  "MA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input bool               AsSeries=true;
input int                period=1;
input ENUM_MA_METHOD     smootMode=MODE_SMA;
input int                shift=0;
//--- indicator buffers
double                   MABuffer[];
int                      ma_handle;
//| Custom indicator initialization function                         |
int OnInit()
//--- indicator buffers mapping
   if(AsSeries) ArraySetAsSeries(MABuffer,true);
   Print("Indicator buffer is timeseries = ",ArrayGetAsSeries(MABuffer));
   Print("Indicator buffer after SetIndexBuffer() is timeseries = ",
//--- change the order of accessing elements of the indicator buffer
//| 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[])
//--- Copy the values of the moving average in the buffer MABuffer
   int copied=CopyBuffer(ma_handle,0,0,rates_total,MABuffer);
   Print("MABuffer[0] = ",MABuffer[0]);// Depending on the value AsSeries
                                      // Will receive a very old value
                                      // Or for the current unfinished bar
//--- return value of prev_calculated for next call


Your time is much appreciated!

To add comments, please log in or register