(also trail stop not working but I'm assuming its probably related). Thanks!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Stops NOT Working
Collapse
X
-
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "X";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.ByStrategyPosition;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
LT1 = 1;
LT2 = 1;
LT3 = 5;
ST1 = 1;
ST2 = 1;
ST3 = 5;
Stop = 1;
}
else if (State == State.Configure)
{
AddDataSeries("GC 06-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
}
else if (State == State.DataLoaded)
{
SMA1 = SMA(Close, 50);
SMA1.Plots[0].Brush = Brushes.Goldenrod;
AddChartIndicator(SMA1);
SetProfitTarget("", CalculationMode.Ticks, LT1);
SetProfitTarget("", CalculationMode.Ticks, LT2);
SetProfitTarget("", CalculationMode.Ticks, ST1);
SetProfitTarget("", CalculationMode.Ticks, ST2);
SetStopLoss("", CalculationMode.Price, Stop, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 3)
return;
// LONG ENTER
if ("hidden code" && Position.MarketPosition == MarketPosition.Flat)
{
EnterLongStopMarket(High[1] + (1 * TickSize),"R3 LE1");
EnterLongStopMarket(High[1] + (1 * TickSize),"R3 LE2");
EnterLongStopMarket(High[1] + (1 * TickSize),"R3 LE3");
}
// LONG EXIT
if (Position.MarketPosition == MarketPosition.Long)
{
//ExitLong(Convert.ToInt32(DefaultQuantity), @"Lx1", "");
SetProfitTarget("R3 LE1",CalculationMode.Ticks,LT1);
SetProfitTarget("R3 LE2",CalculationMode.Ticks,LT2);
SetProfitTarget("R3 LE3",CalculationMode.Ticks,LT3);
SetStopLoss("R3 LE1", CalculationMode.Price,Low[1]-1*TickSize,false);
SetStopLoss("R3 LE2", CalculationMode.Price,Low[1]-1*TickSize,false);
SetStopLoss("R3 LE3", CalculationMode.Price,Low[1]-1*TickSize,false);
// SetTrailStop("R3 LE1",CalculationMode.Ticks,Stop,false);
// SetTrailStop("R3 LE2",CalculationMode.Ticks,Stop,false);
// SetTrailStop("R3 LE3",CalculationMode.Ticks,Stop,false);
}
// SHORT ENTER
if ("hidden code" && Position.MarketPosition == MarketPosition.Flat)
{
EnterShortStopMarket(Low[1] - (1 * TickSize),"R3 SE1");
EnterShortStopMarket(Low[1] - (1 * TickSize),"R3 SE2");
EnterShortStopMarket(Low[1] - (1 * TickSize),"R3 SE3");
}
// SHORT EXIT
if (Position.MarketPosition == MarketPosition.Short)
{
SetProfitTarget("R3 SE1",CalculationMode.Ticks,ST1);
SetProfitTarget("R3 SE2",CalculationMode.Ticks,ST2);
SetProfitTarget("R3 SE3",CalculationMode.Ticks,ST3);
SetStopLoss("R3 SE1", CalculationMode.Price,High[1]+1*TickSize,false);
SetStopLoss("R3 SE2", CalculationMode.Price,High[1]+1*TickSize,false);
SetStopLoss("R3 SE3", CalculationMode.Price,High[1]+1*TickSize,false);
// SetTrailStop("R3 SE1",CalculationMode.Ticks,Stop,false);
// SetTrailStop("R3 SE2",CalculationMode.Ticks,Stop,false);
// SetTrailStop("R3 SE3",CalculationMode.Ticks,Stop,false);
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="LT1", Order=1, GroupName="Parameters")]
public int LT1
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="LT2", Order=2, GroupName="Parameters")]
public int LT2
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="LT3", Order=3, GroupName="Parameters")]
public int LT3
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ST1", Order=4, GroupName="Parameters")]
public int ST1
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ST2", Order=5, GroupName="Parameters")]
public int ST2
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ST3", Order=6, GroupName="Parameters")]
public int ST3
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Stop", Order=7, GroupName="Parameters")]
public int Stop
{ get; set; }
#endregion
}
}
Comment
-
Understood. I'm not trying to get free work from you guys. However, I think I narrowed down the issue and if you could steer me in the right direction I would appreciate that.
Here's the Error I keep getting across several strategies. However I have no idea how it got this number (which isnt even close to the market)??
Is this an entry, exit, order management issue?? thank you
Comment
-
This happens across all strategies. I read it might be a OCO unique identifier issue? Does that sound right. Below is the strategy's OCO column where Entry & Exit have same OCO ID.... Does this like a OCO unique ID issue? If so, is there a template I can use to update my script? Thank you!
Comment
-
Hello elcowen,
Thanks for your reply.
The error message in your post #7 is advising that your strategy code tried place a sell stop (market) or sell stop limit order above the current price and the message identifies the specific order at sell stop market at 1761.6. You will need to debug your strategy to find out why it is placing the order incorrectly. It may be a matter of checking the current price before placing the order to ensure it is appropriate.
The OCO column shows what orders are tied together. If you expand out the name colum, the two orders (in each example) are the Profit Target and Stop loss which should be OCO tied and would be expected to have the same number.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
557 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment