logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Flexi  
#1 Posted : Sunday, May 8, 2011 9:50:07 AM(UTC)
Flexi

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2006(UTC)
Posts: 135

Below is a code for average volume using zigzag. Wanted the indicator to calculate the average volume only when the zigzag is valid. A 2% zigzag would plot the average volume only when price has retraced 2% from the pivot point.How to modify the code?

=========================
Volume - Up/DownSwing avg
=========================
---8<-----------------------------

{ Up/DownSwing average Volume v3.0

 ©Copyright 2006 Jose Silva.
 For personal use only.
 http://www.metastocktools.com }

{ User inputs }
choose:=Input("Avg Volume: [1]UpSwing, [2]DownSwing, [3]Both",1,3,3);
ch:=Input("ZigZag minimum change %",.01,100,2);
plot:=Input("Up/Down [1]Avg Vol [2]Swings, [3]ZigZag, [4]Pk/Tr",1,4,1);

{ ZigZag }
zz:=Zig(C,ch,%);

{ Up/Down bar count }
pkBars:=PeakBars(1,C,ch);
trBars:=TroughBars(1,C,ch);

{ Peaks/Troughs }
pk:=pkBars=0;
tr:=trBars=0;

{ ---------- *** UpSwing Volume *** ---------- }

{ Up swings }
UpSwing:=zz>Ref(zz,-1);

{ Up swing volume }
UpSwingVol:=V*UpSwing;

{ Accumulate & reset UpVolume }
acc:=Cum(UpSwingVol);
accUpVol:=acc-ValueWhen(1,pkBars=0,acc);

{ Average UpSwing Volume }
avgUpVol:=accUpVol/Max(trBars,.00001);

{ Restrict avg Volume to peak bar }
avgUpVolPk:=Ref(avgUpVol,-1)*pk;

{ --------- *** DownSwing Volume *** --------- }

{ Down swings }
DwSwing:=zz<Ref(zz,-1);

{ Down swing volume }
DwSwingVol:=V*DwSwing;

{ Accumulate & reset DownVolume }
acc:=Cum(DwSwingVol);
accDwVol:=acc-ValueWhen(1,trBars=0,acc);

{ Average DownSwing Volume }
avgDwVol:=accDwVol/Max(pkBars,.00001);

{ Restrict avg Volume to trough bar }
avgDwVolTr:=Ref(avgDwVol,-1)*tr;


{ Choose Volume display }
swingAvgVol:=
 If(choose=1,avgUpVol,
 If(choose=2,avgDwVol,
 avgUpVolPk-avgDwVolTr));

{ Plot in own window }
If(plot=1,swingAvgVol,
 If(plot=2,UpSwing-DwSwing,
 If(plot=3,zz,pk-tr)))

---8<-----------------------------

Zigzag validity code

perc:=Input("Percent",0.2,100,10);

Z:=Zig(CLOSE,perc,%);
last:=ValueWhen(1,( Z > Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2) )
OR
( Z < Ref(Z,-1) AND Ref(Z,-1) > Ref(Z,-2) ),
Ref(Z,-1));

pc:=(CLOSE-last) * 100 / last;
pc:= Abs(pc);

SD:=(z>Ref(z,-1) AND Ref(z,-1)>Ref(z,-2)) OR (z<Ref(z,-1) AND Ref(z,-
1)<Ref(z,-2));

res:=If(pc>=perc ,1,0);
If(Alert(res,2) AND SD,1,res)



wabbit  
#2 Posted : Monday, May 9, 2011 1:29:01 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Multiply the UpSwingVol and DnSwingVol volumes by the Boolean value result from the validity function.


wabbit [:D]

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.