I have a market entry (EnterShort(DefaultQuantity, "S") how can I set a Stop Loss at execution price?
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
Stop loss at execution price
Collapse
X
-
Hello dieci,
Thanks for your reply.
You can use the SetStopLoss() method that will immediately deploy as soon as the entry order is filled. You can specify the number of ticks away from the entry price to place the stop.
You can use this two different ways, one is statically meaning the same stop amount is applied to every entry (you can specify x amount of ticks, the method will add or subtract based on the entry direction). the other way is to use dynamically in case you want to change the values. Please see the help guide for the method and its usage: https://ninjatrader.com/support/help...etstoploss.htm
Paul H.NinjaTrader Customer Service
Comment
-
Hi,
there's something I can't understand...here a snippet
protected override void OnStateChange()
{
if (State == State.Configure)
{
if (sOp == "L")
SetStopLoss("L", CalculationMode.Price, iSL, false);
else if (sOp == "S")
SetStopLoss("S", CalculationMode.Price, iSL, false);
}
}
protected override void OnBarUpdate()
{
if (Close[0] >= High[1])
{
sOp = "L";
entryOrderL = EnterLong(DefaultQuantity,"L");
}
else if (Close[0] <= Low[1])
}
sOp = "S";
entryOrderS = EnterShort(DefaultQuantity,"S");
{
I can see the Long or Short entry but I can't see any Stop Loss among my Orders
If I give the same entry name both Long and Short and write only one SetStopLoss referring to that name I can see again my entry, now I can see the Stop Loss among my Orders, state Accepted but it's never executed
What's the issue??
Last edited by dieci; 06-22-2020, 02:23 PM.
Comment
-
Hello dieci,
Thanks for your reply.
That is setting the stop loss to be 1 specific price level (L or S, likely chosen by the user) in state.Configure which is called when the user applies the strategy.
I would not think that would be a good practice unless it is a one time use only as that same stop would be used on all entries.
Paul H.NinjaTrader Customer Service
Comment
-
So I should edit my code like this, right?
iSL = 5;
protected override void OnBarUpdate()
{
if (Close[0] >= High[1])
{
sOp = "L";
entryOrderL = EnterLong(DefaultQuantity,"L");
SetStopLoss("L", CalculationMode.Price, iSL, false);
}
else if (Close[0] <= Low[1])
}
sOp = "S";
entryOrderS = EnterShort(DefaultQuantity,"S");
SetStopLoss("S", CalculationMode.Price, iSL, false);
{
Comment
-
Hello dieci ,
Thanks for your reply.
With reference to your post #3 & #5, I would suggest something like:
Protected override void OnStateChange()
{
if (State == State.Configure)
{
if (sOp == "L")
SetStopLoss("L", CalculationMode.Ticks, iSL, false); // provides a fixed stop-loss of iSL ticks below the Long entry price
else if (sOp == "S")
SetStopLoss("S", CalculationMode.Ticks, iSL, false); // provides a fixed stop-loss of iSL ticks above short entry price
}
}
protected override void OnBarUpdate()
{
if (Close[0] >= High[1])
{
sOp = "L";
entryOrderL = EnterLong(DefaultQuantity,"L");
}
else if (Close[0] <= Low[1])
{
sOp = "S";
entryOrderS = EnterShort(DefaultQuantity,"S");
}
Paul H.NinjaTrader Customer Service
Comment
-
Hello dieci ,
Thanks for your reply.
To clarify: In the "Set" methods, CalculationMode is used to describe the value that is associated with the stop and should not be confused with the calculate setting of the strategy.
If you intend to use the same stop level for all your entries (a static stop) , it is better to set the stop in State.Configure. By using the stop with CalculateMode.Ticks you are setting a specific number of ticks from the entry that the stop will be placed.
The purpose of a stop loss is to exit your position when the price goes against your intended direction. It does not prevent entries if that is what you are asking.
Please take the time to review the "managed approach" which provides an overview and links to the methods: https://ninjatrader.com/support/help...d_approach.htm
Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
4 responses
23 views
0 likes
|
Last Post Today, 08:19 AM | ||
Started by Brevo, Today, 01:45 AM
|
1 response
14 views
0 likes
|
Last Post Today, 08:14 AM | ||
Started by rjbtrade1, 11-30-2023, 04:38 PM
|
2 responses
73 views
0 likes
|
Last Post
by DavidHP
Today, 08:12 AM
|
||
Started by suroot, 04-10-2017, 02:18 AM
|
5 responses
3,021 views
0 likes
|
Last Post Today, 08:11 AM | ||
Started by Stanfillirenfro, Today, 07:23 AM
|
1 response
7 views
0 likes
|
Last Post Today, 07:37 AM |
Comment