Example: I have opened long position on 20$ with stop loss on 15$ and take profit at 35$., and i would like to move the stop loss to 20$ and to stay there when the price reaches 30$. Thanks in advace
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 movement
Collapse
X
-
Stop loss movement
Hi, I was wondering if you could help me with a strategy that I am making and I can not move the stop loss.
Example: I have opened long position on 20$ with stop loss on 15$ and take profit at 35$., and i would like to move the stop loss to 20$ and to stay there when the price reaches 30$. Thanks in advaceTags: None
-
Hello Dragan,
Thank you for your response.
You can find an example of modifying the price of a stop loss or profit target at the following link: http://www.ninjatrader.com/support/f...ead.php?t=3222
Please let me know if I may be of further assistance.
Comment
-
I have simmilar question. Bellow is the code of my strategy. It is simple long entry
with stop loss and profit target. But I want if the price moves 50 ticks above the enter price, the stop to be moved to breakeven. Can you please tell me
how should I incorporate the following lines in my code:
// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + 40 * TickSize)
THIS IS MY CODE:
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class MyCustomStrategy : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
SetStopLoss("", CalculationMode.Ticks, 40, false);
SetProfitTarget("", CalculationMode.Ticks, 150);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (ToTime(Time[0]) > ToTime(8, 10, 0)
&& ToTime(Time[0]) < ToTime(8, 31, 0)
&& CurrentDayOHLC().CurrentClose[0] > PriorDayOHLC().PriorHigh[0])
{
EnterLong(DefaultQuantity, "");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
}
}
Comment
-
Hi flexi,
Are you creating this with the Strategy Wizard?
If so, the stop loss cannot be moved when using the Wizard. Instead you will need to use an exit order.
Attached is an example of how to do this with the wizard.
Also, here is the flow of what happens in this example.
Condition set 1 checks that the position is flat
If true:
Variable0 is set to the trigger price
Variable1 is the to initial stop price
Variable2 is set to correct the trigger price one bar after entry
Variable3 is set to 0 to reset the trigger so that the breakeven only happens once
Condition set 2 checks that the position is long and Variable2 is 0.
If true:
Variable0 is corrected to the entry price plus the trigger amount
Condition set 3 checks that the position is long, that the close price has met the trigger price, and that Variable2 is set to 0 and ready to trigger.
Once these are true:
Variable1 is set to the Position.AvgPrice which is the entry point
Variable3 is set to 1 so the breakeven is not triggered again
DrawDiamond is called to mark the chart where the breakeven was triggered
Condition set 4 checks that we are in a long position
If true:
ExitLongStop is called to set the stop to the current value of Variable1 which is set in condition set 1 and then condition set 2Attached FilesChelsea B.NinjaTrader Customer Service
Comment
-
That worked great. Thanks.
I also put another user defined input for profit taking. But in order to work
I must associate some new user variables with it. Since I run out of
user variables in the wizard (there are only 9), I unlock the code and tried to put
Variable10 and Variable 11 manualy but it is returning error:
The name''Variable10'' does not exist in the current context.
Can you please tell me is there a way to insert Variable10 and Variable11 and more in the
BreakEvenWizardExample you posted?
I neede them not only for my profit takng input but for other modifications as well.
Comment
-
Hi flexi, for adding more user inputs in we have a step by step guide that would take you through that process with the open code file, please check into - http://www.ninjatrader.com/support/f...ead.php?t=5782BertrandNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
|
55 responses
5,448 views
0 likes
|
Last Post
by BartMan
Today, 03:25 PM
|
||
Started by DawnTreader, 05-08-2024, 05:58 PM
|
16 responses
52 views
0 likes
|
Last Post
by DawnTreader
Today, 03:20 PM
|
||
Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
|
15 responses
60 views
0 likes
|
Last Post Today, 03:19 PM | ||
Started by kevinenergy, Yesterday, 12:01 PM
|
8 responses
27 views
0 likes
|
Last Post
by kevinenergy
Today, 03:16 PM
|
||
Started by nightstalker, Today, 01:32 PM
|
1 response
10 views
0 likes
|
Last Post Today, 02:54 PM |
Comment