TS code
Posted: Wed Jun 20, 2007 8:19 pm
I apply the following strategy to AAPL, 4day, 10tick/bar, regular session chart. I only want one entry/exit per day. If price gaps up/down, I want to sellshort/buy 100 shares if price moves .30 towards the previous days close and close the position after a $.04 profit. I also want to exit the position after X minutes.
My Entriestoday part of the code doesn't appear to be working since I get many more than one entry/exit per day. Also, it always exits at the very next bar after entry which probably means my maxopenordertime used to exit isn't working.
Any idea what the problem is?
Inputs: Pullback$(.30), targetprofit(.02), maxopenordertime(400);
Variables: enterprice(0), exprice(0), value1(0);
If Date <> Date[1] and open <> close[1] then begin
{short entry prices}
If Open > close[1] then begin
enterprice = Open - pullback$;
exprice = enterprice - targetprofit;
Value1 = -1;
end;
{long entry prices}
If Open < close[1] then begin
enterprice = Open + pullback$;
exprice = enterprice + targetprofit;
Value1 = 1;
end;
end;
{exits}
If Marketposition = 0 and value1 = 1 and Entriestoday(currentdate) = 0 then Buy 100 shares
next bar at enterprice stop;
If Marketposition = 0 and value1 = -1 and Entriestoday(currentdate) = 0 then sellshort 100 shares
next bar at enterprice stop;
If marketposition = 1 then begin
If currenttime - entrytime >= maxopenordertime then sell 100 shares next bar at market;
sell 100 shares next bar at exprice limit;
end;
If marketposition = -1 then begin
If currenttime - entrytime >= maxopenordertime then buytocover 100 shares next bar at market;
buytocover 100 shares next bar at exprice limit;
End;
setexitonclose;
My Entriestoday part of the code doesn't appear to be working since I get many more than one entry/exit per day. Also, it always exits at the very next bar after entry which probably means my maxopenordertime used to exit isn't working.
Any idea what the problem is?
Inputs: Pullback$(.30), targetprofit(.02), maxopenordertime(400);
Variables: enterprice(0), exprice(0), value1(0);
If Date <> Date[1] and open <> close[1] then begin
{short entry prices}
If Open > close[1] then begin
enterprice = Open - pullback$;
exprice = enterprice - targetprofit;
Value1 = -1;
end;
{long entry prices}
If Open < close[1] then begin
enterprice = Open + pullback$;
exprice = enterprice + targetprofit;
Value1 = 1;
end;
end;
{exits}
If Marketposition = 0 and value1 = 1 and Entriestoday(currentdate) = 0 then Buy 100 shares
next bar at enterprice stop;
If Marketposition = 0 and value1 = -1 and Entriestoday(currentdate) = 0 then sellshort 100 shares
next bar at enterprice stop;
If marketposition = 1 then begin
If currenttime - entrytime >= maxopenordertime then sell 100 shares next bar at market;
sell 100 shares next bar at exprice limit;
end;
If marketposition = -1 then begin
If currenttime - entrytime >= maxopenordertime then buytocover 100 shares next bar at market;
buytocover 100 shares next bar at exprice limit;
End;
setexitonclose;