//Set strategy position Position.MarketPosition = MarketPosition.Long; //Flatten strategy position if(Condition) { ExitLong("", ""); Print("Market Position "+Position.MarketPosition); }
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Set strategy position without submitting order
Collapse
X
-
Set strategy position without submitting order
Is there a way to set a strategy position without using entry/exit signals? Here's some pseudo code that I've been trying within my OnBarUpdate() method:
Code:Tags: None
-
Hello sjwelch,
Thank you for your post and welcome to the NinjaTrader Support Forum!
Position.MarketPosition is not intended for this purpose and thus undesired results are expected.
In addition, ExitLong() only exits a position that truly exists.
There would be no method to generate a fake position. Please let me know if I may be of further assistance.
-
Patrick,
Thanks for your reply. As a follow-up question, is there any way to submit an entry signal to the strategy only without submitting it to the account? Like forcing a virtual entry signal maybe?
Here's why I'm asking: I don't like how NT "syncs" the account to the strategy, so I'm trying to do it vice versa. I have code that will tell me the account position. Now, I just need to sync the strategy position to the account position. I know this is not exactly supported, but if anybody has any hints I would be very grateful!
Comment
-
Hello,
Yes if you leave the strategy property Sync = false
and check mark immediately submit live working orders (go to tools -> options -> Strategies tab -> NinjaScript tab)
I strongly suggest reading through these options here: http://www.ninjatrader.com/support/h..._positions.htm
Let me know if this is not what you were looking for.LanceNinjaTrader Customer Service
Comment
-
Lance,
Thanks for the feedback, but that's not exactly what I'm looking for. The problem with that implementation is when I enable a strategy when the strategy is long but my account is flat. When the strategy exits long it will actually create a short position in my account. I can prevent the strategy from exiting long when my account is flat, but then the strategy will forever be long so that doesn't work.
If there was a way to send the exit long signal to the strategy ONLY without sending it to my account, that would solve the issue. I tried sending EnterLong/ExitLong with quantity 0 but that defaults to quantity 1.
Another thing I'm thinking about trying - if I send ExitLong within the OnBarUpdate() method, but then cancel it within the OnOrderUpdate() method, will my strategy still go to a flat position or will it realize that the order was cancelled and thus stay long?
Comment
-
Hello sjwelch,
Thank you for your response.
There may be a viable solution for what you are looking for. However, I would like to take this back a bit to understand this item better.
What is NinjaTrader doing to sync the account and strategy that is not desired on your end?
Why ExitLong() when there is no position? What are we trying to "simulate" here?
I look forward to your response.
Comment
-
Patrick,
This is the behavior I want: if I enable a strategy and the strategy position is in sync with the account position, the strategy should immediately start executing live orders. However, if I enable a strategy position and they are NOT in sync, I want the strategy to WAIT until the strategy matches my account position, THEN start normal operation.
Between the 4 possibilities of "Wait until flat" or "Immediately submit live..." and sync account = true/false, none of these iterations describes the behavior I want.
In other words, I want NT to sync the strategy to the account, not the account to the strategy. That's why I'm trying to see if there are ways to have the strategy send an order only to itself, without altering my account position.
Thanks again for your feedback.
Comment
-
Originally posted by sjwelch View PostLance,
Thanks for the feedback, but that's not exactly what I'm looking for. The problem with that implementation is when I enable a strategy when the strategy is long but my account is flat. When the strategy exits long it will actually create a short position in my account. I can prevent the strategy from exiting long when my account is flat, but then the strategy will forever be long so that doesn't work.
If there was a way to send the exit long signal to the strategy ONLY without sending it to my account, that would solve the issue. I tried sending EnterLong/ExitLong with quantity 0 but that defaults to quantity 1.
Another thing I'm thinking about trying - if I send ExitLong within the OnBarUpdate() method, but then cancel it within the OnOrderUpdate() method, will my strategy still go to a flat position or will it realize that the order was cancelled and thus stay long?Last edited by koganam; 05-06-2013, 04:40 PM.
Comment
-
Originally posted by koganam View PostIn which case, either issue manually an order to bring the account into sync with the strategy, or else arrange a bool or enum parameter whcih will allow you to use the Historical property to force realtime operation only for the session. You can then reset the strategy to normal once the day is over.
I've thought about filtering based on real-time vs. historical before, and I'm not sure if this will work for me. Here's a step-by-step scenario where I think it doesn't work (correct me if I'm wrong):
1) I have my strategy filter out historical bars so it uses real-time data only
2) I enter the market as expected. My strategy is long and the account is long and I hold the security overnight.
3) I have to restart NT overnight for maintenance. When I restart the strategy, the account is long and the strategy should hypothetically be long, but it's flat because I've filtered out historical bars. The two are now out of sync and the next sell signal will be missed because the strategy thinks it's flat.
4) As a result, I edit my strategy to use historical bars upon startup only (using time stamps or some other method)
5) Now, I enable a strategy when the strategy is long but the account is flat. The two are again out of sync and the next exit long signal will force my account short
If I'm missing something, please let me know. I'm still curious about what would happen if I send a buy signal in the OnBarUpdate() method but cancel the order in the OnOrderUpdate() method...could this work?
Comment
-
Sorry for the double post, but as I finished typing my response I realized how koganam's solution could work for me. If I configured my strategy to filter out historical bars only when my account is flat, I believe this will accomplish what I want.
Thanks everyone for your help!Last edited by sjwelch; 05-06-2013, 04:23 PM.
Comment
-
Originally posted by sjwelch View PostSorry for the double post, but as I finished typing my response I realized how koganam's solution could work for me. If I configured my strategy to filter out historical bars only when my account is flat, I believe this will accomplish what I want.
Thanks everyone for your help!
However, being a control freak, and not wanting NT to do anything outside my control, I have the somewhat more cumbersome method that I described.
1. I have a bool to trade realtime only. It is usually false.
2. I start my strategy, and it claims to be long, when the account is flat, because I always go home flat: never hold overnight.
3. I stop the strategy; enable the bool to realtime only; reenable the strategy. So the strategy will be flat, and take the next signal.
4. I let the strategy ride until it exits at end of day, or at target.
5. I stop the strategy, disable realtime only, ...
Comment
-
Originally posted by sjwelch View PostSorry for the double post, but as I finished typing my response I realized how koganam's solution could work for me. If I configured my strategy to filter out historical bars only when my account is flat, I believe this will accomplish what I want.
Thanks everyone for your help!
Real-time data missed a sell signal that's present on historical data, so my position is long despite historical being flat. Now, when I restart the strategy, the two are out of sync.
So now I'm back to square one. Any ideas? The most robust solution is finding a method to set strategy position without changing account position. If I call an EnterLong signal in my OnBarUpdate method and then cancel the order in the OnOrderUpdate method, would that update the strategy position or would the strategy position "think" it's long?
Comment
-
Originally posted by sjwelch View PostOk, so I tried this way but that didn't quite work out. Here's what happened:
Real-time data missed a sell signal that's present on historical data, so my position is long despite historical being flat. Now, when I restart the strategy, the two are out of sync.
So now I'm back to square one. Any ideas? The most robust solution is finding a method to set strategy position without changing account position. If I call an EnterLong signal in my OnBarUpdate method and then cancel the order in the OnOrderUpdate method, would that update the strategy position or would the strategy position "think" it's long?
That is the method that I use, because I understand the logic behind it. If you are looking for an automated method to read your account position, that is a different kettle of fish.
Comment
-
koganam,
I'm assuming you mean turn historical on/off (not real-time)? My strategy automatically does this when my account is flat, essentially per the method you described. I should have explained the problem a little better. Here's the scenario:
-I start up a strategy. The account is flat, historical position is irrelevant (it's filtered out)
-Real-time buy signal happens. My account and strategy position are both long. Everything's going well up to this point.
-I restart NT overnight (while still holding on to long position)
-When I restart, historical position is flat yet my account position is long. I believe this happened because the sell signal didn't trigger on real-time data, but it triggered for historical data (the two are slightly different). Now the two are out of sync (account is long, strategy is flat).
Ideally I would like the strategy to think it's long because my account position is long. Another possible solution is if there's a way to retain real-time data after restarting NT, and using that data instead of historical when starting a strategy. Not sure if this is possible though...
Comment
-
Originally posted by sjwelch View Postkoganam,
I'm assuming you mean turn historical on/off (not real-time)?
My strategy automatically does this when my account is flat, essentially per the method you described. I should have explained the problem a little better. Here's the scenario:
-I start up a strategy. The account is flat, historical position is irrelevant (it's filtered out)
-Real-time buy signal happens. My account and strategy position are both long. Everything's going well up to this point.
-I restart NT overnight (while still holding on to long position)
-When I restart, historical position is flat yet my account position is long. I believe this happened because the sell signal didn't trigger on real-time data, but it triggered for historical data (the two are slightly different). Now the two are out of sync (account is long, strategy is flat).
Ideally I would like the strategy to think it's long because my account position is long. Another possible solution is if there's a way to retain real-time data after restarting NT, and using that data instead of historical when starting a strategy. Not sure if this is possible though...
If I cannot communicate the below to you, then I have failed, and I will bow out of this discussion.
Code://pseudocode: If account position is not flat, process [I]Historical [/I]bars. If account position is flat, but processing [I]Historical[/I] bars makes the Strategy inMarket, then do not process Historical bars.
In order to make that happen, I have a parameter that determines whether I process Historical bars or not. That parameter is manually specified through the PropertyGrid, and may mean that I have to:- Stop the Strategy;
- Set or unset the parameter,
- Restart the Strategy in order to bring things into sync.
To put it simply, you are not doing what I described.Last edited by koganam; 05-13-2013, 09:42 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by connorlmarble, Today, 08:25 PM
|
0 responses
4 views
0 likes
|
Last Post
![]() |
||
Started by algospoke, 02-20-2025, 08:12 PM
|
7 responses
88 views
0 likes
|
Last Post
![]()
by MiCe1999
Today, 07:13 PM
|
||
Started by MiCe1999, Today, 05:55 PM
|
0 responses
9 views
0 likes
|
Last Post
![]()
by MiCe1999
Today, 05:55 PM
|
||
Started by volIQ, Today, 05:43 PM
|
0 responses
7 views
0 likes
|
Last Post
![]()
by volIQ
Today, 05:43 PM
|
||
Started by afoschini, 05-18-2020, 09:03 AM
|
6 responses
869 views
0 likes
|
Last Post
![]()
by shodown888
Today, 04:40 PM
|
Comment