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
SetStopLoss in Live Account Error
Collapse
X
-
SetStopLoss in Live Account Error
I have a managed strategy where I use use SetStopLoss and SetProfitTarget. I set them initially in State.Configure and update them in OnExecution to the correct levels. I then reset them in OnPositionUpdate when flat. Everything works perfect when backtesting, however in real-time (live account) the strategy tries to modify the stop loss (about 100 times in 1 second) and throws an error that it can't modify the order (I have the strategy set to ignore errors so once the error is closed, the strategy is managed correctly). I am completely out of ideas on how to fix this, so I it would be great to be able to send the strategy and trace log to someone so they can double check if there is an issue internally with handling stop and targets in the managed approach, or if there is some unique order of events that I am not adhering.Tags: None
-
Hello Jack22,
Thank you for your note.
I have attached 3 samples you could import and take a look at, perhaps they may shed light on what you could be doing wrong.
If you are still unable to resolve your issue, send an email to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and attach the log and trace files for the day in subject which you can find in My Documents>NinjaTrader8>Log and My Documents>NinjaTrader8/Trace folders.
Please let us know if you need further assistance.Attached FilesAlan P.NinjaTrader Customer Service
-
**Update: support just stated this issue was fixed in 8.0.12.0**
Some more information. Everything works correctly in a sim account. Live account I run into this issue. I added print statements today before every SetStopLoss and every SetProfitTarget.
I SetStopLoss in State.Confiture (all good here--even though I add more Bars, I attach orders to BIP 0):
Code:else if (State == State.Configure) { if(this.iDebug) Print("Set Stop / Profit - Configure"); SetStopLoss(CalculationMode.Ticks, 20); SetProfitTarget(CalculationMode.Ticks, Math.Max(4, this.iProfitTarget01)); AddDataSeries(BarsPeriodType.Tick, 1); // 1 AddDataSeries(BarsPeriodType.Minute, 1); // 2 AddDataSeries(BarsPeriodType.Range, 1); // 3 }
Code:protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition) { if(Position.MarketPosition == MarketPosition.Flat) { if(this.iDebug) Print("Set Stop / Profit - OnPositionUpdate"); SetStopLoss(CalculationMode.Ticks, 20); SetProfitTarget(CalculationMode.Ticks, Math.Max(4, this.iProfitTarget01)); } }
Code:protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { // Long if(oLong01 != null && oLong01 == execution.Order) { if(execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { if(this.iDebug) Print("Set Stop / Profit - oLong01"); SetStopLoss(CalculationMode.Price, this.swingL[iStopList] - this.iStopLossOffset * TickSize); SetProfitTarget(CalculationMode.Ticks, this.iProfitTarget01); if(execution.Order.OrderState != OrderState.PartFilled) { oLong01 = null; } } } if(oLong02 != null && oLong02 == execution.Order) { if(execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { if(this.iDebug) Print("Set Stop / Profit - oLong02"); SetStopLoss(CalculationMode.Price, this.swingL[iStopList] - this.iStopLossOffset * TickSize); SetProfitTarget(CalculationMode.Ticks, this.iProfitTarget02); if(execution.Order.OrderState != OrderState.PartFilled) { oLong02 = null; } } } }
This is how I assign an Order in OnOrderUpdate:
Code:protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { if(order.Name == "L01") oLong01 = order; if(oLong01 != null && oLong01 == order) { if(oLong01.OrderState == OrderState.Cancelled || oLong01.OrderState == OrderState.Rejected) { oLong01 = null; } } if(order.Name == "L02") oLong02 = order; if(oLong02 != null && oLong02 == order) { if(oLong02.OrderState == OrderState.Cancelled || oLong02.OrderState == OrderState.Rejected) { oLong02 = null; } } }
Last edited by Jack22; 02-02-2018, 09:46 AM.
Comment
-
Originally posted by NinjaTrader_ChrisL View PostHello,
Thank you for the reply.
Was this strategy able to run this live properly after upgrading to NT8 R12? I can confirm that this was fixed in R12.
I look forward to hearing of your results.
Comment
-
Originally posted by Jack22 View PostI tested on a live account today and it seems like the issue was fixed in R12. I am running the same strategy live all week, so if anything changes I'll post here; otherwise, all is working as it should.
Comment
-
Hello Jack22,
Thank you for your update.
Please send me your log and trace files so we may look into this matter further.
You can do this by going to the Control Center-> Help-> Email Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.
Please list 'ATTN: Patrick H' in the subject line and reference this thread in the body of the email.
I look forward to assisting you further.
Comment
-
Hello bcomas,
Thank you for your post.
What errors are you getting when running your strategy on a live account?
Do you see any errors occur in the Log tab of the Control Center? If so, what do these report?
Note that setting the stop loss would not be recommended to do in OnExecution/OnPositionUpdate.
Please ensure that in your strategy the SetTrailingStop and SetStopLoss orders are reset before entry orders are placed.
If you are calling SetStopLoss in OnBarUpdate(), you would need to reset the stop loss before the next entry so that it is set back to an initial level.
Please see the SamplePriceModification example in the help guide documentation below for how this could be accomplished. What are you doing differently from the example script?
SamplePriceModification — https://ninjatrader.com/support/help...of_stop_lo.htm
Thanks in advance, I look forward to your reply.Brandon H.NinjaTrader Customer Service
- Likes 1
Comment
-
Thanks a lot for the instructions. I have changed the code like the attached. Hoppefully in live it will work like in Sim.Could you review it?
I replicated my strategy for the management of the StopLoss and Trailing.
BernardAttached Files
Comment
-
Hello,
Again in Live trading a Log alert came up with the following message using exactly the previous StrategyTEST for orders management:
LiveAccount××××, Cannot change order '439192773' because current order values already match. affected Order: BuyToCover 1 StopMarket @ 13546
it happen only on the trailing side(shorts). In low and high volatility...
How can I fix it?? Only remove the messages.. the trailing works ok. ..
Many Thanks in advance
Bernard
Comment
-
Hello bcomas,
Thank you for your note.
The error message means that a change order was submitted because the current order already matches the values you are trying to change the order to. This means that you would need to ensure that the change order is placed at a value that does not match the current order.
To clarify, are you wanting to stop the error messages from displaying on the screen or in the Log tab of the Control Center? If so, there is no documented or supported methods for stopping error messages from displaying.
Please let us know if we may assist further.Brandon H.NinjaTrader Customer Service
Comment
-
Thank you for your response.
This issue happened in 2018 ... It was solved but the solution is not clear.
All works perfect in Sim and in Live.
But in Live trading it sending several error messages that is annoying. For sure there is a simple solution. The SetTrailingStop() the cause of the messages ONLY in Live trading.
Bernard
Comment
-
Hello bcomas,
Thank you for your note.
The error message means that SetTrailStop() is adjusting the order to the same level. Are you calling SetTrailStop() from OnBarUpdate() multiple times? If so, this could be fixed with a simple boolean flag. For example:
public bool ShouldUpdateStop = true;
if(ShouldUpdateStop)
{
Update();
ShouldUpdateStop = false;
}
Using Print Statements within your code is also very useful to see how the code is running. If you add a Print statement right before the order changing code, do you see the print statement twice? You should also turn on TraceOrders in the strategy to see what the trace orders are saying about the orders.
Prints - https://ninjatrader.com/support/help...nt8/?print.htm
TradeOrders - https://ninjatrader.com/support/helpGuides/nt8/?traceorders.htm
Please note that there is no way to disable the messages from the Log tab of the Control Center.
Let me know if I can assist any further.Brandon H.NinjaTrader Customer Service
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Max238, Today, 01:28 AM
|
5 responses
42 views
0 likes
|
Last Post
by Max238
Today, 08:30 AM
|
||
Started by giulyko00, Yesterday, 12:03 PM
|
3 responses
12 views
0 likes
|
Last Post Today, 08:26 AM | ||
Started by habeebft, Today, 07:27 AM
|
1 response
14 views
0 likes
|
Last Post Today, 08:08 AM | ||
Hi
by AveryFlynn
Started by AveryFlynn, Today, 04:57 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:57 AM | ||
Started by r68cervera, Today, 05:29 AM
|
1 response
10 views
0 likes
|
Last Post Today, 07:47 AM |
Comment