[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Indicator System problem



PureBytes Links

Trading Reference Links

Hi,
Below I've tried to code the framework for a system as an indicator.  It's
being debugged at present and doesn't include proper exit signals or use of
the P variable to introduce Interest rate change.  All things for the
future.  Enough excuses...

I've run into the problem of variables being initialised late and despite
the use of early false entry/exit signals, the Equity variable (for example)
doesn't get initialised until both a real Long and Short signal get
generated.

Grateful for any help.

Thanks,
Sean


{Larry Williams - Long-Term secrets to Short-Term trading p.102}
{Smash Day BUY has up close but in lower 25% of days range,
Close less than Open.  Enter tomorrow at today's High.
Sell Short is opposite.
Should combine with strong trend and interest rates}
{System uses following day entry}
Periods:=5; {Used to delay false early triggers if necessary}
LongEntryPoint:=Ref(H,-1); {calc. on day of entry, limit order entry}
ShortEntryPoint:=Ref(L,-1); {calc. on day of entry, limit order entry}
LongExitPoint:=O;
ShortExitPoint:=O;
LongEntry:=If(Cum(1)=Periods+1,1,
    Ref(C,-1) < C AND
    C < L+((H-L)/4) AND
    C < O AND
    H < Ref(H,+1)); {last part only for system test - following day entry
condition}
LongExit:=If(Cum(1)=Periods+4,1,
    barsSince(LongEntry)=3);{auto exit 3 days later}
ShortEntry:=If(cum(1)=Periods+6,1,
    Ref(C,-1) > C AND
    C > H-((H-L)/4) AND
    C > O AND
    L > Ref(L,+1)); {last part only for system test - following day entry
condition}
ShortExit:=If(Cum(1)=Periods+9,1,
    barsSince(ShortEntry)=3);{auto exit 3 days later}
Position:=If(Ref(BarsSince(LongEntry)<=BarsSince(LongExit),-1),1,
    If(Ref(BarsSince(ShortEntry)<=BarsSince(ShortExit),-1),-1,0));
TotalLong:=Cum(Cross(Position,0.5));
TotalShort:=Cum(Cross(-0.5,Position));
Equity:=Cum(
    if(Cross(0.5,Position),

ValueWhen(1,Cross(0.5,Position),LongExitPoint)-ValueWhen(1,Cross(Position,0.
5),LongEntryPoint),
        If(Cross(Position,-0.5),

ValueWhen(1,Cross(-0.5,Position),ShortEntryPoint)-ValueWhen(1,Cross(Position
,-0.5),ShortExitPoint),
        0)
    ));

TotalLongWin:=Cum(if(Cross(0.5,Position),ValueWhen(1,Cross(Position,0.5),Lon
gEntryPoint)<ValueWhen(1,Cross(0.5,Position),LongExitPoint),0));
TotalLongLoss:=TotalLong-TotalLongWin;
TotalShortWin:=Cum(If(Cross(Position,-0.5),ValueWhen(1,Cross(-0.5,Position),
ShortEntryPoint)>ValueWhen(1,Cross(Position,-0.5),ShortExitPoint),0));
TotalShortLoss:=TotalShort-TotalShortWin;

Equity;