mothlymedian,weeklymedian

 
Hi can somebody tell me how to find the mothly as well as weekly previous median in mql4? Thanks
 

median = (High+Low)/2;

 
Hi sir thanks for your reply but is i use this to find the weekly as well as monthly previous median? because i used it but it is not working ?
    daily_Maxh = High[Highest(NULL,0,MODE_HIGH,PERIOD_D1,i)];
    daily_Minh = Low[Lowest(NULL,0,MODE_LOW,PERIOD_D1,i)];
    weekly_Maxh= High[Highest(NULL,0,MODE_HIGH,PERIOD_W1,i)];
    weekly_Minh= Low[Lowest(NULL,0,MODE_LOW,PERIOD_W1,i)];
    monthly_Maxh=High[Highest(NULL,0,MODE_HIGH,PERIOD_MN1,i)];
    monthly_Minh = Low[Lowest(NULL,0,MODE_LOW,PERIOD_MN1,i)];
    ExtBuffer0[i]=MathAbs((daily_Maxh+daily_Minh)/2);
    ExtBuffer1[i]=MathAbs((weekly_Maxh+weekly_Minh)/2);
    ExtBuffer2[i]=MathAbs((monthly_Maxh+monthly_Minh)/2);
Is this code is correct to find the weekly,monthly and daily previous median?
 
// I don't think you really want this
daily_Maxh = High[Highest(NULL,0,MODE_HIGH,PERIOD_D1,i)];

//This should do what you want
daily_Maxh = iHigh(NULL,PERIOD_D1,i);

//repeat for the remainder

ExtBuffer0[i]=MathAbs((daily_Maxh+daily_Minh)/2);  //why the MathAbs?
 
#property  indicator_separate_window
#property  indicator_buffers 7
#property  indicator_color1  Blue
#property  indicator_color2  Red
#property  indicator_color3  Green
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
double ExtBuffer3[];
double daily_Maxh=0;
double daily_Minh=0;
double weekly_Maxh=0;
double weekly_Minh=0;
double monthly_Maxh=0;
double monthly_Minh=0;
void init()
  {
     SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Blue);
     SetIndexBuffer(0,ExtBuffer0);
     SetIndexStyle(0,DRAW_LINE,STYLE_DASH,2,Red);
     SetIndexBuffer(0,ExtBuffer1);
     SetIndexStyle(0,DRAW_LINE,STYLE_DOT,2,Green);
     SetIndexBuffer(0,ExtBuffer2);
  }
void start(){
int i;
    int    counted_bars=IndicatorCounted();
    if(counted_bars>0) counted_bars--;
    i=Bars-counted_bars;
    while(i>=0){  
    daily_Maxh = iHigh(NULL,PERIOD_D1,i);
    daily_Minh = iLow(NULL,PERIOD_D1,i);
    weekly_Maxh= iHigh(NULL,PERIOD_W1,i);
    weekly_Minh= iLow(NULL,PERIOD_W1,i);
    monthly_Maxh=iHigh(NULL,PERIOD_MN1,i);
    monthly_Minh = iLow(NULL,PERIOD_MN1,i);
    ExtBuffer0[i]=(daily_Maxh+daily_Minh)/2;
    ExtBuffer1[i]=(weekly_Maxh+weekly_Minh)/2;
    ExtBuffer2[i]=(monthly_Maxh+monthly_Minh)/2;
    i--;
   } 
return(0);
}   
sir i have written this code but still it is not working it doesn't printing the lines of daily,weekly and monthly can you please tell me what mistake i have made in this code ?
 
ankitkalindi:
sir i have written this code but still it is not working it doesn't printing the lines of daily,weekly and monthly can you please tell me what mistake i have made in this code ?


You will have the problem that when i ==1, you will get

Yesterday's daily median

Last weeks weekly median

Last month's monthly median

When i == 2, you will get

Daily median from 2 days ago

Weekly median from 2 weeks ago

Monthly median from 2 months ago.

I think that you will have to use Time[i] for the current timeframe and find iBarShift for that time on other timeframes.

 
ankitkalindi:
sir i have written this code but still it is not working it doesn't printing the lines of daily,weekly and monthly can you please tell me what mistake i have made in this code ?


we can tell

PREVIOUS Day'sMedian

we can tell you to define your indicatorbuffers correctly

     SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Blue);
     SetIndexBuffer(0,ExtBuffer0);
     SetIndexStyle(0,DRAW_LINE,STYLE_DASH,2,Red);
     SetIndexBuffer(0,ExtBuffer1);
     SetIndexStyle(0,DRAW_LINE,STYLE_DOT,2,Green);
     SetIndexBuffer(0,ExtBuffer2);

we can tell you barnumber chart is not barnumber dailychart and not/also barnumber weeklychart .........

but will you understand ....... if we do

 
yes sir can you explain me ?because those are so confusing for me and please tell me through example or code to find the previous median of daily,weekly,monthly?
 
ankitkalindi:
yes sir can you explain me ?because those are so confusing for me and please tell me through example or code to find the previous median of daily,weekly,monthly?
double iMA(string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)
Calculates the Moving average indicator and returns its value.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
period - Averaging period for calculation.
ma_shift - MA shift. Indicators line offset relate to the chart by timeframe.
ma_method - MA method. It can be any of the Moving Average method enumeration value.
applied_price - Applied price. It can be any of Applied price enumeration values.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
Sample:
AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);

Show your attempt

double YesterdayMedian = iMA(..what do you have to write here for getting YesterdayMedian..);
 
 #property  indicator_separate_window
 #property  indicator_buffers 7

 double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
void init()
  {
     SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Silver);
     SetIndexBuffer(0,ExtBuffer0);
     SetIndexStyle(1,DRAW_LINE,STYLE_DASH,2,Green);
     SetIndexBuffer(0,ExtBuffer1);
     SetIndexStyle(0,DRAW_LINE,STYLE_DOT,2,Blue);
     SetIndexBuffer(2,ExtBuffer2);
  }
   
void start(){  
int i=1;
    int    counted_bars=IndicatorCounted();
    if(counted_bars>0) counted_bars--;
    i=Bars-counted_bars;
    while(i>=0){    

    daily_median=iMA(NULL,PERIOD_D1,13,8,MODE_SMMA,PRICE_MEDIAN,i);
    weekly_median=iMA(NULL,PERIOD_W1,13,8,MODE_SMMA,PRICE_MEDIAN,i);
    monthly_median=iMA(NULL,PERIOD_MN1,13,8,MODE_SMMA,PRICE_MEDIAN,i);
    ExtBuffer0[i]=daily_median;

    ExtBuffer1[i]=weekly_median;

    ExtBuffer2[i]=monthly_median;
}
}
sir is this code is correct? because it is not showing me the line of all three median in the separate chart
 
ankitkalindi:
sir is this code is correct? because it is not showing me the line of all three median in the separate chart


no

daily_median=iMA(NULL,PERIOD_D1,13,8,MODE_SMMA,PRICE_MEDIAN,i);

what is i ??? in your code

is daily_median=iMA(NULL,PERIOD_D1,13,8,MODE_SMMA,PRICE_MEDIAN,0);

and also daily_median=iMA(NULL,PERIOD_D1,13,8,MODE_SMMA,PRICE_MEDIAN,1);

and also daily_median=iMA(NULL,PERIOD_D1,13,8,MODE_SMMA,PRICE_MEDIAN,2);

....

do you get median for only a day by taking period 13 ???

....

what is that 8 doing in the code ??

...

why did you choose MODE_SMMA ???

...

If you don't know how to use this indicator ....


your attempt ???

double YesterdayMedian = iMA(..what do you have to write here for getting YesterdayMedian..);
Reason: