(also trail stop not working but I'm assuming its probably related). Thanks!
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
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.
Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
148 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
5 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
5 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,283 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
Comment