Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Orders Not fired
Collapse
X
-
Orders Not fired
I've created a simple strategy to start with for testing, I've developed using StategyBuilder, however the orders are not working. I debugged with the print messages and the conditions seem to be fine. Appreciate any feedback. Attached is the code.Tags: None
-
Actually - i found this message in output window. Any idea what this means?
Strategy 'RSIMoxie/-1': An order has been ignored since the stop price ‘20’ near the bar stamped ‘9/30/2021 7:45:00 PM’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
Comment
-
Hello ark321,
Thank you for your reply.
You're not seeing orders being taken because you're placing the orders really far from the current price. Here's what you have for your entry orders:
EnterShortStopMarket(Convert.ToInt32(DefaultQuanti ty), 20, @"EnterShort");
EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), 20, @"Long");
Keep in mind the Value for the order is a price, so no matter what price the instrument the strategy is running on currently has, it's submitting these at a price of 20. If you've got something like say, the ES 12-21, that's currently trading around 4342 as I type this. Those orders would be placed waaaaaay down at 20. If it's a short stop market order that'll work and you'll get an order placed there, but since stop market orders can't be placed on the wrong side of the market (buy stop market orders must be above the market, short stop orders below), you'll get an error if it tries to place a buy stop market order there.
I would suggest instead, if you're looking to place the orders near enough to the current price that they may get hit, to set the price of these orders to the current close at the time of the order submission with a tick offset of + or - a few ticks. Please see the video below:
World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.
Now, if you want the order to stay alive even if it's not filled after 1 bar, you can take a look at the BreakEvenBuilder example on this post for how you can achieve that:
Please let us know if we may be of further assistance to you.
Comment
-
Thanks for the video explanation. Really appreciate it.
I meant to put a stop for 20 ticks from the entry price. I will review the BreakEvenBuilder.
Is there any example Strategy code for the below: I want to trade 2 contracts. Both will be setup a fixed stop (20 ticks), 1st contract will be closed after 20 ticks and 2nd contract closed using some logic (like cross over of MA). Appreciate any reference code.
Comment
-
Hello ark321,
Thank you for your reply.
You could take a look at this ScaleOutBuilderExample script I'm attaching below - basically, you'd want to make 2 simulaneous entries, but give them each a unique Signal Name, like, say, Entry1 and Entry2. You can then use this signal name in the From Entry Signal field that stops/targets/exit orders have to connect that closing order to the associated entry, so it will only close that particular order.
Further information on Signal Names may be found in our help guide here:
Please let us know if we may be of further assistance to you.Attached Files
Comment
-
this is helpful. Thank you.
Two other questions (1) Is there a way to move the stop loss on the 2nd entry to breakeven(entry price) once the entry 1 is closed (2) For 2nd target, if I want to exit the trade based on some logic where do i define the logic (say for example - close the trade when MA crosses over)
Comment
-
Hello ark321,
Thank you for your reply.
You would need to use exit orders to add breakeven functionality to a Strategy Builder script. Here's a link to another forum post with a couple of examples of breakeven behavior with the Builder:
As for exiting the second target based on conditions, you'd also need to use an exit order in a new set on the Conditions and Actions screen.
Please let us know if we may be of further assistance to you.
Comment
-
This is the sample strategy I'm building to make sure I understand the build logic.
If the DefaultQuantity is '1' - it fires two long or two short based on the logic. Both with a fixed stop loss of 20 ticks. 1st order gets closed at a profit of 20 ticks and the 2nd order will be closed when the EMA logic meets. Does this make sense? Also, is the DefaultQuantity concept makes sense? if I set 1, since I'm calling the entries twice it will get doubled.
namespace NinjaTrader.NinjaScript.Strategies
{
public class Test1 : Strategy
{
private EMA EMA1;
private EMA EMA2;
private EMA EMA3;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Test1";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 2;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.High;
OrderFillResolutionType = BarsPeriodType.Minute;
OrderFillResolutionValue = 1;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 27;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
_ADX = 22;
_StopLoss = 20;
_ProfitTarget = 20;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 15);
AddDataSeries(Data.BarsPeriodType.Minute, 30);
AddDataSeries(Data.BarsPeriodType.Minute, 60);
AddDataSeries(Data.BarsPeriodType.Minute, 1);
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(Close, 14);
EMA2 = EMA(Close, 21);
EMA3 = EMA(Close, 9);
SetStopLoss(@"entry1", CalculationMode.Ticks, _StopLoss, false);
SetProfitTarget(@"entry1", CalculationMode.Ticks, _ProfitTarget);
SetStopLoss(@"entry2", CalculationMode.Ticks, _StopLoss, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if (EMA1[0] >= EMA2[0])
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"entry1");
EnterLong(Convert.ToInt32(DefaultQuantity), @"entry2");
}
// Set 2
if (EMA1[0] <= EMA2[0])
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"entry1");
EnterShort(Convert.ToInt32(DefaultQuantity), @"entry2");
}
// Set 3
if (EMA3[0] >= EMA2[0])
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"exitLong2", @"entry2");
}
// Set 4
if (EMA3[0] <= EMA2[0])
{
ExitShort(Convert.ToInt32(DefaultQuantity), @"exitShort2", @"entry2");
}
}
#region Properties
[NinjaScriptProperty]
[Range(20, int.MaxValue)]
[Display(Name="_ADX", Description="ADX Value", Order=1, GroupName="Parameters")]
public int _ADX
{ get; set; }
[NinjaScriptProperty]
[Range(10, int.MaxValue)]
[Display(Name="_StopLoss", Description="Stop loss value", Order=2, GroupName="Parameters")]
public int _StopLoss
{ get; set; }
[NinjaScriptProperty]
[Range(10, int.MaxValue)]
[Display(Name="_ProfitTarget", Description="Profit Target", Order=3, GroupName="Parameters")]
public int _ProfitTarget
{ get; set; }
#endregion
}
}
Comment
-
Hello ark321,
Thank you for your reply.
As is, you'll get a warning that you can't use High Order Fill Resolution with this script since you have multiple data series added. You're not actually using those in the script at the current time so I've commented those out in the version below.
To get the results I believe you're expecting, you should set Entry Handling to Unique Entries and Entries Per Direction to 1. If you have set 1 for the default quantity, one quantity of each entry will be submitted.
Going further though, I would suggest adding a position check to your conditions for entry so that if one of the two is exited, it will not enter again until your position returns to flat. I've added this in the attached script as well.
I'd test this and see if this is what you're looking for.
Please let us know if we may be of further assistance to you.Attached Files
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
56 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
133 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment