NexusFi: Find Your Edge


Home Menu

 





How to exit the day after entry?


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Orjan with 6 posts (0 thanks)
    2. looks_two kevinkdog with 5 posts (2 thanks)
    3. looks_3 ABCTG with 2 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 8,090 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 14 posts
    2. attach_file 3 attachments




 
Search this Thread

How to exit the day after entry?

(login for full post details)
  #1 (permalink)
Orjan
Stockholm Sweden
 
Posts: 20 since Apr 2012
Thanks Given: 12
Thanks Received: 2

I use TradeStation 200i and use daily bars for my strategy and entry is at close of the day.
I have several exits, one is a fixed point exit.

Sometimes the exit should be the day after entry but that does never happen when I run the backtest, the exit is in those cases at best the second day after entryday, never the first day where it should be.

Anyone who knows how to make sure the trade can go to exit also the first day after entry?

Code for entry:
If Close > Open AND Marketposition = 0 AND MA>MA[1] AND Cantrade Then Buy This Bar at Close;

Code for exit:
If Marketposition = 1 then Exitlong at Stoploss or lower;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Looking for an MQL4 MetaTrader programmer/coder
The Elite Circle
Request for MACD with option to use different MAs for fa …
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Daytrading ES & NQ
32 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Retail Trading As An Industry
25 thanks
Battlestations: Show us your trading desks!
24 thanks

(login for full post details)
  #3 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,638 since Jul 2012
Thanks Given: 1,883
Thanks Received: 7,308



Orjan View Post
I use TradeStation 200i and use daily bars for my strategy and entry is at close of the day.
I have several exits, one is a fixed point exit.

Sometimes the exit should be the day after entry but that does never happen when I run the backtest, the exit is in those cases at best the second day after entryday, never the first day where it should be.

Anyone who knows how to make sure the trade can go to exit also the first day after entry?

Code for entry:
If Close > Open AND Marketposition = 0 AND MA>MA[1] AND Cantrade Then Buy This Bar at Close;

Code for exit:
If Marketposition = 1 then Exitlong at Stoploss or lower;


I think the reason for this is that, on the entry bar, Tradestation doesn't know you are in a position until after the bar closes (and all code is acted upon). So, on the entry bar, marketposition=0, which will then keep your exit statement from being executed. Try this instead, and see if it works:

Code for exit:
Sell at Stoploss or lower;

Follow me on Twitter Reply With Quote
(login for full post details)
  #4 (permalink)
Orjan
Stockholm Sweden
 
Posts: 20 since Apr 2012
Thanks Given: 12
Thanks Received: 2

Thanks,

Sell at Stoploss or lower

did not help.

As you say, market position is 0 at the close of the entry bar, but right after the open of next bar the market position should be 1, I thought. And therefore exit should be possible somewhere on that bar.

Reply With Quote
(login for full post details)
  #5 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,638 since Jul 2012
Thanks Given: 1,883
Thanks Received: 7,308


Orjan View Post
Thanks,

Sell at Stoploss or lower

did not help.

As you say, market position is 0 at the close of the entry bar, but right after the open of next bar the market position should be 1, I thought. And therefore exit should be possible somewhere on that bar.


Maybe it is your calculation of "stoploss" that is the issue, because I can get it to work fine when I simplify your entry and exit...


Here is an example, I enter at the close of August 12, and exit at the next bar open. Works fine:


if date=1130812 then
Buy ( "Entry Name" ) this bar at close ;

Sell next bar at market;







But, if I put the marketposition statement in, it delays it a day (which is what you were experiencing originally);

if date=1130812 then
Buy ( "Entry Name" ) this bar at close ;

if marketposition=1 then Sell next bar at market;



Follow me on Twitter Reply With Quote
(login for full post details)
  #6 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,638 since Jul 2012
Thanks Given: 1,883
Thanks Received: 7,308

Here is another example, using a stop loss... It exits the next day as desired.


if date=1130812 then
Buy ( "Entry Name" ) this bar at close ;


Sell next bar at 105.2 stop;



Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:
(login for full post details)
  #7 (permalink)
Orjan
Stockholm Sweden
 
Posts: 20 since Apr 2012
Thanks Given: 12
Thanks Received: 2

Yes, you are right, my calculation of stoploss was the problem. I have changed that and now it works as I want.
Thank you.

Reply With Quote
(login for full post details)
  #8 (permalink)
Orjan
Stockholm Sweden
 
Posts: 20 since Apr 2012
Thanks Given: 12
Thanks Received: 2

I am trading on daily bars and one of my exits is a gliding one: when 2 % profit has been reached, I take my profit if it goes down to 1,5 %. It works, but Tradestation does not take exit if both the target (2 %) and profit (1.5 %) happen on the same bar/day. Instead Tradestation takes exit next day, but that is not what I want.

I have checked intraday that the target is reached first in order, and after that the profit level is triggered - so that is not the problem.

Some ideas how to solve this?

Code for exit:

If MaxPositionProfit >= (Firsttarget * Entryprice/100) Then Exitlong at ("1:st") Entryprice + (Firstprofit * Entryprice/100) or lower ;

Reply With Quote
(login for full post details)
  #9 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,638 since Jul 2012
Thanks Given: 1,883
Thanks Received: 7,308


Orjan View Post
I am trading on daily bars and one of my exits is a gliding one: when 2 % profit has been reached, I take my profit if it goes down to 1,5 %. It works, but Tradestation does not take exit if both the target (2 %) and profit (1.5 %) happen on the same bar/day. Instead Tradestation takes exit next day, but that is not what I want.

I have checked intraday that the target is reached first in order, and after that the profit level is triggered - so that is not the problem.

Some ideas how to solve this?

Code for exit:

If MaxPositionProfit >= (Firsttarget * Entryprice/100) Then Exitlong at ("1:st") Entryprice + (Firstprofit * Entryprice/100) or lower ;

I know of no east way offhand. With daily bars, your code is read only at each close, and by then it is too late to do what you want.

You might take a look at Intrabar Order Generation (IBOG), if you haven't already. The problem is this is an advanced topic, and you can easily do things you don't intend to do.

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:
(login for full post details)
  #10 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,429 since Apr 2013
Thanks Given: 479
Thanks Received: 1,619


Orjan,
you will most definitely have to use intrabar order generation for this and kevinkdog is right with saying that this is a more advanced topic. Without IOG every order will become active on the next bar only (unless it's on the close of the current bar, which in reality will get you a fill not before the next bar, too).
When you enable IOG in your code this will affect all orders, so you need to make sure that your entries will still be executed at the point where they are now etc..

Regards,
ABCTG

Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:





Last Updated on November 4, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts