How to exit the day after entry? - futures io
futures io futures trading



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 6,032 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 14 posts
    2. attach_file 3 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

How to exit the day after entry?

(login for full post details)
  #1 (permalink)
Stockholm Sweden
 
 
Posts: 20 since Apr 2012
Thanks: 12 given, 2 received

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 futures io?
Which kind of Blockvolume is visible? - order processing
Emini and Emicro Index
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
What blockvolume is visible? - order processing
NinjaTrader
Short Interest Ratio indicator?
ThinkOrSwim
Automatic pattern research with NT
Elite Algorithmic NinjaTrader Trading
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Selling Options on Futures?
109 thanks
Battlestations: Show us your trading desks!
108 thanks
Rank your Futures vs Stocks trading priority
55 thanks
Want your NinjaTrader indicator created, free?
27 thanks
Whats this confusion with margins?
21 thanks
 
(login for full post details)
  #3 (permalink)
 
 
Posts: 2,979 since Jul 2012
Thanks: 1,576 given, 5,905 received



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)
Stockholm Sweden
 
 
Posts: 20 since Apr 2012
Thanks: 12 given, 2 received

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)
 
 
Posts: 2,979 since Jul 2012
Thanks: 1,576 given, 5,905 received


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)
 
 
Posts: 2,979 since Jul 2012
Thanks: 1,576 given, 5,905 received

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)
Stockholm Sweden
 
 
Posts: 20 since Apr 2012
Thanks: 12 given, 2 received

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)
Stockholm Sweden
 
 
Posts: 20 since Apr 2012
Thanks: 12 given, 2 received

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)
 
 
Posts: 2,979 since Jul 2012
Thanks: 1,576 given, 5,905 received


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)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received


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:
 
(login for full post details)
  #11 (permalink)
Stockholm Sweden
 
 
Posts: 20 since Apr 2012
Thanks: 12 given, 2 received

Intrabar order generation is not possible in TradeStation 2001. But maybe I can build the system with intraday bars, lets say 15 min., and write an instruction that takes entry at the close of the day. I also need an daily MACD-indcator But for the moment I don't know how to do that.

Perhaps the soluton is to combine two charts. One for data 1 = 15 min and one for data 2 = daily?

Reply With Quote
 
(login for full post details)
  #12 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received

True, I totally forgot about that. Your solution with two datastreams will likely reduce the occurrence of your problem, but it will not fix it. Even if you build everything based on a minute chart and emulate the daily bars, the problem can still happen.
You might want to take a trial for Multicharts or Tradestation 9 and see how much different the performance would be. Maybe the benefits already merit switching completely for you.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #13 (permalink)
 
 
Posts: 2,979 since Jul 2012
Thanks: 1,576 given, 5,905 received


Orjan View Post
Intrabar order generation is not possible in TradeStation 2001. But maybe I can build the system with intraday bars, lets say 15 min., and write an instruction that takes entry at the close of the day. I also need an daily MACD-indcator But for the moment I don't know how to do that.

Perhaps the soluton is to combine two charts. One for data 1 = 15 min and one for data 2 = daily?

Your solution would work, but calculating with 2 datastreams is tricky too. If you go this route, I recommend spending a lot of time making sure that anything you calculate from datastream2 is really what you want, and that it updates every day, not every 15 minutes.

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #14 (permalink)
Stockholm Sweden
 
 
Posts: 20 since Apr 2012
Thanks: 12 given, 2 received

Yes, a trial for Multicharts or Tradestation 9 would be the best I guess.

Reply With Quote
 
(login for full post details)
  #15 (permalink)
Buenos Aires / Argentina
 
Experience: Intermediate
Platform: Tradestation
Trading: YM
 
Posts: 15 since Oct 2013
Thanks: 46 given, 14 received

Better is a trial in diferents plattaforms.

Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > How to exit the day after entry?


Last Updated on November 4, 2013


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts