{ // Resets the stop loss to the original value when all positions are closed if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculationMode.Ticks, 25); } // If a long position is open, allow for stop loss modification to breakeven if (Position.MarketPosition == MarketPosition.Long) { // Once the price is greater than entry price, plus 5 ticks, readjust Stop if (Close[0] > Position.AvgPrice + 5 * TickSize) { SetStopLoss("LONG", CalculationMode.Price, Close[0] - 20 * TickSize, false); } } // If a short position is open, allow for stop loss modification to breakeven if (Position.MarketPosition == MarketPosition.Short) { // // Once the price is less than entry price, less 5 ticks, readjust Stop if (Close[0] < Position.AvgPrice - 5 * TickSize) { SetStopLoss("SHORT", CalculationMode.Price, Close[0] + 20 * TickSize, false); } }
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
StopLoss Order being rejected
Collapse
X
-
StopLoss Order being rejected
Hello, I'm running a crude oil futures strategy with StopLosses that enable at Buy/Sell and then adjust to the market price after a certain threshold. However, when this order enables, I receive the error "Sell Order Stop Price must be below last trade price ExchangeRejectionCode = 2060". I'm wondering how it's creating sell stops and buy stops below / above the market given the script I have included:
Code:Tags: None
-
Hello,
I was unable to capture the cause of the issue while testing on my end, but I did find a way to resolve the issue. You can get around this by switching the calculation mode to CalculationMode.Ticks, then entering "20" for the value. This will place the stop loss in the same place at which you are currently attempting to place it, but it will go about it in a different way.
Please let me know if I can assist further.Dave I.NinjaTrader Product Management
-
I believe I resolved it by decoupling it from EntryOrder handling and saying SetStopLoss(CalculationMode.Price, High[HighestBar(High, 2)] - 20) for both my buys and sells, this seems to the trick. Now, I changed if (Close[0] > Position.AvgPrice + 5 * TickSize) to if (GetCurrentAsk() > (Position.AvgPrice + 5 * TickSize))
However, once the Ask is above my average price by 5 ticks, the stop does not change. Any thoughts?
Comment
-
If COBC is being set to true in the script, then it is possible that it is overriding the setting in the Strategy Window. This would cause the script to run its calculations on each incoming tick, while in backtesting they would run at the close of each bar. This could certainly explain the differences you are seeing.Dave I.NinjaTrader Product Management
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by samish18, 04-17-2024, 08:57 AM
|
16 responses
56 views
0 likes
|
Last Post
by samish18
Today, 03:30 PM
|
||
Started by arvidvanstaey, Today, 02:19 PM
|
3 responses
10 views
0 likes
|
Last Post Today, 04:08 PM | ||
Started by jordanq2, Today, 03:10 PM
|
2 responses
8 views
0 likes
|
Last Post
by jordanq2
Today, 03:23 PM
|
||
Started by traderqz, Today, 12:06 AM
|
10 responses
18 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
||
Started by algospoke, 04-17-2024, 06:40 PM
|
5 responses
47 views
0 likes
|
Last Post Today, 02:36 PM |
Comment