if (Close[0] >= Position.AvgPrice + trail)
{
SetTrailStop("", CalculationMode.Ticks, trail/.25, false);
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
trailstop after a certain threshold
Collapse
X
-
trailstop after a certain threshold
hi how come the above is not working as scripted. i want to set a trailstop when price goes above a certain threshold. but what it's doing is setting a trailstop as soon as i enter a position.Code:Tags: None
-
It's set in OBCOriginally posted by NinjaTrader_PatrickH View PostHello calhawk01,
Thank you for your post.
Is the SetTrailStop() set in the Initialize() method? What determines the "trail" value?
I look forward to your response.
User sets the value for trail... For example "4"
If close > Avgprice+4.... Start the trailstop
Comment
-
nOOriginally posted by NinjaTrader_PatrickH View PostHello calhawk01,
Thank you for your response.
Are there any Set() methods in the Initalize() method?
Code:protected override void Initialize() { CalculateOnBarClose = true; TraceOrders = true; }Code:protected override void OnBarUpdate() { double total = profit+trigger; if ((Position.MarketPosition == MarketPosition.Flat) &&.....................................) { EnterLongLimit(..................); SetProfitTarget("", CalculationMode.Ticks, total/.25); } if (Close[0] >= Position.AvgPrice + trail) { SetTrailStop("", CalculationMode.Ticks, trail/.25, false); } if (ToTime(Time[0]) == ToTime(15, 57, 0)) { ExitLong("", ""); } }
Comment
-
That is the issue with the Set() methods. Once used, they exist for all time. That is why they need to be reset when you go flat.Originally posted by calhawk01 View PostnO
Code:protected override void Initialize() { CalculateOnBarClose = true; TraceOrders = true; }Code:protected override void OnBarUpdate() { double total = profit+trigger; if ((Position.MarketPosition == MarketPosition.Flat) &&.....................................) { EnterLongLimit(..................); SetProfitTarget("", CalculationMode.Ticks, total/.25); } if (Close[0] >= Position.AvgPrice + trail) { SetTrailStop("", CalculationMode.Ticks, trail/.25, false); } if (ToTime(Time[0]) == ToTime(15, 57, 0)) { ExitLong("", ""); } }
Comment
-
-
Hello calhawk01,
Thank you for your response.
An example of this is the following:
The above code was taken form the following reference sample: http://www.ninjatrader.com/support/f...ead.php?t=3222Code:// Resets the stop loss to the original value when all positions are closed if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculationMode.Ticks, stoplossticks); }
Please let me know if I may be of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 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
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment