Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 5/13/2005(UTC) Posts: 715 Location: Midwest, USA
Was thanked: 1 time(s) in 1 post(s)
|
OK. What's unclear is the sell signal -- would any one of the conditions do it, or all three, or what? The following assumes a reverse crossover would do it -- otherwise, are you saying a 3% drop and 4.2% drop -- from where, the high/low/close? Anyway, the following code which will "filter" redundant signals, and you will need to understand the FMLVAR() function. There are three separate indicators; each formula name has an underscore "_". Code:
_Pyramid1
Entry:=Cross(Mov(C,2,E),Mov(C,36,S));
Exit:=Cross(Mov(C,36,E),Mov(C,2,S));
{ REMOVE EXTRA SIGNALS, +1=Buy -1=Sell }
Signal:=Cum(IsDefined(Entry+Exit))=1; { Enough data ? }
Signal:=ValueWhen(1,Entry-Exit<>0 OR Signal,Entry); { Current }
Entry:=Signal*(Alert(Signal=0,2) OR Entry*Cum(Entry)=1); { Current or 1st }
Exit:=(Signal=0)*(Alert(Signal,2) OR Exit*Cum(Exit)=1); { Current or 1st }
Entry:=(Exit=0)*entry; { favor EXIT }
Signal:=Entry-Exit; { Signal }
Season:=ValueWhen(1,Signal<>0,Entry)*2-1; { Signal active }
{ PLOT }
Signal;
_Pyramid2
Condition:=FmlVar("_Pyramid1","Entry");
PriceAtCrossover:=ValueWhen(1,Condition,H);
Value:=(H-PriceAtCrossover)/PriceAtCrossover;
Entry:=Value>0.03 and FmlVar("_Pyramid1","Season")=1;
Exit:=FmlVar("_Pyramid1","Exit");
{ REMOVE EXTRA SIGNALS, +1=Buy -1=Sell }
Signal:=Cum(IsDefined(Entry+Exit))=1; { Enough data ? }
Signal:=ValueWhen(1,Entry-Exit<>0 OR Signal,Entry); { Current }
Entry:=Signal*(Alert(Signal=0,2) OR Entry*Cum(Entry)=1); { Current or 1st }
Exit:=(Signal=0)*(Alert(Signal,2) OR Exit*Cum(Exit)=1); { Current or 1st }
Entry:=(Exit=0)*entry; { favor EXIT }
Signal:=Entry-Exit; { Signal }
Season:=ValueWhen(1,Signal<>0,Entry)*2-1; { Signal active }
{ PLOT }
Signal;
_Pyramid3
Condition:=FmlVar("_Pyramid1","Entry");
PriceAtCrossover:=ValueWhen(1,Condition,C);
Value:=(C-PriceAtCrossover)/PriceAtCrossover;
Entry:=Value>0.042 and FmlVar("_Pyramid2","Season")=1;;
Exit:=FmlVar("_Pyramid1","Exit");
{ REMOVE EXTRA SIGNALS, +1=Buy -1=Sell }
Signal:=Cum(IsDefined(Entry+Exit))=1; { Enough data ? }
Signal:=ValueWhen(1,Entry-Exit<>0 OR Signal,Entry); { Current }
Entry:=Signal*(Alert(Signal=0,2) OR Entry*Cum(Entry)=1); { Current or 1st }
Exit:=(Signal=0)*(Alert(Signal,2) OR Exit*Cum(Exit)=1); { Current or 1st }
Entry:=(Exit=0)*entry; { favor EXIT }
Signal:=Entry-Exit; { Signal }
Season:=ValueWhen(1,Signal<>0,Entry)*2-1; { Signal active }
{ PLOT }
Signal;
|