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

Re: Indicator System problem



PureBytes Links

Trading Reference Links

Sean

I believe the following code will track long and short positions more accurately than that swapped
in previous posts. For the sake of brevity I have reduced Position to Pos. A long trade is assigned
a value of +2, and a short trade a value of -1. Therefore Pos will have a value >0 for any long
position (with or without a short position) and = ABS(1) for any short position (with or without a
long position). I guess you do not expect to be in both a long and short position at the same time,
but with system testing if it can happen then it will. There are probably a number of other values
that could be used for Position but +2 and -1 seem to make it simple enough to differentiate between
current positions.

Roy

Pos{ition}:=Ref(If(BarsSince(LongEntry OR Init)>=
  BarsSince(LongExit OR Init),0,2) +
  If(BarsSince(ShortEntry OR Init)>=
  BarsSince(ShortExit OR Init),0,-1),-0);
EnterLong:=Alert(Pos<1,2) AND Pos>=1;
CloseLong:=Alert(Pos>=1,2) AND Pos<1;
EnterShort:=Alert(Abs(Pos)<>1,2) AND Abs(Pos)=1;
CloseShort:=Alert(Abs(Pos)=1,2) AND Abs(Pos)<>1;