Thanks.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.Chris L.NinjaTrader Customer Service
- 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:
Code:if(long) { SetStopLoss(CalculationMode.Price, MAX(5)); } else if(short) { SetStopLoss(CalculationMode.Price, MIN(5)); }
Chris L.NinjaTrader Customer Service
- Likes 1
Comment
-
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:
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 FilesChris L.NinjaTrader Customer Service
- 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
-
Hello Trader17,
Thanks for the reply.
You can add or subtract ticks like so:
SetStopLoss(CalculationMode.Price, MIN(5)[0] -TickSize,tick);
To subtract two ticks:
SetStopLoss(CalculationMode.Price, MIN(5)[0] -(TickSize*2),tick);
Please let me know if you have any questions.Chris L.NinjaTrader Customer Service
- Likes 1
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
-
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 TraderG23, 12-08-2023, 07:56 AM
|
9 responses
382 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
||
Started by oviejo, Today, 12:28 AM
|
0 responses
1 view
0 likes
|
Last Post
by oviejo
Today, 12:28 AM
|
||
Started by pechtri, 06-22-2023, 02:31 AM
|
10 responses
125 views
0 likes
|
Last Post Today, 12:03 AM | ||
Started by judysamnt7, 03-13-2023, 09:11 AM
|
4 responses
59 views
0 likes
|
Last Post
by DynamicTest
Yesterday, 08:25 PM
|
||
Started by ScottWalsh, Yesterday, 06:52 PM
|
4 responses
36 views
0 likes
|
Last Post
by ScottWalsh
Yesterday, 07:40 PM
|
Comment