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

Re: Gremlins in TS or crappy code



PureBytes Links

Trading Reference Links

> What it is trying to do right now is wait for OB to be long or
> short and then buy the breakout of yesterday's high or low.  As you
> can see by the attched gif, on the first trade pictured it enters
> fine, but on the second trade it does not enter properly. 
> 
> If OddBall_Permission(7,0,0) = 1 and OpenD(0) < HighD(1) Then Buy at
> HighD(1) Stop;

The permission is 1 and OpenD(0) < HighD(1).  You exited the open 
position at EOD on 7/3, but then the system entered again at the open 
on 7/5.  Why, since it's supposed to buy at HighD(1) stop?

Because you kept issuing the buy order even after you went long on 
the 3rd, all the way through to the end of the day.  (If you enable 
multiple entries, I bet you'll see it going long on every bar that's 
above HighD(1).)  The order on the last bar of 7/3 was in effect on 
the 1st bar of 7/5, and since the open of that bar was above the 
HighD of 7/2, the system bought again.

You could resolve this by only issuing the buy order if you're 
currently flat (or not long), or by not issuing any orders late in 
the day.  Which might be a good idea in itself.

> Also what I need to do is specify not to take new trades that day
> if permission changes during the day ie. wait until tomorrow, but I
> don't know how to do that.  Any insights would be appreciated. 

Off the top of my head, you could do something like this:

Perm = OddBall_Permission(7,0,0);
if Date > Date[1] then SavePerm = Perm;
if Perm = SavePerm then begin
  If Perm = 1 and OpenD(0) < HighD(1) Then Buy at HighD(1) Stop;
  ...etc

BTW:  I think you're on TS2k or TS6 so this shouldn't be a problem 
for you, but for any TS4 users out there:  calling HighD/LowD/etc 
inside an "if" will produce bizarre results.  The xxxxD functions 
have a bug in TS4.  They must be called on EVERY BAR to work 
properly, and they won't be if they're inside an "if."  If you need 
to reference them inside an "if," call the function OUTSIDE the "if" 
and save it in a variable, then refer to the variable inside the "if".

Gary