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 SalmaTrader, 07-07-2026, 10:26 PM
|
0 responses
50 views
0 likes
|
Last Post
by SalmaTrader
07-07-2026, 10:26 PM
|
||
|
Started by CarlTrading, 07-05-2026, 01:16 PM
|
0 responses
22 views
0 likes
|
Last Post
by CarlTrading
07-05-2026, 01:16 PM
|
||
|
Started by CaptainJack, 06-17-2026, 10:32 AM
|
0 responses
16 views
0 likes
|
Last Post
by CaptainJack
06-17-2026, 10:32 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:15 AM
|
0 responses
22 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:15 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:06 AM
|
0 responses
23 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:06 AM
|

Comment