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

Re: Indicator System problem



PureBytes Links

Trading Reference Links

Sean

> I've been using 4 different ways to debug the code:

I guess I've been using all the same methods of troubleshooting except Experts which I have little
use for.

> I've also just stripped out the code to basics so I can see what's
> happening - a monthly test entry to boot...
> Using this I've figured out what was happening.  I still had the Barsince()
> in the Exit condition.  This was causing the Pos variable to initialise
> late.
> Now I've replaced it with your Alert() it's highlighted to me why you needed
> to create another set of entry/exit conditions off Pos.  The Alert()
> continues the Exit conditions.

I've found the Alert() function to be very useful, and with a little thought it can be used with
signals that are not pure binary in nature too.

> Thanks for your help.  I'm going to work the Equity etc in now.

No problem. Thanks to the prompting of your earlier questions I have put together the following
indicators for a long and/or short trade binary, and a modest long and/or short equity curve. The
equity curve is based on a constant(or fixed) position size rather than the MS compounding equity. I
believe that fixed equity is more appropriate for system testing than compounding equity.

These indicators are not the ultimate for multiple stock testing, but I think they could provide a
useful starting point for an EOD MS user to develop their own multiple stock tests.

I suggest the Trade Binary be displayed in an inner window as two differently coloured histograms. I
normally lay the equity curve in the main chart window but there is no right and wrong.

Oh, the normal entry/exits (O, H, L, C) should be binary indicators with code identical to that used
in the System Tester (but without optimisation). The stop entry/exits should be coded to spike to
the required entry/exit values and be zero at all other times. With a little thought this is not too
difficult. Any external value that is not required can/should be set to =0.

Roy

  {Trade Binary}
OptionE:=Input("Enter: 1=O 2=C 3=H 4=L 5=Stop",1,5,2);
OptionX:=Input( "Exit: 1=O 2=C 3=H 4=L 5=Stop",1,5,2);
EntryDelay:=Input("Trade entry delay",0,3,1);
CloseDelay:=Input(" Trade exit delay ",0,3,1);
Costs:=Input("Brokerage ",0,100,50);
Capital:=Input("Capital",1000,100000,10000);
EnterLong:=Fml("Your Enter Long");
CloseLong:=Fml("Your Close Long");
EnterShort:=Fml("Your Enter Short");
CloseShort:=Fml("Your Close Short");
LongEntryStop:=Fml("Your Enter Long Stop");
LongCloseStop:=Fml("Your Close Long Stop");
ShortEntryStop:=Fml("Your Enter Short Stop");
ShortCloseStop:=Fml("Your Close Short Stop");
  {*** Do not change following code ***}
LongEntryStop:=If(OptionE=5,LongEntryStop,0);
LongCloseStop:=If(OptionX=5,LongCloseStop,0);
ShortEntryStop:=If(OptionE=5,ShortEntryStop,0);
ShortCloseStop:=If(OptionX=5,ShortCloseStop,0);
LongEntryPrice:=If(OptionE=5 AND LongEntryStop
  >0,Max(O,LongEntryStop),If(OptionE=1,O,
  If(OptionE=3,H,If(OptionE=4,L,C))));
LongExitPrice:=If(OptionX=5 AND LongCloseStop
  >0,Min(O,LongCloseStop),If(OptionX=1,O,
  If(OptionX=3,H,If(OptionX=4,L,C))));
ShortEntryPrice:=If(OptionE=5 AND ShortEntryStop
  >0,Min(O,ShortEntryStop),If(OptionE=1,O,
  If(OptionE=3,H,If(OptionE=4,L,C))));
ShortExitPrice:=If(OptionX=5 AND ShortCloseStop
  >0,Max(O,ShortCloseStop),If(OptionX=1,O,
  If(OptionX=3,H,If(OptionX=4,L,C))));
EnterLong:=If(OptionE=5,If(LongEntryStop>
  0,1,0),Ref(EnterLong,-EntryDelay));
CloseLong:=If(OptionX=5,If(LongCloseStop>
  0,1,0),Ref(CloseLong,-CloseDelay));
EnterShort:=If(OptionE=5,If(ShortEntryStop>
  0,1,0),Ref(EnterShort,-EntryDelay));
CloseShort:=If(OptionX=5,If(ShortCloseStop>
  0,1,0),Ref(CloseShort,-CloseDelay));
Init:=Cum(EnterLong<>2 AND CloseLong<>2 AND
  EnterShort<>2 AND CloseShort<>2 )=1;
Trade:=Ref(If(BarsSince(EnterLong OR Init)>=
  BarsSince(CloseLong OR Init),0,2) +
 If(BarsSince(EnterShort OR Init)>=
  BarsSince(CloseShort OR Init),0,-1),-0);
If(Trade>=1,1,0); If(Abs(Trade)=1,-1,0);

  {Trade Equity}
Costs:=FmlVar("Trade Binary","Costs");
Capital:=FmlVar("Trade Binary","Capital");
EnterLong:=FmlVar("Trade Binary","EnterLong");
EnterShort:=FmlVar("Trade Binary","EnterShort");
CloseLong:=FmlVar("Trade Binary","CloseLong");
CloseShort:=FmlVar("Trade Binary","CloseShort");
Init:=FmlVar("Trade Binary","Init");
LongExitPrice:=FmlVar("Trade Binary","LongExitPrice");
ShortExitPrice:=FmlVar("Trade Binary","ShortExitPrice");
Trade:=FmlVar("Trade Binary","Trade");
LongEntry:=Alert(Trade<1,2) AND Trade >=1;
LongExit:=Alert(Trade>=1,2) AND Trade <1;
ShortEntry:=Alert(Abs(Trade)<>1,2) AND Abs(Trade)=1;
ShortExit:=Alert(Abs(Trade)=1,2) AND Abs(Trade)<>1;
LastBar:=(Trade<>0 OR Alert(Trade<>0,2)) AND LastValue(Cum(1)-0)=Cum(1);
LongEntryPrice:=ValueWhen(1,Init OR LongEntry,
  FmlVar("Trade Binary","LongEntryPrice"));
ShortEntryPrice:=ValueWhen(1,Init OR ShortEntry,
  FmlVar("Trade Binary","ShortEntryPrice"));
Gain:=If(LongExit OR (LastBar AND Trade>=1),
  (Capital-Costs)*
  (LongExitPrice/LongEntryPrice)-Capital-Costs,0)+
 If(ShortExit OR (LastBar AND Abs(Trade)=1),
  ((Capital-Costs)*
  ((ShortEntryPrice-ShortExitPrice)/ShortEntryPrice)) -2 *Costs,0);
Equity:=Cum(Gain) - Capital +
 If(Trade>=1 AND LastBar=0,(Capital-Costs)*
  (LongExitPrice/LongEntryPrice),Capital) +
 If(Abs(Trade)=1 AND LastBar=0,((Capital-Costs)*
  ((ShortEntryPrice-ShortExitPrice)/ShortEntryPrice))
  +Capital-Costs,Capital);
Equity;