Need help with the AFL on Zig Zag pivot

swagat86

Active Member
#1
Hi frnds,

i got this this afl from Subhim's collection.

Need help on this one.

My queries:
1) I tried changing the PercentChange = 6; but its not givin me right signals when im changin it.
2) When im pressin the backtest button, im not gettin proper report. if utry this on nifty for last 2 yrs , u get just 52% gains. where as the real chart indicates much more better performance.



//z_ZigZagValid
// ******** CHARTING
PercentChange = 6;
mystartbar = SelectedValue(BarIndex()); // FOR GRAPHING

mystartbardate = LastValue(ValueWhen(mystartbar == BarIndex(), DateNum(),1));

InitialValue = LastValue(ValueWhen(mystartbardate == DateNum(), C , 1 ) ) ;
Temp1 = IIf(BarIndex() >= mystartbar, InitialValue, Null) ;
Plot(Temp1, " ", colorBlack,styleLine);
Plot((1+(LastValue(PercentChange)/100))*(Temp1), " ", colorGreen, styleLine) ;
Plot((1-(LastValue(PercentChange)/100))*(Temp1), " ", colorRed, styleLine) ;

ZZ = Zig(C,LastValue(PercentChange)) ;
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, Null),1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, Null),1);

PlotShapes( shapeCircle*PivotLow, colorGreen,0, L, -20) ;
PlotShapes( shapeCircle*PivotHigh,colorRed,0,H, 20) ;

Buy = IIf(C>(1+(LastValue(PercentChange)/100))*(ValueWhen(PivotLow, C, 1))
AND ROC(ZZ,1) > 0,1,0);
Sell = IIf(C<(1-(LastValue(PercentChange)/100))*(ValueWhen(PivotHigh, C, 1))
AND ROC(ZZ,1) < 0,1,0);

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

PlotShapes( shapeUpArrow*Buy, colorGreen,0, L, -20);
PlotShapes( shapeDownArrow*Sell, colorRed,0,H, -20) ;

BarColors =
IIf(BarsSince(Buy) < BarsSince(Sell)
AND BarsSince(Buy)!=0, colorGreen,
IIf(BarsSince(Sell) < BarsSince(Buy)
AND BarsSince(Sell)!=0, colorRed, colorBlue));

Plot(C, " ", BarColors, styleBar ) ;
Plot(ZZ," ", colorLightGrey,styleLine|styleThick);
Plot(ZZ," ", BarColors,styleDots|styleNoLine);

Title = Name() + " " + Date() + WriteIf(PivotLow, " Up Pivot ","")+WriteIf(PivotHigh," Down Pivot ","")+ WriteIf(Buy, " Buy Point ", "") + WriteIf(Sell, " Sell Point ", "") ;

AlertIf(Buy, "", "",1,1 );
AlertIf(Sell, "", "",2,1 );
Thanks in advance
 

Attachments

#2
Hello

ZIG
- zig-zag indicator Basic price pattern detection
(AFL 1.1)


SYNTAX zig(ARRAY, change )
RETURNS ARRAY
FUNCTION Calculates the minimum % change Zig Zag indicator. Caveat: this function is based on Zig-Zag indicator and may look into the future - this means that you can get unrealistic results when back testing trading system using this indicator. This function is provided rather for pattern and trend recognition formulas.
EXAMPLE zig(close,5)


As new data comes in signals will disappear.
regards

Saji
 
#3
Hello swagat86,

Before using any AFL use the check function (Tools menu in indicator window)after pasting the AFL code in the indicator window. Use the same code you posted earlier and read the message displayed.

Or even better apply this AFL code on any scrip and mark any buy sell signal dates. Then delete your data for that scrip by one one day using edit menu, delete quotation from the last quote.

You will find all buy sell signals gone as you go on deleting latest datas. Ensure you do not save the changes made to data. For this go to preferences- miscellaneous , tick ask to save changed data. When you exit AMI a message will shown whether changes are to be saved. Press cancel.

Regards

Saji
 

swagat86

Active Member
#4
Hello

ZIG
- zig-zag indicator Basic price pattern detection
(AFL 1.1)


SYNTAX zig(ARRAY, change )
RETURNS ARRAY
FUNCTION Calculates the minimum % change Zig Zag indicator. Caveat: this function is based on Zig-Zag indicator and may look into the future - this means that you can get unrealistic results when back testing trading system using this indicator. This function is provided rather for pattern and trend recognition formulas.
EXAMPLE zig(close,5)


As new data comes in signals will disappear.
regards

Saji

thanks for ur reply Saji.

Hello swagat86,

Before using any AFL use the check function (Tools menu in indicator window)after pasting the AFL code in the indicator window. Use the same code you posted earlier and read the message displayed.

Or even better apply this AFL code on any scrip and mark any buy sell signal dates. Then delete your data for that scrip by one one day using edit menu, delete quotation from the last quote.

You will find all buy sell signals gone as you go on deleting latest datas. Ensure you do not save the changes made to data. For this go to preferences- miscellaneous , tick ask to save changed data. When you exit AMI a message will shown whether changes are to be saved. Press cancel.

Regards

Saji
yes i know Zig zag has a bad repitition for signals disapearing but wat my view point is we can gaze the trend as mentioned in the book by Larry Williams as mentioned in his book. this AFL can be used to find the trend, ie if a higher high pivot is made it indicates uptrend and vice versa.


thanks again.
 

Similar threads