Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SetStopLoss not moving
Collapse
X
-
trail stop not moving
Good day, I have made a simple code for a long strategy with a trailing stop loss under low of closed bar. But StopLoss does not move and every trade ends up at close of the day. Can u offer me advice? Thanks Zdenek
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{ if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, Low[0]-TickSize);
}
else if (Position.MarketPosition == MarketPosition.Long)
{
SetTrailStop("", CalculationMode.Ticks, Low[0], false);
}
// Condition set 1
if (Close[0] > Open[0])
{
EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public bool ControlOne
{
get { return controlOne; }
set { controlOne = value; }
}
#endregion
Comment
-
Hello squashfan,
I am seeing a issue with the setting of the trail:
SetTrailStop("", CalculationMode.Ticks, Low[0], false);
You are setting the trail using ticks but you are supplying a price. The trail is likely trailing the number of ticks away that the low of the price bar is. Meaning if the low of the bar is 1500, the trail is trailing 1500 ticks away from the current price.
Try setting this to a number of ticks. If you want the trail to trail 5 ticks from the current price use:
SetTrailStop("", CalculationMode.Ticks, 5, false);Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bortz, 11-06-2023, 08:04 AM
|
47 responses
1,605 views
0 likes
|
Last Post
by aligator
Today, 07:22 PM
|
||
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
8 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
4 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
13 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
Comment