Rank: Advanced Member
Groups: Registered, Registered Users Joined: 1/19/2005(UTC) Posts: 1,065 Location: Koh Pha-Ngan, Earth
Was thanked: 2 time(s) in 2 post(s)
|
James, try adapting this MS indicator code to your needs:
[code:1:689363cda4]
============================
Indicator Peak/Trough values
============================
---8<---------------------------
{ http://www.metastocktools.com }
{ User inputs }
pds:=Input("Indicator periods",1,2600,21);
val:=Input("Indicator peak/trough [1~100] value",1,100,1);
plot:=Input("[1]Peak/Trough signals, [2]Values, [3]SMA, [4]2+3",1,4,4);
{ Indicator example - Simple Moving Average }
x:=Mov(C,pds,S);
{ Indicator simple peak/trough }
pk:=Ref(x,-1)>x AND Ref(x,-1)>Ref(x,-2);
tr:=Ref(x,-1)<x AND Ref(x,-1)<Ref(x,-2);
{ Indicator peak/trough values }
pkVal:=ValueWhen(val,pk,Ref(x,-1));
trVal:=ValueWhen(val,tr,Ref(x,-1));
{ Select plot }
pkPlot:=If(plot=1,pk,If(plot=2,pkVal,x));
trPlot:=If(plot=1,-tr,If(plot=2,trVal,x));
{ Plot on price chart }
If(plot=4,x,trPlot); { Green }
If(plot=4,trVal,trPlot); { Red }
If(plot=4,pkVal,pkPlot) { Blue }
---8<---------------------------
[/code:1:689363cda4]
You could then reference the above values for your exit signal:
[code:1:689363cda4]
{ User input }
pr:=Input("Sell if x% down from last peak",
0,100,2)/100;
{ Reference indicator & peak values }
indikator:=FmlVar("Indicator Peak/Trough values","X");
pkVal:=FmlVar("Indicator Peak/Trough values","PKVAL");
{ Sell signal }
sell:=indikator<pkVal*(1-pr);
{ Plot in own window }
sell
[/code:1:689363cda4]
jose '-)
|