AFL Code not giving desired BUY and Sell Signal

/*****Vwap*******/
_SECTION_BEGIN("Yesterdays VWAP Strategy");

 
HaCloseF = (O + H + L + C)/4;                  /* for HA Candle */
HaOpenF = AMA( Ref( HaCloseF, -1 ), 0.5 ); 
HaHighF = Max( H, Max( HaCloseF, HaOpenF ) ); 
HaLowF = Min( L, Min( HaCloseF, HaOpenF ) ); 
xDiff = (HaHighF - HalowF) * 10000;
barcolor = IIf(HaCloseF >= HaOpenF,colorGreen,colorRed);
PlotOHLC( HaOpenF, HaHighF, HaLowF, HaCloseF, "", barcolor, styleCandle );

marketstarttime = 091500;

Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == marketstarttime , BarIndex());
TodayVolume = iif(Sum(V,Bars_so_far_today) <= 0,1,Sum(V,Bars_so_far_today));
average = (H+L+C)/3;
IIf (BarIndex() >= StartBar, VWAP = Sum (average * V, Bars_so_far_today  ) / TodayVolume,0);


newday = Ref(Day(),-1) != Day();

yVWAP = ValueWhen(newday, Ref(VWAP,-1) ,1);

VW=yVWAP;

Plot(VWAP,"yVWAP",colorBlack,styleLine | styleThick);                             /* MY VWAP Line*/


DDFH=Param("DDFH",21,0,200,1);                                                     /* My Moving Average Line*/
DHFV=MA(C,DDFH);
Plot(DHFV,"",colorLightOrange,styleThick|styleDashed);

/*** CONDITIONS*/ 

NB=HahighF>DHFV;                   /* 1 HA Candle High should be more than Moving average Line*/
NS=HaLowF<DHFV;

NB1= HacloseF>VW;                    /* 2 HA Candle CLOSE should be more than VWAP Line*/
NS1=HacloseF<VW;

NB2= HaOpenF<HaCloseF;               /*3  HA Candle Should be green*/
NS2= HaCloseF<HaOpenF;

NS4= HaHighF<DHFV; 

Buy=  NB1 AND NB AND NB2 ;             /* All 3 Condition to be fulfill*/
Sell= NS4 OR NS2;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Short=0;
Cover=0;
  
 
PlotShapes(IIf(Buy, shapeUpArrow , shapeNone), colorBlue);

PlotShapes(IIf(Sell, shapeStar , shapeNone), colorLime); 
 
 
_SECTION_END();

Hi,
I was trying to make code which is not give desired Buy signals. Its VWAP and Heikin Ashi cancel combination on 15 Min Charts.

3 Condition for BUY
a) HaClose should be more than VWAP
b) HaHigh should be more than Moving Average Line.
c ) Heikin Ashi candle should be green

Either of 2 Condition for Sell
I) HaHigh should be less than Moving Average
ii) Heikin Ashi candle Red color.

I would be very thankful if someone can help in rectifying the mistake.

Those copied code lines are baloney lines. And what is volume lower zero???

average = (H+L+C)/3;
bars = BarsSince(Day() != Ref(Day(),-1))+1;
TodayVolume = Sum(V,bars);
VWAP = SafeDivide(Sum(average*V,bars), TodayVolume);

Or you can use SumSince() instead of Sum().

1 Like

Thanks every one. I got It

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.