Hello,
I wrote the following code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("3MA");
// Buy and Sell
TimeFrameSet( inHourly );
ma5_h = MA(C, 5);
ma20_h = MA(C, 20);
TimeFrameRestore();
TimeFrameSet( 4*inHourly );
ma50_4h = MA(C, 50);
ma20_4h = MA(C, 20);
TimeFrameRestore();
Buy = (ma20_4h > ma50_4h) AND Cross(ma5_h, ma20_h);
Sell = Cross(ma20_h, ma5_h);
Buy = ExRem (Buy, Sell);
Sell = ExRem (Sell, Buy);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -10);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset = -20);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0, L, Offset = -15);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorRed, 0, H, Offset = 35);
_SECTION_END();
_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("MA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
What is the buy signal? MA(C,20) should be greater than MA(C,50) (4h timeframe) and MA(C,5) crosses MA(C,20) in the hourly timeframe.
In the below pic, MA(C,20) is less than MA(C,50) (4h timeframe), so there shouldn't be any buy signal, but if I go the hourly timeframe I find some wrong buy signals:


Could you please tell me why is that?
Best regards,
Siamak
@awilson