private void ManageOrders1()
{
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, 2);
LongStopPrice = 0; //initial long stop as small as possible.
}
// If a long position is open, allow for stop loss modification
else if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Math.Max(LongStopPrice, Position.AvgPrice + target1))
{
if (Close[0] >= Position.AvgPrice + target1) SetStopLoss(CalculationMode.Price, Close[0]-(Close[0] - Position.AvgPrice));
LongStopPrice = Close[0]; //update the StopPrice
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Programming manual trailstop
Collapse
X
-
Programming manual trailstop
hi since we cant use setstoploss and trailstop together, i'm trying to program the logic from trailerstop
for some reason the stoploss does not update as price goes up. it only sets the stoploss once and then forgets about itCode:Tags: None
-
i added print, and it works.
here is the code that i am working with right now, i think it's working but i dont think it's the most efficient way.
what do you think?
Code:private double LongStopPrice = 0; private double diff = 0; private void ManageOrders1() { if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculationMode.Ticks, 2); LongStopPrice = 0; //initial long stop as small as possible. } // If a long position is open, allow for stop loss modification else if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Math.Max(LongStopPrice, Position.AvgPrice + target1)) { if (Close[0] >= Position.AvgPrice + target1) SetStopLoss(CalculationMode.Price, Close[0]-((Close[0] - Position.AvgPrice)-diff)); LongStopPrice = Close[0]; //update the StopPrice diff = Close[0]-(target1+Position.AvgPrice); //update the StopPrice } }
Comment
-
Hi calhawk01,
Thanks for your reply.
May have the entire script (with the print statement) so that I may test this on my end?
To export your script do the following:- Click File -> Utilities -> Export NinjaScript
- Enter a unique name for the file in the value for 'File name:'
- Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
- Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message
By default your exported file will be in the following location:- (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>
Below is a link to the help guide on Exporting NinjaScripts.
Once exported please attach the exported file to your reply. If you would like to keep the code private between us, please send the script to support[at]ninjatrader[dot]com. In the body of the email write Attn: Chelsea #880778.
I look forward to receiving the file.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
634 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment