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. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"2009, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property indicator_separate_window#property indicator_buffers1#property indicator_plots1//---- plot MA#property indicator_label1"MA"#property indicator_type1DRAW_LINE#property indicator_color1clrRed#property indicator_style1STYLE_SOLID#property indicator_width11//--- input parametersinputbool AsSeries=true;
inputint period=1;
inputENUM_MA_METHOD smootMode=MODE_SMA;
inputENUM_APPLIED_PRICE price=PRICE_MEDIAN;
inputint shift=0;
//--- indicator buffersdouble MABuffer[];
int ma_handle;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- indicator buffers mappingif(AsSeries) ArraySetAsSeries(MABuffer,true);
Print("Indicator buffer is timeseries = ",ArrayGetAsSeries(MABuffer));
SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
Print("Indicator buffer after SetIndexBuffer() is timeseries = ",
ArrayGetAsSeries(MABuffer));
//--- change the order of accessing elements of the indicator bufferArraySetAsSeries(MABuffer,AsSeries);
IndicatorSetString(INDICATOR_SHORTNAME,"MA("+period+")"+AsSeries);
//---
ma_handle=iMA(Symbol(),0,period,shift,smootMode,price);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
//--- Copy the values of the moving average in the buffer MABufferint 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 callreturn(rates_total);
}
//+------------------------------------------------------------------+
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
Your time is much appreciated!