Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
If you want to draw level lines at the swing points, try using this :
Us:=BarsSince((H>Ref(H,-1)) AND (Ref(H,-1)>Ref(H,-2)));
Ds:=BarsSince((L<Ref(L,-1)) AND (Ref(L,-1)<Ref(L,-2)));
Sd1:=If(Us=0,If(Ref(L,-1)<>LowestSince(1,Ds=0,L),1,0),
If(Ds=0,If(Ref(H,-1)<>HighestSince(1,Us=0,H),-1,0),0));
Sd2:=If(Sd1=1,If(Ref(BarsSince(Sd1=1),-1)>
Ref(BarsSince(Sd1=-1),-1),1,0),If(Sd1=-1,
If(Ref(BarsSince(Sd1=1),-1)<Ref(BarsSince(Sd1=-1),-1), -1,0),0));
TD1:=ValueWhen(1,Sd2<>0,Sd2);
Up:=Cross(TD1,.5);
Dn:=Cross(-.5,TD1);
If(BarsSince(up)>BarsSince(Dn),ValueWhen(1,DN,Ref(H,-1)),ValueWhen(1,UP,Ref(L,-1)))
If you want to mark the bar when the swing occur ...
You would have to create a new expert advisor and use the highlights or symbols. In the symbols (or highlight tab) Click on New and call it Up swing ( or whatever ). Select the symbol, the color and its position. In the formula Type :
Us:=BarsSince((H>Ref(H,-1)) AND (Ref(H,-1)>Ref(H,-2)));
Ds:=BarsSince((L<Ref(L,-1)) AND (Ref(L,-1)<Ref(L,-2)));
Sd1:=If(Us=0,If(Ref(L,-1)<>LowestSince(1,Ds=0,L),1,0),
If(Ds=0,If(Ref(H,-1)<>HighestSince(1,Us=0,H),-1,0),0));
Sd2:=If(Sd1=1,If(Ref(BarsSince(Sd1=1),-1)>Ref(BarsSince(Sd1=-1),-1),1,0),
If(Sd1=-1,If(Ref(BarsSince(Sd1=1),-1)<Ref(BarsSince(Sd1=-1),-1),
-1,0),0));
TD1:=ValueWhen(1,Sd2<>0,Sd2);
Cross(TD1,.5)
Then Click on new again, this time call it Down swing,
Select the symbol, the color and its position.
Us:=BarsSince((H>Ref(H,-1)) AND (Ref(H,-1)>Ref(H,-2)));
Ds:=BarsSince((L<Ref(L,-1)) AND (Ref(L,-1)<Ref(L,-2)));
Sd1:=If(Us=0,If(Ref(L,-1)<>LowestSince(1,Ds=0,L),1,0),If(Ds=0,If(Ref(H,-1)<>
HighestSince(1,Us=0,H),-1,0),0));
Sd2:=If(Sd1=1,If(Ref(BarsSince(Sd1=1),-1)>Ref(BarsSince(Sd1=-1),-1),1,0),If(Sd1=-1,
If(Ref(BarsSince(Sd1=1),-1)<Ref(BarsSince(Sd1=-1),-1),
-1,0),0));
TD1:=ValueWhen(1,Sd2<>0,Sd2);
Cross(-.5,TD1)
Then attach the expert on your chart.
The way I did mine, it plotted a red arrow above the price bar on a down swing day and a green arrow below the price bar on a upswing day. But you could use anything symbol you want or highlights instead.
|