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
SP500 Strategy: Strategy ends early after adding StopLoss
Collapse
X
-
Originally posted by NinjaTrader_PatrickH View Post
-
Hello KirkHammett,
Thank you for your patience.
This is occurring due to two exits filling on the same bar in historical processing. Essentially, the historical fill processing is seeing that the exits can fill on the same bar thus an Overfill occurs and the entry gets "stuck" in state that it cannot be cancelled.
To avoid this behavior we must use just the SetStopLoss, SetTrailStop, and SetProfitTarget methods without any Exit methods in our Managed code.
Alternatively, you can use the Unmanaged Order Methods in order to work around the Manage Order Methods resulting in such behavior.
Please refer to the Unmanaged Order Methods at the following link: https://ninjatrader.com/support/help...d_approach.htm
We have however submitted this report as a feature request for Historical Fill Processing to avoid such behavior.
Please let me know if you have any questions.
Leave a comment:
-
Hi!
Sorry for the late Reply, was quite busy. First of all, thanks a lot for your responses!
@ Conan
There is no error or anything in the Log.
@ Alan P.
It is a Currency stop, not a Price stop. So, the calculationmode.currency just says: Sell if my loss is 3000$. The price of the S&P is not relevant. With a tick stop the problem still remains.
I checked the Code again. There is a problem between the StopLoss and the the "BarsSinceEntryExecution()". As soon as I delete the BarsSinceEntryExecution code, everything works fine again.
Any other ideas? To me, it looks like a bug.Last edited by KirkHammett; 10-11-2017, 11:09 AM.
Leave a comment:
-
Hello KirkHammett,
You are trying to set a stop loss at a price the SP has never traded, 3000. If you enter long and try to place a buy stop 400% above the market it will be rejected.
Your code,
// SetStopLoss(CalculationMode.Currency, 3000);
Consider using,
SetStopLoss(CalculationMode.Ticks, 300);
Please let us know if you need further assistance.
Leave a comment:
-
Typically, when a strategy stops running prematurely it is because it gets a run-time error. Have you checked the Log tab in the Control Center to see if adding the StopLoss method call somehow creates a run-time error?
Leave a comment:
-
SP500 Strategy: Strategy ends early after adding StopLoss
Hi!
I couldn't find any threads on my following Problem in NT8:
I am back testing a strategy on the S&P500 with daily bars. The timeframe is 1995-2016.
If I don't add a stop loss in the code everything is fine (see screenshot 1). However, as soon as I add a stop loss, the strategy ends during 1999, so it doesn't execute any further trades.
The code is set out below. To add the stop loss just uncomment (delete "//") the stop loss code right before the "Region Properties" pretty much in the end of the code.
Would very much appreciate your help.
Regards
Kirk
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class Test : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Test";
Name = "Test";
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
Capital = 100000;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (this.CurrentBar < this.BarsRequiredToTrade)
return;
double entryPrice = Close[0];
int size = (int) (this.Capital / entryPrice);
if (Close[0] < WMA(14)[0])
{
EnterLong(size, "Buy");
}
if (BarsSinceEntryExecution() > 14)
ExitLong();
// SetStopLoss(CalculationMode.Currency, 3000);
}
#region Properties
[NinjaScriptProperty]
[Range(0, int.MaxValue)]
[Display(ResourceType = typeof(Custom.Resource), Name="Capital", Order=1, GroupName="NinjaScriptStrategyParameters")]
public int Capital
{ get; set; }
#endregion
}
}Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by judysamnt7, 03-13-2023, 09:11 AM
|
4 responses
59 views
0 likes
|
Last Post
by DynamicTest
Today, 08:25 PM
|
||
Started by ScottWalsh, Today, 06:52 PM
|
4 responses
36 views
0 likes
|
Last Post
by ScottWalsh
Today, 07:40 PM
|
||
Started by olisav57, Today, 07:39 PM
|
0 responses
7 views
0 likes
|
Last Post
by olisav57
Today, 07:39 PM
|
||
Started by trilliantrader, Today, 03:01 PM
|
2 responses
21 views
0 likes
|
Last Post
by helpwanted
Today, 07:25 PM
|
||
Started by cre8able, Today, 07:24 PM
|
0 responses
10 views
0 likes
|
Last Post
by cre8able
Today, 07:24 PM
|
Leave a comment: