Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Auto trailing stop for a stragegy
Collapse
X
-
Auto trailing stop for a stragegy
Hi, I am attempting to set up a trailing stop for a strategy, it appears that I need to enter some code to do this, I am not a programmer, all I want to do have a 35 pip trailing stop following the current price of the pair that is being traded, does anyone out there have a coded solution?Tags: None
-
Strazzman, to add a simple trailing stop to your strategy takes just one line of code in the Initialize() section:
Code:protected override void Initialize() { SetTrailStop(CalculationMode.Ticks, 35); }
AustinNinjaTrader Customer Service
-
Trailing stop question
Thanks for the reply Austin, however now I am wondering where the initialize section you are referring to is found?. Have done tools > edit ninjascript > strategy > selected strategy > ok.
Now do I unlock code on the opening page or next onto the stops and targets page?
Comment
-
Hi,
Extending a little bit the topic:
1) How can I make the stop loss to jump to breakeven + 1 tick when the price reaches a certain trigger value (so many ticks above/below the entry price) in the direction of my trade?
2) Then, when the price reaches a 2nd trriger, the stop should become a trailing stop (by a certain no of ticks/amount/%).
3) Then, when the price reaches a 3rd trigger, the trailing stop should tighten.
I would like to do all this in the Strategy Wizard, without un-locking the code. This is important.
Thx.
Comment
-
BBzDan,
Unfortunately you can only do what you want through unlocked code with the programming techniques demonstrated in this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=3222Josh P.NinjaTrader Customer Service
Comment
-
Breakeven and 2-tier trailing stops
Hello,
I've been trying to develop a breakeven and 2-tier trailing stop strategy, as mentioned in a previous post, using various suggestions for developing the code found in the forum and in the manual (as suggested), but there is something wrong with my code. I've done 2 versions, one using if and one using switch. Both behave in the same way:- they place correctly the stop and target. However,
- the stop doesn't move to breakeven + 2 ticks (as programmed), but jumps above this, to something else
- the stop remains there, it doesn't move/trail anymore, even if the price moves in the direction of the trade well beyond the targets set to trigger the movement of 1st trailing stop and the 2nd, tightened trailing stop.
The codes have some extra parameters/variables not used in the program, just ignore them.
As mentioned, I did look in the manual, and at the SamplePriceModification.cs, and other examples found in the forum, trying to follow what's there.
Thank you,
Dan
Comment
-
Comment
-
OK, made some progress: managed to bring the stop loss to breakeven + n ticks, and make it trail a little. Now, I have a problem with the trailing condition.
1st question:
Is it possible to get the current price, or the price of last trade, instead of Bid or Ask, and use it in an if statement? I've been trying something like this:- To bring the stop loss to BE + n ticks
&& initialBreakEven == 0.000)
{
initialBreakEven = Position.AvgPrice + plusBreakEven * TickSize;
bid = GetCurrentBid();
SetStopLoss("Long", CalculationMode.Price,initialBreakEven, false);
}
which is OK.
2. To start trailing, once at BE+n and after the trailing trigger is reached (trailing==1, which is a flag showing the trailing trigger was reached):
if (GetCurrentBid() > bid
&& trailing == 1)
{
trail = trail + trailStep * TickSize;
trail = trail == 0 ? initialBreakEven + trailStep * TickSize : trail + trailStep * TickSize;
SetStopLoss("Long", CalculationMode.Price, trail, false);
}
This doesn't work well, because it uses bid price instead of actual last price. Also, I do not want to compare it with the high, or close of the bar, (as I use range bars), but with the price of the previous tick. Thus, how do I get the current price, and the price of the last tick (the previous price)?
2nd question:
Is it possible to convert a stop loss to a trailing stop (after it reached BE+n ticks)? If YES, how?
Thank you.
Comment
-
Dan, great progress - for the last price just use for example Close[0] in combination with CalculateOnBarClose = false.
It's not possible to convert it - you continue to adjust the stop loss level as the trade moves into more and more profit, thus you code in at what steps you like to move it by calling SetStopLoss again to adjust the placed value.
You may want to check into our sharing where some good scripts have been published on implmenting a trail stop logic.
BertrandNinjaTrader Customer Service
Comment
-
Bertrand,
Thx for comments and for quick reply.
Regarding Close(0) in combination with CalculateOnBarClose = false, the problem is that the entry conditions are based on calculating the indicator I use at the close of the bar, not tick-by-tick. Is it possible to have two regions, one with CalculateOnBarClose=true (for entry conditions) and one with ...=false, for stop trailing? If yes, how?
I'll check the file sharing section, see what's there, thx.
Comment
-
You can have two regions. Use CalculateOnBarClose = false and then filter the regions where you want it to behave like true with this:
Code:if (FirstTickOfBar)
Josh P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by adolfosanz44, Today, 01:53 PM
|
0 responses
6 views
0 likes
|
Last Post
by adolfosanz44
Today, 01:53 PM
|
||
Started by alphatango, 09-16-2024, 02:09 PM
|
2 responses
30 views
0 likes
|
Last Post
by alphatango
Today, 01:51 PM
|
||
Started by zehua, Today, 11:03 AM
|
1 response
11 views
0 likes
|
Last Post
by TradeSaber
Today, 01:21 PM
|
||
Started by Estherwanger, Today, 01:04 PM
|
1 response
9 views
0 likes
|
Last Post Today, 01:06 PM | ||
Started by martinsedward28, Today, 11:43 AM
|
0 responses
7 views
0 likes
|
Last Post Today, 11:43 AM |
Comment