Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
ATM Strategy question
Collapse
X
-
OK, just did a repair first. Loaded NT and closed my workspace. Opened a DOM and bare chart and added the sample strategy and started replay. I discovered a few very weird things. Once a position pending or entered I had to manually select something like 'AvtiveStrategy' in the DOM to see the target and stop bars. This is not even there to select if there is not a pending trade or an open position. Once the position closes, the ATM Strategy reverts back to the last. WTH is that all about? The next weird thing was that the 4 tick stop would move down to 5 ticks. As price traded lower, the stop crept down until at one point it was at -9 ticks. Not good at all. Soooo, I hope these things are not normal and will be fixed with a complete reinstall? Waiting to hear any explanations before doing so.
-
Looking at the default strategy I can see it is moving the stop, something I took out when I lifted the code for my use. I don't know what the default setting for the DOM is since my settings are the default. I thought I read it should be DisplaySelectedAtmStrategyOnly, which I use for the default. I see this SelectActiveAtmStrategyOnOrderSubmission works and automatically switches the DOM.
Another question is:
In my strategy I have two separate long and short entry tests so that depending on which entry is taken, the appropriate ATM Strategy will work. The problem is that only the first long test and first short test ever are executed. Using Print() shows the if() is hit but nothing ever happens.
By the way, thanks for the help, turns out I'm not going crazy!
Comment
-
SelectActive is the default. Please just stick with SampleAtmStrategy. No changes or modifications. I cannot help you diagnose the scenario unless you stick to the base case scenario.
To make subsequent entries you need to have reset the strategyId. Check Control Center logs for errors.Josh P.NinjaTrader Customer Service
Comment
-
Everything is good now with the sample, now I'm trying to debug the problem I just described. Two separate tests for longs and two for shorts. Essentially:
if(xxx)
"go long with ATM Strategy A", etc.
if(yyy)
"go long with ATM Strategy B", etc.
if(aaa)
"go short with ATM Strategy A", etc.
if(bbb)
"go short with ATM Strategy B", etc.
The problem is that (yyy) and (bbb) are never acted upon and no parenthesis are out of place.
Comment
-
Ok here is the section, probably with redundant code and not optimized, but needs to be working first.
Code:if(useATMstrategy) //Begin Section { if (Historical)return; if(wwwww || xxxxx || yyyyyy || !zzzzzz) {if(useOutputWindow){Print("Long Signals OK ");Print("");} if(FirstTickOfBar) {if (orderId.Length == 0 && atmStrategyId.Length == 0 && BuySignal[1] == 1) { atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "Strategy1", atmStrategyId); } }} if(nnnn && oooo && BuySignal[1] ==1 || ppppp && BuySignal[1] ==1) //<---No matter what is here, it never gets executed {if(useOutputWindow){Print("Long Signals+ OK ");Print("");} if(FirstTickOfBar) {if (orderId.Length == 0 && atmStrategyId.Length == 0) { atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "Strategy2", atmStrategyId); } }} if(!wwwww || !xxxxx || !yyyyyy || zzzzzz) {if(useOutputWindow){Print("Short Signals OK ");Print("");} if(FirstTickOfBar) {if (orderId.Length == 0 && atmStrategyId.Length == 0 && SellSignal[1] == 1) { atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(Action.Sell, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "Strategy1", atmStrategyId); } }} Print("Using ATM Strategy S+ "); if(!nnnn && !oooo && SellSignal[1] ==1] || !ppppp && SellSignal[1] ==1) //<---No matter what is here, it never gets executed {if(useOutputWindow){Print("Short Signals+ OK ");Print("");} if(FirstTickOfBar) {if (orderId.Length == 0 && atmStrategyId.Length == 0) { atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(Action.Sell, OrderType.Market, 0, 0, TimeInForce.Day, orderId, "Strategy2", atmStrategyId); } }} if (orderId.Length > 0) { string[] status = GetAtmStrategyEntryOrderStatus(orderId); // If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements if (status.GetLength(0) > 0) { // Print out some information about the order to the output window Print("The entry order average fill price is: " + status[0]); Print("The entry order filled amount is: " + status[1]); Print("The entry order order state is: " + status[2]); // If the order state is terminal, reset the order id value if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected") orderId = string.Empty; } } // If the strategy has terminated reset the strategy id else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat) atmStrategyId = string.Empty; if (atmStrategyId.Length > 0) { // You can change the stop price if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat) //AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId); // Print some information about the strategy to the output window Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId)); Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId)); Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId)); Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId)); } }//Closes the "if(useATMstrategy)" sectionLast edited by eDanny; 01-27-2009, 05:16 PM.
Comment
-
Why would that matter? When any of the four conditions are met, orderId.Length is checked and atmStrategyId.Length is checked to see if an order is in progress. If I make separate ID's for the two different ATM Strategy trades then I could have two orders open at once, correct? That is not my goal at this time. I must be not seeing something.
Comment
-
{if (orderId.Length == 0 && atmStrategyId.Length == 0)
Before the order is executed.
else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
atmStrategyId = string.Empty;
After an order is made.
Are these not the checks you are looking for?
That code posted is the whole body of trade execution section, the rest is all testing for the trade conditions. If there is something more I need that I missed, what is it?Last edited by eDanny; 01-28-2009, 10:48 AM.
Comment
-
OK, changed orderId to orderId0 and added orderId1. Did the same for atmStrategyId. Now for every trade I should check if orderId0.Length == 0 && atmStrategyId0.Length == 0 && orderId1.Length == 0 && atmStrategyId1.Length == 0 and if all true an entry is made, correct?Last edited by eDanny; 01-28-2009, 11:11 AM.
Comment
-
Right. So those may be the necessary checks and those checks are likely the ones that are preventing your additional entries because they are not reset. You will need to slowly step through your code and track the state of them to see when they reset (if ever).Josh P.NinjaTrader Customer Service
Comment
-
eDanny,
Unfortunately I cannot assist you in debugging. You need to slowly step through your code at every single step and find what all your variables are before each if-statement and find which one is stopping you from calling additional AtmStrategyCreate()s.
Always check the Control Center for errors as well. You should be able to get unique orderIds. Print it out immediately after you set it.Josh P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
608 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
355 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
561 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment