protected override void Initialize()
{
SetStopLoss(sENTRY1L, CalculationMode.Ticks, 6, false);
SetProfitTarget(sENTRY1L, CalculationMode.Ticks, 4);
........
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strange Profit Targets
Collapse
X
-
Strange Profit Targets
I have been testing a strategy for quite a while now that uses the following code:
In my testing, I have never had an issue with the "StopLoss" or "Target". However, I have given my strategy to a friend and his targets are messed up. Instead of using target = 4, sometimes it gets out after 3 ticks or even 1 tick. It's bizarre. Is there another way I should be specifying stop and target?Code:Tags: None
-
OK, I have narrowed the problem down - the strategy ALWAYS uses limit orders and yet when I look at my friend's "Orders tab", the strategy is sometimes taking market orders! What I see is say a long limit order filled and then a few seconds later sold at market price. Under what scenario would this happen? I do have CancelOrder logic in case price moves far enough and an order is not yet filled but I wouldn't think that CancelOrder would interfere with positions - correct?
Comment
-
OK, let me ask this. Suppose CancelOrder is called on an open position which really doesn't make sense but suppose it gets called. Would CancelOrder affect the open position in any way?
Comment
-
CancelOrder() accepts an IOrder object representing an order. It cannot be called on an open position. If you call CancelOrder on an order that is not available, then there will likely be an error message "Object reference not set to an instance of an object" in both TraceOrders output and log tab of control center.
We're happy to help work through strategy items you're having trouble with. The best way for us to do so is if you provide some code snippets, example sequences, messages you aren't sure about or screenshot evidence of any issues you're seeing.Last edited by NinjaTrader_RyanM1; 11-17-2011, 01:02 PM.Ryan M.NinjaTrader Customer Service
Comment
-
Here is some code:
Here is the order part to go long (order type is set to BID_ASK):Code:protected override void Initialize() { SetProfitTarget(sENTRY1L, CalculationMode.Ticks, ProfitTarget); SetProfitTarget(sENTRY1S, CalculationMode.Ticks, ProfitTarget); SetStopLoss(CalculationMode.Ticks, StopLoss); EntriesPerDirection=1; EntryHandling = EntryHandling.UniqueEntries; CalculateOnBarClose = true; //Exit On Close ExitOnClose = false; //Error Handling in event of "Rejected Order" //RealtimeErrorHandling = RealtimeErrorHandling.StopStrategyCancelOrdersClosePosition; (Default) RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction; //Trace Orders to LOG TraceOrders = true; //Init Connections dStatus = ConnectionStatus.Connected; oStatus = ConnectionStatus.Connected; //Init order objects iOrderL1 = null; iOrderS1 = null; }
Here is the OnExecution part:Code:if (((TakeHistorical && Historical) || !Historical)) { if (iOrderType == eOrderType.MARKET) { iOrderL1 = EnterLong(iQuantity1, sENTRY1L); } else if (iOrderType == eOrderType.BID_ASK) { tVars.lEntry = GetCurrentBid(); iOrderL1 = EnterLongLimit(0, true, iQuantity1, tVars.lEntry, sENTRY1L); } else if (iOrderType == eOrderType.LIMIT) { tVars.lEntry = Close[0] - iLimitOffsetTicks * TickSize; iOrderL1 = EnterLongLimit(0, true, iQuantity1, tVars.lEntry, sENTRY1L); } }
Code:protected override void OnExecution(IExecution execution) { #region orderL1 if (iOrderL1 != null) { if (iOrderL1.Token == execution.Order.Token) { //----------------------------------------------------- // PENDING ORDERS (PendingSubmit / Working / Accepted) //----------------------------------------------------- if ( execution.Order.OrderState == OrderState.PendingSubmit || execution.Order.OrderState == OrderState.Working || execution.Order.OrderState == OrderState.Accepted ) { //Log This ////LogFile.LogToFile(Historical, "OnExecution : Long - Orderstate PendingSubmit / Working / Accepted", true); } //---------------------------- // Filled Order Response? //---------------------------- if (execution.Order.OrderState == OrderState.Filled) { //clear the order variable iOrderL1 = null; } //---------------------------- //Rejected Long Order? //---------------------------- if (execution.Order.OrderState == OrderState.Rejected) { //clear the order variable iOrderL1 = null; //Log This ////LogFile.LogToFile(Historical, "OnExecution : Long - Rejected", true); } } } #endregion #region orderS1 if (iOrderS1 != null) { if (iOrderS1.Token == execution.Order.Token) { //----------------------------------------------------- // PENDING ORDERS (PendingSubmit / Working / Accepted) //----------------------------------------------------- if ( execution.Order.OrderState == OrderState.PendingSubmit || execution.Order.OrderState == OrderState.Working || execution.Order.OrderState == OrderState.Accepted ) { } //---------------------------- // Filled Order Response? //---------------------------- if (execution.Order.OrderState == OrderState.Filled) { //clear the order variable iOrderS1 = null; } //---------------------------- //Rejected Long Order? //---------------------------- if (execution.Order.OrderState == OrderState.Rejected) { //clear the order variable iOrderS1 = null; //Log This //LogFile.LogToFile(Historical, "OnExecution : Short - Rejected", true); } } } #endregion }
Comment
-
Great, Thanks for including the code snippet. Can you also please include the following details that will allow us to reproduce what you're seeing.
1) The steps needed to see.
2) Your expectations of behavior based on the strategy and steps.
For # 1 you can attach a screenshot of the strategy settings. For #2 this is just to find out what you are expecting and where the results deviate from your expectations.Ryan M.NinjaTrader Customer Service
Comment
-
OK, pls see attachments for settings and my friends trades.
He has two trades. You can clearly see the targets are wrong, being filled at +1 tick and -3 ticks. But notice the settings are +4 profit target and -6 stop loss. And notice the setting is BID_ASK for order type.
Notice on his order tab, there are MARKET orders.
Comment
-
Are you sure he's running the strategy you posted? I don't see any connection with the signal names and the screenshot you posted, and the name provided for set orders is always "Profit Target" and "Stop Loss", never "Sell". At this point, there is no need for you to be in the middle between NT support and your friend. Please have him email support 'at' ninjatrader 'dot' com and we'll arrange a time where I can take a look at things over remote assistance.Ryan M.NinjaTrader Customer Service
Comment
-
Are you resetting your StopLoss when you go flat ?Originally posted by scottreynolds View PostOK, I have narrowed the problem down - the strategy ALWAYS uses limit orders and yet when I look at my friend's "Orders tab", the strategy is sometimes taking market orders! What I see is say a long limit order filled and then a few seconds later sold at market price. Under what scenario would this happen? I do have CancelOrder logic in case price moves far enough and an order is not yet filled but I wouldn't think that CancelOrder would interfere with positions - correct?
Comment
-
-
Yes Scott, that would be needed as otherwise the script may use a legacy stop price in it's calcs : http://www.ninjatrader.com/support/f...ead.php?t=3222
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
650 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 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
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
577 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment