The below code's purpose is to:
- Calculate and plot Heikin Ashi Price
- And on the (heikin ashi) chart, look for the following conditions in the hourly chart:
The code works fine when applied like an indicator (i.e. on a chart) but as a scanner, it only returns the morning signals.
Here's the chart (indicator works normally):
The white circle is for SELL, yellow is for BUY.
And here's the scanner:
Clearly, there are much more trades in chart than in the analysis window. Why is this happening?
_SECTION_BEGIN("Price Heikin Ashi");
SetChartOptions(0,chartShowArrows | chartShowDates);
TimeFrameSet(inHourly);
HaClose = (O + H + L + C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );
// 3 GREEN CANDLES AFTER 1 RED
Gtrig0 = IIf(Ref(HaClose,-2)<=Ref(HaOpen,-2),True,False); // RED CANDLE BEFORE GREEN
Gtrig1 = IIf(HaClose>=HaOpen,True,False); // 2ND GREEN CANDLE
Gtrig2 = IIf(Ref(HaClose,-1)>=Ref(HaOpen,-1),True,False); // 1ST GREEN CANDLE
//Gtrig3 = IIf(Ref(HaClose,-3)>=Ref(HaOpen,-3),True,False);
Gtrig4 = IIf(HaClose>Ref(HaClose,-1) AND Ref(HaClose,-1)>Ref(HaClose,-2), True, False);
//StockName = FullName();
//BankN = StockName == "BANKNIFTY";
Buy = Gtrig0 AND Gtrig1 AND Gtrig2 AND Gtrig4; // AND Gtrig4;
PlotShapes(IIf(Buy, shapeCircle, shapeNone), colorYellow, 0);
// 3 RED CANDLES AFTER 1 GREEN
Rtrig0 = IIf(Ref(HaClose,-2)>=Ref(HaOpen,-2),True,False); //GREEN CANDLE BEFORE RED
Rtrig1 = IIf(HaOpen>=HaClose,True,False); // 2ND RED CANDLE
Rtrig2 = IIf(Ref(HaOpen,-1)>=Ref(HaClose,-1),True,False); // 1ST RED CANDLE
//Rtrig3 = IIf(Ref(HaOpen,-3)<=Ref(HaClose,-3),True,False);
Rtrig4 = IIf(HaClose<Ref(HaClose,-1) AND Ref(HaClose,-1)<Ref(HaClose,-2), True, False);
Sell = Rtrig0 AND Rtrig1 AND Rtrig2 AND Rtrig4;
PlotShapes(IIf(Sell, shapeCircle, shapeNone), colorWhite, 0);
Filter = Buy OR Sell;
TimeFrameRestore();
_SECTION_END();
Help would be appreciated!