I'm trying to code a strategy that enters a position at bar close, but exits off of a tick based profit target. However, it appears the strategy itself only evaluates the profit target condition at the bar close instead of right after the position is opened. How would I go about splitting the conditions between the two?
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Separating open and close conditions
Collapse
X
-
Separating open and close conditions
Hello,
I'm trying to code a strategy that enters a position at bar close, but exits off of a tick based profit target. However, it appears the strategy itself only evaluates the profit target condition at the bar close instead of right after the position is opened. How would I go about splitting the conditions between the two?Tags: None
-
SetProfitTarget(CalculationMode.Ticks, 10);
EnterLong();
Or, you could use ExitLongLimit() but that would work better after you know the fill price you will receive.
If you are entering with a limit order, you could presume you will be filled at or about the limit price and go ahead and put the ExitLongLimit in there.
NinjaTrader won't actually put those exit orders in the market until you get a fill because it understands they are exits.
-
This is all in the documentation - for instance: https://ninjatrader.com/support/help...ive_delta2.htm
Comment
-
Hello rsz16,
Thanks for your post.
"I'm trying to code a strategy that enters a position at bar close, but exits off of a tick based profit target."
Logic can be separated between Calculate.OnEachTick and Calculate.OnBarClose using IsFirstTickOfBar. Please note that a hosted script will inherit the Calculate mode of the script that hosts it. You can take the following approach to differentiate logic between OnBarClose and OnEachTick processing.
Note that you should use Exit methods, such as ExitLongLimit()/ExitLongStopLimit(), if you separate the logic between OnBarClose and OnEachTick processing.
Please see this reference sample which demonstrates a technique used for those who need to separate their logic to calculate some values on each tick and others only on the close of a bar. You will set your host script to Calculate.OnEachTick and use if(IsFirstTickOfBar) and place all code that needs to calculate once every bar within that condition check. Then place all code that you want to calculate OnEachTick outside of the IsFirstTickOfBar condition check.
SampleEnterOnceExitEveryTick -https://ninjatrader.com/support/help...either_cal.htm
In regard to accessing Order Flow Cumulative Delta values in a NinjaScript, please see the sample code in the help guide page: https://ninjatrader.com/support/help...ta2.htmBrandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by DJ888, Yesterday, 10:57 PM
|
0 responses
6 views
0 likes
|
Last Post
by DJ888
Yesterday, 10:57 PM
|
||
Started by MacDad, 02-25-2024, 11:48 PM
|
7 responses
158 views
0 likes
|
Last Post Yesterday, 10:23 PM | ||
Started by Belfortbucks, Yesterday, 09:29 PM
|
0 responses
7 views
0 likes
|
Last Post
by Belfortbucks
Yesterday, 09:29 PM
|
||
Started by zstheorist, Yesterday, 07:52 PM
|
0 responses
7 views
0 likes
|
Last Post
by zstheorist
Yesterday, 07:52 PM
|
||
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
151 views
0 likes
|
Last Post
by rehmans
Yesterday, 06:44 PM
|
Comment