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
exit open position in state of transition
Collapse
X
-
exit open position in state of transition
What is the proper way to close or exit and open position in state of transition?Tags: None
-
Hello luxurious_04,
Thank you for the post.
Could you provide more detail on this question? Are you asking about closing historical positions before entering realtime to become flat? If you are currently trying something, are you seeing an error with what you are currently testing?
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
-
Hello luxurious_04,
The Transition state its self would not be a good place to do this type of logic, but you could do this on the first realtime OnBarUpdate call. If your strategy has entered into a historical position, and you are using the default start behavior the script should be yellow and wait for your exit condition to become true before starting.
Here is a simple test that would enter into a historical position, and then use the transition state to set a bool in which it can use to exit the position:
Code:private bool pastTransition = false; protected override void OnStateChange() { else if (State == State.Transition) { pastTransition = true; } } protected override void OnBarUpdate() { if(State == State.Historical) EnterLong(); if(pastTransition == true) { if(Position.MarketPosition == MarketPosition.Long)ExitLong(); pastTransition = false; } }
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jesse View PostHello luxurious_04,
The Transition state its self would not be a good place to do this type of logic, but you could do this on the first realtime OnBarUpdate call. If your strategy has entered into a historical position, and you are using the default start behavior the script should be yellow and wait for your exit condition to become true before starting.
Here is a simple test that would enter into a historical position, and then use the transition state to set a bool in which it can use to exit the position:
Code:private bool pastTransition = false; protected override void OnStateChange() { else if (State == State.Transition) { pastTransition = true; } } protected override void OnBarUpdate() { if(State == State.Historical) EnterLong(); if(pastTransition == true) { if(Position.MarketPosition == MarketPosition.Long)ExitLong(); pastTransition = false; } }
I look forward to being of further assistance.
Hi I’m trying to accomplish the same thing. I tried your code but didn’t work as expected. What start behavior are you suggesting? Basically I want to close historical positions when I turn on my strategy. I tried.
Code:if(State == State.Historical && CurrentBars[0] <=1 && hd==true) { Print("Sold"); ExitLong(Convert.ToInt32(Position.Quantity), "fresh", "Long1"); ExitShort(Convert.ToInt32(Position.Quantity), "fresh", "Short1"); }
Last edited by staycool3_a; 08-31-2018, 05:00 AM.
Comment
-
Hello staycool3_a,
Thank you for the post.
The code I had provided previously was used with the default settings of wait until flat sync account. If you are having difficulties with something you are trying, I would suggest that you create a new thread for that new question and include a sample of the syntax you had used while testing and results you had seen.
The sample you provided is also not like what I had provided, you have other conditions and two directions of exits without checking for positions.
I would suggest trying a more simple test as it looks like you may have multiple series in your test as well "CurrentBars[0]". If you are still having difficulties, please create a sample of the syntax you had used and create a new thread for the questions surrounding that syntax.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Tim-c, Today, 08:36 AM
|
1 response
2 views
0 likes
|
Last Post Today, 08:45 AM | ||
Started by goodknight777, Today, 08:43 AM
|
0 responses
2 views
0 likes
|
Last Post Today, 08:43 AM | ||
Started by martini, Yesterday, 04:45 PM
|
3 responses
27 views
0 likes
|
Last Post Today, 08:38 AM | ||
Started by Mestor, Today, 03:15 AM
|
2 responses
10 views
0 likes
|
Last Post
by Mestor
Today, 08:36 AM
|
||
Started by roblogic, 11-30-2023, 06:20 PM
|
57 responses
1,364 views
0 likes
|
Last Post
by playr101
Today, 08:35 AM
|
Comment