Sorry for not paying enough attention. This is the correct code version which
plots MA values from a higher timeframe chart (as you see it) on the current
timeframe chart.
HTF_Sel = ParamList("Higher
Timeframe","inMinutes|Weekly|Daily|Monthly|Quaterly|Yearly");
HTF_Min = Param("Haw many minutes if HTM in minutes ?",1,10,60,1);
HTF_Period = Param("Higher TimeFrame MA Period",3,2,200,1);
Plot_Traditional = ParamToggle("Plot MA using Traditional Higher
TimeFrame?","No|Yes",defaultval=1);
Plot_Close = ParamToggle("Plot Close of Higher
TimeFrame?","No|Yes",defaultval=1);
Plot_HTM_Bars = ParamToggle("Plot Higher TimeFrame
Bars?","No|Yes",defaultval=1);
Resolution_Color = ParamColor("MA color using lower resolution TimeFrame
",colorBrightGreen);
Traditional_Color = ParamColor("MA color using Traditional Higher TimeFrame
",colorYellow);
Close_Color = ParamColor("Close of Higher TimeFrame color",colorRed);
Bar_Color = ParamColor("Higher TimeFrame Bar color",colorBlue);
switch (HTF_Sel)
{
case "inMinutes":
HTF = in1Minute * 60 * HTF_Min;
break;
case "Daily":
HTF = inDaily;
break;
case "Weekly":
HTF = inWeekly;
break;
case "Monthly":
HTF = inMonthly;
break;
case "Quaterly":
HTF = inQuarterly;
break;
case "Yearly":
HTF = inYearly;
break;
}
Chart_Interval = Interval();
if (Chart_Interval >= HTF)
{
Font_Size = 12;
X_Text = floor(Status("pxwidth") * 0.01);
Y_Text = floor(Status("pxheight") / 2 - Font_Size / 2);
GfxSetOverlayMode( 0);
GfxSelectFont("Tahoma",Font_Size,800);
GfxSetTextColor(colorRed);
Error = "!!! THE HIGHER TIMEFRAME HAS TO BE GREATER THAN THE CURRENT
CHART INTERVAL !!!";
GfxTextOut(Error,X_Text,Y_Text);
}
else
{
// the essential code - calculation of MA(Close,HTF_Period) of the
Higher Timeframe using the resulution of the current chart TimeFrame
TimeFrameSet(HTF);
BI_HTF = BarIndex();
Close_HTF = Close;
MA_HTF = MA(Close_HTF,HTF_Period);
Sum_HTF = Sum(Close_HTF,HTF_Period);
Sum_NO_HTF = Sum(Close_HTF,HTF_Period - 1);
TimeFrameRestore();
BI_HTF_in_Base = TimeFrameExpand(BI_HTF,HTF);
HTF_Bar_in_Base = IIf(BI_HTF_in_Base != Ref(BI_HTF_in_Base,-1),1,0);
Jorgen_MA = IIf(HTF_Bar_in_Base,TimeFrameExpand(Sum_HTF,HTF) /
HTF_Period,(TimeFrameExpand(Sum_NO_HTF,HTF) + Close) / HTF_Period);
Plot(Jorgen_MA,"JMA(C,"+NumToStr(HTF_Period,1.0)+")",Resolution_Color);
// end of the essential code
// ################### This is for illustration purposes only
###################################
if (Plot_Traditional)
Plot(TimeFrameExpand(MA_HTF,HTF),"MA(C,"+NumToStr(HTF_Period,1.0)+")",
Traditional_Color);
if (Plot_Close)
Plot(TimeFrameExpand(Close_HTF,HTF),"C_TF",Close_Color );
if (Plot_HTM_Bars)
{
Height = Param("Higher TimeFrame Bar Height as % of Y axis",10,
2, 90, 1) ;
Min_Y = Status("axisminy");
Max_Y = Status("axismaxy");
HTF_B = IIf(HTF_Bar_in_Base, Min_Y + 0.01 * Height * (Max_Y -
Min_Y),Null);
Plot(HTF_B,"",Bar_Color,styleHistogram);
}
}
AF