Ive code a break even condition if the strategy is in profit buy 12 ticks. The code by itself work and does the job but as soon as i set stop loss and the profit target ,its not doing is job. is there a way to set the profit and stop loss values so all the condition are working Heres some screenshot. Thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SetStopLoss, SetProfitTarget
Collapse
X
-
SetStopLoss, SetProfitTarget
Hey guys, maybe a newb quastion but ive been coding for 2 weeks and came across this issues and cant figure it out.
Ive code a break even condition if the strategy is in profit buy 12 ticks. The code by itself work and does the job but as soon as i set stop loss and the profit target ,its not doing is job. is there a way to set the profit and stop loss values so all the condition are working Heres some screenshot. Thanks
4 PhotosLast edited by NinjaTrader_BrandonH; 04-02-2023, 02:39 PM.Tags: None
-
Hello Nicars,
Thanks for your post.
Set methods and Exit methods should not be used within the same NinjaScript as this goes against the Managed Approach Internal Order Handling Rules linked below.
Internal Order Handling Rules: https://ninjatrader.com/support/help...rnalOrderHandl ingRulesThatReduceUnwantedPositions
To accomplish your goal, the Set methods should be removed from the script and only Exit methods should be used to place profit target and stop loss orders.
See the educational examples on this forum thread that was shared by my colleague Chelsea. The example scripts demonstrate strategy builder breakeven and trailing stop in the strategy builder here: https://ninjatrader.com/support/foru...der#post806596
You could compare the example script to your script to see where differences might be and where logic could be modified in your script.
Please let me know if I may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Thank you. I manage to code the ExitLongLimit with this:
if ((Position.MarketPosition == MarketPosition.Long)
&& (Close[0] >= (Position.AveragePrice + (0 * TickSize)) ))
{
ExitLongLimit(Convert.ToInt32(PositionSize), (Position.AveragePrice + (TP1 * TickSize)) , "@TP1", @"Long1");
}
{
But, using the same logic the ExitShortLimit dont work
// Profit Target Short
if ((Position.MarketPosition == MarketPosition.Short)
&& (Close[0] <= (Position.AveragePrice + (0 * TickSize)) ))
{
ExitShortLimit(Convert.ToInt32(PositionSize), (Position.AveragePrice + (TP1 * TickSize)) , @"TP1", @"Short1");
}
{
Comment
-
i tried the negative offset like this and its not working.Originally posted by QuantKey_Bruce View PostShouldn't your limit be BELOW your Position.AveragePrice for a short? You are adding TP1 * TickSize so unless that TP1 is negative, it's backward. That may not be the only problem, but that is a problem.
ExitShortLimit(Convert.ToInt32(PositionSize), (Position.AveragePrice - (TP1 * TickSize)) , @"TP1", @"Short1");
Thanks for your help
Comment
-
Well, I would imagine for NinjaTrader support to help when they are online they're going to want you to post your corrected code so they can make better suggestions since we don't know what all else has changed in the interim.
As a suggestion, paste in the code in a code block reply (the "#" button on your forum post editor) or attach the .cs file rather than posting a screenshot - when you do that you're essentially asking them to type all that in so they can run it and try to help which is a high bar.
Comment
-
Very helpful, thank you sir!Originally posted by QuantKey_Bruce View PostWell, I would imagine for NinjaTrader support to help when they are online they're going to want you to post your corrected code so they can make better suggestions since we don't know what all else has changed in the interim.
As a suggestion, paste in the code in a code block reply (the "#" button on your forum post editor) or attach the .cs file rather than posting a screenshot - when you do that you're essentially asking them to type all that in so they can run it and try to help which is a high bar.
Comment
-
Hello Nicars,
Thanks for your notes.
I understand that you removed the Set methods in the script.
"i tried the negative offset like this and its not working."
When you mention it is not working, please provide a brief description of what exactly is not working so I may accurately assist.
Do you see error messages pop up or appear in the Log tab of the Control Center? If so, what do the errors report?
Have you added debugging prints to your script to understand how your logic is behaving?
If not, please add debugging prints to the script to see how your logic is processing and how the script is placing orders.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
Let us know if we may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
52 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
48 views
0 likes
|
Last Post
|

Comment