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

Re: help with limit orders in TradeStation


  • To: "Omega Mailing List" <dennis@xxxxxxxxxx>
  • Subject: Re: help with limit orders in TradeStation
  • From: "W. Lawson McWhorter" <lawson@xxxxxxxxxxxxx>
  • Date: Sat, 17 Oct 1998 13:35:29 -0400 (EDT)

PureBytes Links

Trading Reference Links

On Fri, 16 Oct 1998 20:23:37 -0700, Dennis Holverstott wrote:

>> if condition1=1 then buy at market;
>> exitlong at entryprice(0) + 1 point limit;
>
>Yup, the good old 1 bar delay. As written, your code will generate the
>buy signal on bar 1. It will buy on the open of bar 2. On bar 3, the
>entryprice function will know you have a new long and issue the limit
>order. Bar 4 is the earliest your limit could be executed. Before bar 3,
>the entryprice function is working from the *previous* order.
>

Thanks Dennis for this well written explanation of the order in which TS processes 
code.  This reminded me of two excellent posts sent to the Omega-List a long time ago 
which I had saved, thinking they would one day be useful.  Sure enough, these old posts 
solved my problems with limit orders.  The solution involves creating your own 
variables for entryprice,marketposition,barssinceentry, etc.  The following are the two 
posts that I thought many list members might find useful.

Regards,

Lawson McWhorter

*** Post 1**********************

Both Marketposition and Barssinceentry are inconsistent in the way they evaluate
systems.

The results you get at the close of the bar depend on the TIME you entered the
trade.


If you change your position AT the close of a bar, then Marketposition will not
change until the close of the NEXT bar.

If you change your position BEFORE the close of a bar, then Marketposition will
change AT the close of that bar.


If you change your position AT the close of a bar, then Barssinceentry will not
start a new count until the close of the NEXT bar.

If you change your position BEFORE the close of a bar, then Barssinceenetry will
equal 0 at the close of that bar.


A good way to understand what is happening is with the following examples:

Let's say that at the close of bar#10, Marketposition=-1 and Barssinceentry=4.
We get a buy signal at the close of bar#11.
At the close of bar#11, Marketposition=-1 and barssinceentry=5.
At the close of bar#12, Marketposition=1 and barssinceentry=1.

Now, let's do it another way.
Again, at the close of bar#10, Marketposition=-1 and Barssinceentry=4.
This time get stopped long DURING bar#11.
At the close of bar#11, Marketposition=1 and barssinceentry=0.
At the close of bar#12, Marketposition=1 and barssinceentry=1. 

TS assumes that if you got a signal on the close of a bar then it is impossible
to actually enter the trade until the open of the next bar. So, even though you
get a pretty little arrow on your chart at the close, TS assumes you didn't
change your position until the next open. Also, barssinceentry is counting the
number of COMPLETE bars that you have been in the trade. That means you have to
be in from the open through the close. 

IMO, this is a terrible design. However, there is an easy way around it. In all
of my systems, I create my own variables for marketposition and barssinceentry.
I just call them MP and BSE. These variables are reset at the close everytime a
new rule comes in. This way, it doesn't matter if I got stopped into the trade
during the bar, or got the signal at the close of the bar. The numbers are
always consistent.

Hope this helps,

Michael

*** Post 2 *********************************

Michael L. asked me to forward a copy of this to the list:

for example, for a system that is never flat:

Vars:mp(0),bse(0);

if c>c[1] then begin
buy ("rule1") today close;
mp=1;bse=1;
end;

if c<c[1] then begin
sell("rule2") today close;
mp=-1;bse=1; 
end;
 
IF mp=1 and bse>2 then sell("rule3") tomorrow at l-.15 stop;
IF mp[1]=1 and bse[1]>2 and l<=l[1]-.15 and date=entrydate then begin
mp=-1;bse=1;
end;

IF mp=-1 and bse>4 then buy("rule4") tomorrow at h+.15 stop;
IF mp[1]=-1 and bse[1]>4 and h>=h[1]+.15 and date=entrydate then begin
mp=1;bse=1;
end;

if  mp=mp[1] then bse=bse+1;

{----------------------------------------------------------------------
}

I also make my own variables for ER (entryrule number), ATH(at$ h), ATL(at$
l),
etc. I do this because TS won't let me REVERSE a position based on any of
their
functions for these same things. All of these functions are set and reset
just
like the others. 

{So, a typical rule would look like this:} 

if c>c[1] then begin
buy ("rule1") today close;
mp=1;bse=1;er=1;ath=h;atl=l;
end;

{which then allows another rule to say}

If er=1 and bse>10 then sell("rule2") tomorrow at atl+.50 stop;
if er[1]=1 and bse[1]>10 and l<=atl+.50 and date=entrydate then begin
mp=-1;bse=1;er=2;ath=h;atl=l;
end;

I do this automatically for every rule in every system that I write. It gives
me
complete control and consistency.

Michael
73207.2214@xxxxxxxxxxxxxx