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
Long and Short Simultaneously
Collapse
X
-
Long and Short Simultaneously
I'm working on script that sometimes produces a long entry while currently in a short position. I'd like to be in both positions at the same time. However, when I run a backtest the short position gets closed by the Strategy Analyzer ("Close position" is shown in the "Exit name" column on the "Trades" page). If I set the code to trade only long or only short this doesn't happen. What's going on here and how do I fix it?Tags: None
-
Hello spottysallrite,
Thanks for your post.
A NinjaScript strategy cannot have a long position and a short position on the same account/instrument combination.
If the strategy entered a long position and then you call an Enter method to place a short order such as EnterShort(), the long position will be closed and the strategy will place the short entry order.
From the Managed Approach help guide: "Entry() methods will reverse the position automatically. For example if you are in a 1 contract long position and now call EnterShort() -> you will see 2 executions, one to close the prior long position and the other to get you into the desired 1 contract short position."
Managed Approach: https://ninjatrader.com/support/help...d_approach.htm
To truly have an open long account position and an open short account position on the same instrument (instead of a net flat account position), this would require placing trades to two different accounts. One account to hold a long position, the other account to hold a short position.
See this forum thread which discusses this topic: https://forum.ninjatrader.com/forum/...t792660Brandon H.NinjaTrader Customer Service
- Likes 1
-
I'm not following. On the Strategy Analyzer there is the option, under "Order handling" for "Entries per direction". Does this not allow one to be both long and short at the same time?
Comment
-
Hello spottysallrite,
Thanks for your notes.
The 'Entry Handling' and 'Entries Per Direction' property determine how many orders can be placed in a single direction when in a position.
This does not allow for you to be in a long position and a short position at the same time.
NinjaTrader does not support being in a long position and a short position at the same time on the same account/instrument combination. This would require placing trades to two different accounts. One account to hold a long position, the other account to hold a short position.
EntriesPerDirection and EntryHandling could be used to control the maximum number of entries allowed per direction while a position.
If you set Entry Handling to EntryHandling.AllEntries, NinjaScript will process all entry order methods up to the maximum allowable entries set in the EntriesPerDirection property. For example, if you set EntriesPerDirection to 3 and use EntryHandling.AllEntries, up to a total of 3 entry orders will process.
If you set Entry Handling to EntryHandling.UniqueEntries, NinjaScript will process order entry methods up to the maximum allowable entries set by the EntriesPerDirection property for each uniquely named entry. For example, if you have two entry order methods using unique signal names ("entry1" and "entry2"), set EntriesPerDirection to 3, and use EntryHandling.UniqueEntries, a maximum number of 3 entry orders will process for each uniquely named entry order (up to 3 orders for "entry1" and 3 orders for "entry2").
See the help guide documentation below for more information.
EntriesPerDirection: https://ninjatrader.com/support/helpGuides/nt8/NT HelpGuide English.html?entriesperdirection.htm
EntryHandling: https://ninjatrader.com/support/helpGuides/nt8/NT HelpGuide English.html?entryhandling.htm
Brandon H.NinjaTrader Customer Service
Comment
-
Hmmm. Well, it's certainly possible to have one strategy trade only long, and another to trade only short. Or, for the script to check if there is already a position, so not to enter an order for the opposite direction.
The reason I'd like to have the option of being long and short at the same time is that I'm thinking one might mitigate the other (kinda like a trailing stop). That is, after you enter a position you don't really know which direction the market will take. So, if after entering the first position then conditions change so as to indicate a different direction, then I'd like to enter a trade in that direction and not close the prior position. Since the algos for each long and short are independent of each other, it could well be that each produce winning trades, just closing at different times.
So, it would be nice to run optimizations that would show how much one strategy mitigates the other (ie, allowing the possibility of being both long and short at the same time). With this current mode (ie, disallowing trades in the opposite direction at the same time), performance is decreased (as indicated by Total net profit and Max drawdown).
Thoughts?
Comment
-
elirion, you missed my point. I wasn't suggesting that I should be able to implement this script on a single brokerage account. What I want to see is how the overall performance (especially the drawdown) is affected if simultaneous positions were possible. Yes, one could run backtests for each strategy, then "add" the results of the two. That works for something like Total net profit and total number of trades, but adding the drawdown from one strategy to the drawdown of another strategy doesn't make sense.
- Likes 1
Comment
-
Hello spottysallrite,
Thanks for your notes.
As stated previously, NinjaTrader does not support going both long and short on the same account/instrument combination at the same time. You could either go long on an account/instrument combination or you could go short on an account/instrument combination.
Further, NinjaTrader does not support hedging.
The supported means for having a long position and short position at the same time on the same instrument would be to submit the long order to one account and submit the short order to a separate account.
See this forum thread for more information: https://forum.ninjatrader.com/forum/...92660%E2%80%8B
We are tracking interest in an existing feature request for the ability to generate a strategy group backtest report that shows combined results of multiple backtests ran on multiple strategies in the Strategy Analyzer
I have added your vote to this feature request.
This request is being tracked under the number SFT-6065.
As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted on the Release Notes page of the Help Guide.
Release Notes — https://ninjatrader.com/support/help...ease_notes.htm
Last edited by NinjaTrader_BrandonH; 03-25-2024, 09:26 AM.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,964 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
4 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
52 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
5 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
||
Started by lightsun47, Today, 03:51 PM
|
0 responses
8 views
0 likes
|
Last Post
by lightsun47
Today, 03:51 PM
|
Comment