protected void pBull() { if (!buyOn) return; if (UseTrend && !IsRising(ValuesAlligatorTeeth)) { Log("Limit not setted. Outside trend for " + patternType + " time " + Time[0], LogLevel.Information); Draw.Diamond(this, "NTrendBull" + Time[0], true, 0, Open[0] - TickSize * 35, System.Windows.Media.Brushes.Red); return; } double price = Low[0]; double bar = High[0] - Low[0]; double sl, tp, entry; Log("Set Limit Order type " + patternType + " time " + Time[0], LogLevel.Information); for (int index = 0; index < fibo_count; index++) { int half = 0; Order order = null; Order orderH = null; entry = price + bar * fiboArr[index, 0] / 100; if (entry >= GetCurrentAsk()) continue; if (onFixSL) sl = entry - fixSL * TickSize; else sl = price + bar * fiboArr[index, 1] / 100; if (onFixTP) tp = entry + fixTP * TickSize; else tp = price + bar * fiboArr[index, 2] / 100; if (CloseHalf && lotCorr > 1) { half = lotCorr / 2; orderH = EnterLongLimit(0, true, half, entry, signalCorr[index] + "_1"); } order = EnterLongLimit(0, true, lotCorr - half, entry, signalCorr[index]); if (orderH == null && order == null) { Log("null order " + Time[0], LogLevel.Information); orderCorr[index] = null; orderCorrHalf[index] = null; continue; } if (sl == entry) sl -= TickSize; if (tp == entry) tp += TickSize; if (order != null) { SetStopLoss(signalCorr[index], CalculationMode.Price, sl, false); SetProfitTarget(signalCorr[index], CalculationMode.Price, tp, MITTP); } if (orderH != null) { SetStopLoss(signalCorr[index] + "_1", CalculationMode.Price, sl, false); SetProfitTarget(signalCorr[index] + "_1", CalculationMode.Price, tp, MITTP); } signalTP[index] = tp; signalWork[index] = false; orderCorr[index] = order; orderCorrHalf[index] = orderH; Log("Set Limit Order success. " + index + " time" + Time[0], LogLevel.Information); } } protected void pBear() { if (!sellOn) return; if (UseTrend && !IsFalling(ValuesAlligatorTeeth)) { Log("Limit not setted. Outside trend for " + patternType + " time " + Time[0], LogLevel.Information); Draw.Diamond(this, "NTrendBear" + Time[0], true, 0, Open[0] + TickSize * 50, System.Windows.Media.Brushes.Red); return; } double price = High[0]; double bar = High[0] - Low[0]; double sl, tp, entry; Log("Set Limit Order type " + patternType + " time " + Time[0], LogLevel.Information); for (int index = 0; index < fibo_count; index++) { int half = 0; Order order = null; Order orderH = null; entry = price - bar * fiboArr[index, 0] / 100; if (entry <= GetCurrentBid()) continue; if (onFixSL) sl = entry + fixSL * TickSize; else sl = price - bar * fiboArr[index, 1] / 100; if (onFixTP) tp = entry - fixTP * TickSize; else tp = price - bar * fiboArr[index, 2] / 100; if (CloseHalf && lotCorr > 1) { half = lotCorr / 2; orderH = EnterShortLimit(0, true, half, entry, signalCorr[index] + "_1"); } order = EnterShortLimit(0, true, lotCorr - half, entry, signalCorr[index]); if (orderH == null && order == null) { Log("null order " + Time[0], LogLevel.Information); orderCorr[index] = null; orderCorrHalf[index] = null; } if (sl == entry) sl += TickSize; if (tp == entry) tp -= TickSize; if (order != null) { SetStopLoss(signalCorr[index], CalculationMode.Price, sl, false); SetProfitTarget(signalCorr[index], CalculationMode.Price, tp, MITTP); } if (orderH != null) { SetStopLoss(signalCorr[index] + "_1", CalculationMode.Price, sl, false); SetProfitTarget(signalCorr[index] + "_1", CalculationMode.Price, tp, MITTP); } signalTP[index] = tp; signalWork[index] = false; orderCorr[index] = order; orderCorrHalf[index] = orderH; Log("Set Limit Order success. " + index + " time " + Time[0], LogLevel.Information); } }
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 problems
Collapse
X
-
SetStopLoss problems
Hello! I have the strategy code:
Code:Last edited by xasser; 05-29-2020, 02:33 PM.Tags: None
-
Hi xasser, thanks for your question.
Please try calling SetStopLoss and SetProfitTarget before submitting the order. SetStopLoss and SetProfitTarget apply the protective order to any orders submitted after they are called.
Please let me know if this does not resolve your inquiry.Chris L.NinjaTrader Customer Service
-
Even with partial execution of an order to open a position, stops are placed. Then the position opens and when changing stops an error is issued: 'Cannot change order '1192556598' because current order values already match.'
Code:[TABLE="border: 0, cellpadding: 0, cellspacing: 0"] [TR] [TD="width: 575"]Disabling NinjaScript strategy 'XO1/202142948'[/TD] [/TR] [TR] [TD]Order='26865dc1849640099da48e14d2131672/7PQ6868' Name='Profit target' New state='Cancelled' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3004.5 Quantity=2 Type='MIT' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='26865dc1849640099da48e14d2131672/7PQ6868' Name='Profit target' New state='Cancel submitted' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3004.5 Quantity=2 Type='MIT' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]7PQ6868, Cannot change order '1192556598' because current order values already match. affected Order: BuyToCover 1 StopMarket @ 3010.5[/TD] [/TR] [TR] [TD]Strategy 'XO1/202142948' submitted an order that generated the following error 'Unable to change order'. Strategy has sent cancel requests, attempted to close the position and terminated itself.[/TD] [/TR] [TR] [TD]Order='1192556598/7PQ6868' Name='Stop loss' New state='Working' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3010.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='Unable to change order' Native error='Cannot change order '1192556598' because current order values already match.'[/TD] [/TR] [TR] [TD]Order='1192556598/7PQ6868' Name='Stop loss' New state='Accepted' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3010.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='26865dc1849640099da48e14d2131672/7PQ6868' Name='Profit target' New state='Trigger pending' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3004.5 Quantity=2 Type='MIT' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='26865dc1849640099da48e14d2131672/7PQ6868' Name='Profit target' New state='Change submitted' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3004.5 Quantity=2 Type='MIT' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Execution='314793676557' Instrument='ES 06-20' Account='7PQ6868' Exchange=Globex Price=3008 Quantity=1 Market position=Short Operation=Operation_Add Order='1192565567' Time='5/29/2020 11:29 AM'[/TD] [/TR] [TR] [TD]Order='1192565567/7PQ6868' Name='Fibo_1_1' New state='Filled' Instrument='ES 06-20' Action='Sell short' Limit price=3008 Stop price=0 Quantity=2 Type='Limit' Time in force=GTC Oco='' Filled=2 Fill price=3008 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Instrument='ES 06-20' Account='7PQ6868' Average price=3008 Quantity=1 Market position=Short Operation=Operation_Add[/TD] [/TR] [TR] [TD]Order='1192556598/7PQ6868' Name='Stop loss' New state='Working' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3010.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='1192556598/7PQ6868' Name='Stop loss' New state='Accepted' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3010.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='2dbb181d1adf4f14ae5cd9949dd4ffeb/7PQ6868' Name='Stop loss' New state='Submitted' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3010.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='26865dc1849640099da48e14d2131672/7PQ6868' Name='Profit target' New state='Trigger pending' Instrument='ES 06-20' Action='Buy to cover' Limit price=0 Stop price=3004.5 Quantity=1 Type='MIT' Time in force=GTC Oco='314793671181' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]NinjaScript strategy 'XO1/202142948' submitting order[/TD] [/TR] [TR] [TD]NinjaScript strategy 'XO1/202142948' submitting order[/TD] [/TR] [TR] [TD]Execution='314793671181' Instrument='ES 06-20' Account='7PQ6868' Exchange=Globex Price=3008 Quantity=1 Market position=Short Operation=Operation_Add Order='1192565567' Time='5/29/2020 11:29 AM'[/TD] [/TR] [TR] [TD]Order='1192565567/7PQ6868' Name='Fibo_1_1' New state='Partially filled' Instrument='ES 06-20' Action='Sell short' Limit price=3008 Stop price=0 Quantity=2 Type='Limit' Time in force=GTC Oco='' Filled=1 Fill price=3008 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='1192565568/7PQ6868' Name='Fibo_1' New state='Working' Instrument='ES 06-20' Action='Sell short' Limit price=3008 Stop price=0 Quantity=2 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='1192565568/7PQ6868' Name='Fibo_1' New state='Accepted' Instrument='ES 06-20' Action='Sell short' Limit price=3008 Stop price=0 Quantity=2 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='1192565567/7PQ6868' Name='Fibo_1_1' New state='Working' Instrument='ES 06-20' Action='Sell short' Limit price=3008 Stop price=0 Quantity=2 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='1192565567/7PQ6868' Name='Fibo_1_1' New state='Accepted' Instrument='ES 06-20' Action='Sell short' Limit price=3008 Stop price=0 Quantity=2 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='6eeccbae48ce4acb82a8177da5a54873/7PQ6868' Name='Fibo_1' New state='Submitted' Instrument='ES 06-20' Action='Sell short' Limit price=3008 Stop price=0 Quantity=2 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Order='d6b2e8f79a2e44a8907f26288ba4a5f4/7PQ6868' Name='Fibo_1_1' New state='Submitted' Instrument='ES 06-20' Action='Sell short' Limit price=3008 Stop price=0 Quantity=2 Type='Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''[/TD] [/TR] [TR] [TD]Set Limit Order success. 0 time 5/29/2020 11:20:00 AM[/TD] [/TR] [TR] [TD]NinjaScript strategy 'XO1/202142948' submitting order[/TD] [/TR] [TR] [TD]NinjaScript strategy 'XO1/202142948' submitting order[/TD] [/TR] [TR] [TD]Set Limit Order type 2 time 5/29/2020 11:20:00 AM[/TD] [/TR] [/TABLE]
Comment
-
Hello! I did not change the stop. I set a limit order on two lots using EnterShortLimit and put two stops on it using SetStopLoss and SetProfitTarget. With partial execution of the limit order, stops were established. OK. When the position was fully opened, this error occurred.
Comment
-
Hello xasser,
The error received is a native error from the broker. The broker's order routing servers are returning an error when the order is attempted to be changed to the same price.
To prevent the strategy from being deactivated, you can set the strategy's RealtimeErrorHandling property to IgnoreAllErrors and then trap the UnableToChangeOrder error in OnOrderUpdate. If the order could not be changed, and there is no cancel or fill seen for the order, you can expect it to still be protecting your position, and it would not be necessary to take any additional action.
Another option would be to attempt moving the order to a different price and then back to the desired price so you can see confirmation of the order moving to your desired price.
RealtimeErrorHandling - https://ninjatrader.com/support/help...orhandling.htm
OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm
Please let me know if I can be of further assistance.Attached FilesJimNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Stanfillirenfro, Today, 07:23 AM
|
1 response
2 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
20 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
943 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Comment