Thanks.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Using Indicator as Stop Loss
Collapse
X
-
Hello Trader17,
Thanks for the post.
In the Stops and Targets section of the Strategy Builder you can click the "set" button and get the value of any indicator in the platform for the price of the stop/target. The MIN or MAX indicator could be used to get the high or low values from X bars ago.
Please let me know if I can assist further.
- Likes 1
-
Hello Trader17,
Thanks for the reply.
You would need to unlock your code and program this. The strategy builder will only allow for one stop/target option so switching back and forth for long/short orders will need to be done in a fashion similar to the following pseudocode:
Please let me know if you have any questions.Code:if(long) { SetStopLoss(CalculationMode.Price, MAX(5)); } else if(short) { SetStopLoss(CalculationMode.Price, MIN(5)); }
- Likes 1
Comment
-
I tried this in a strategy and I am getting error message while compiling that "long" and "short" are invalid expressions. Why? Below is the code I inserted.Originally posted by NinjaTrader_ChrisL View PostHello Trader17,
Thanks for the reply.
You would need to unlock your code and program this. The strategy builder will only allow for one stop/target option so switching back and forth for long/short orders will need to be done in a fashion similar to the following pseudocode:
Please let me know if you have any questions.Code:if(long) { SetStopLoss(CalculationMode.Price, MAX(5)); } else if(short) { SetStopLoss(CalculationMode.Price, MIN(5)); }
Thank you.
if(long)
{
SetStopLoss(CalculationMode.Price, MIN(5));
}
else if(short)
{
SetStopLoss(CalculationMode.Price, MAX(5));
}
Comment
-
Hello Trader17,
Thank you for the reply.
My example was in "pseudocode". A complete C# implementation would look something like the attached script. I used OnPositionUpdate() to know the moment the strategy becomes long/short and save the boolean variables in case I needed them at a later time.
Please let me know if I can assist further.
Attached Files
- Likes 1
Comment
-
Originally posted by NinjaTrader_ChrisL View PostHello Trader17,
Thank you for the reply.
My example was in "pseudocode". A complete C# implementation would look something like the attached script. I used OnPositionUpdate() to know the moment the strategy becomes long/short and save the boolean variables in case I needed them at a later time.
Please let me know if I can assist further.
Thank you very much. MIN or MAX returns the lowest or highest price. What if I want to subtract/add a tick or two to this value? Is what I did below correct or needs to be done differently?
Thanks.
LongPosition = true; //Use LongPosition elsewhere if needed
SetStopLoss(CalculationMode.Price, MIN(5)[0] -1,tick);
Comment
-
Thank you very much. Also, will SetTrailStop work with MIN and MAX? So instead of using MIN and MAX to place the fixed stop at the start of the trade I want it to move dynamically on each bar close. Can this be done in Strategy Builder? If not, would be a nice feature to have.
Thank you very much.Last edited by Trader17; 10-24-2018, 11:50 AM.
Comment
-
I did not use the bool but did it this way instead. Is it correct?Originally posted by NinjaTrader_ChrisL View PostHello Trader17,
Thank you for the reply.
My example was in "pseudocode". A complete C# implementation would look something like the attached script. I used OnPositionUpdate() to know the moment the strategy becomes long/short and save the boolean variables in case I needed them at a later time.
Please let me know if I can assist further.
protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
{
if (position.MarketPosition == MarketPosition.Long)
{
LongPosition = true; //Use LongPosition elsewhere if needed
SetStopLoss(CalculationMode.Price, MIN(5)[0]);
}
else if (position.MarketPosition == MarketPosition.Short)
{
ShortPosition = true; //Use ShortPosition elsewhere if needed
SetStopLoss(CalculationMode.Price, MAX(5)[0]);
}
}
Thank you.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
55 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
132 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment