If you want to see how the strategy would behave, you probably need to run it using the simulation engine.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
ATR Profit Target
Collapse
X
-
I am not sure that I understand what you mean there. What are you expecting to see on the chart? Where? Are we talking about a backtest or a live test using Market Replay, or the simulation engine?Originally posted by zachj View Post
If you want to see how the strategy would behave, you probably need to run it using the simulation engine.
-
There are a few things wrong with your code, as you have removed important code that you had before. A SetStopLoss() must exist before an entry in order for the entry to be coupled to the StopLoss. If the entry does not initially have an associated StopLoss, there is nothing to adjust. That is why we always put an initial SetStopLoss() statement in the Initialize() method.Originally posted by zachj View PostIn the Strategy Analyzer, Im backtesting the Dow Mini, YM. It is not hitting any targets and then doing a trailing stop. Im wanting it to hit a target of the ATR*2 and then do a trail stop of 1ATR after it hits the target. Its not working.
While your strategy is not really that complex, it is rather ambitious for a first strategy, which I assume that this probably is. The first thing to do is to simplify your code to exactly one condition for entry and exit. It is also evident that there is a certain lack of understanding as to the flow and structure of a strategy.
Before you continue, I would suggest that you go through the tutorials in the documentation, on how to build a strategy. What you have written is missing too many basic features. A forum is just not a very effective tutorial method unless you already know the basics.Last edited by koganam; 01-20-2012, 08:53 PM.
Comment
-
I really don't think that this is all that complicated and no offense but I think that maybe you do not know how to do it yourself and im getting lead way off course here. I appreciate you trying to help though. This profitTarget item and the SetStopLoss are commands I should not even be using. I should be using a SetTrailStop and a SetProfitTarget. The SetProfitTarget will not exit me out of the position if I have a SetTrailStop as this will cancel out the profit target once its reached and will trail the position. I will try to post the code once I figure it out.
Comment
-
Interesting. If that is your way of psychologically challenging me to write the code for you instead of helping you to write it for yourself, I decline.Originally posted by zachj View PostI really don't think that this is all that complicated and no offense but I think that maybe you do not know how to do it yourself and im getting lead way off course here. I appreciate you trying to help though. This profitTarget item and the SetStopLoss are commands I should not even be using. I should be using a SetTrailStop and a SetProfitTarget. The SetProfitTarget will not exit me out of the position if I have a SetTrailStop as this will cancel out the profit target once its reached and will trail the position. I will try to post the code once I figure it out.
I accept your insult that I do not know how to write code. Please feel free to place me on your ignore list. You have just been placed on mine, so unfortunately, I shall not see any further insults that you may choose to cast.
Comment
-
I would appreciate it if I receive assistance directly from Ninja Trader, I plan on paying a hefty fee for this software and I need to know that it will perform the operations that I need it to. This should be very simple to do and so far Im not seeing any threads where this has been succesfully done or any info that clearly illustrates how to do this or that this software is able to do as I requested in original post. Most people on here are not code masters. There should be examples in the guide on how to do such a simple exercise of hitting a target and trailing after a target is hit. Why isn't this sort of common setup available in the strategy wizard.Last edited by zachj; 01-20-2012, 11:12 PM.
Comment
-
zachj, I'm not sure why the tone in this thread developed the way it has - koganam is a very knowledgable and helpful forum member and we always appreciate his input here. If you're coding skills are basic it would be best to give our tutorials a run first to understand the framework and strucutre you're working in :
The next thing would be taking a look at the reference sample I had posted a few posts back -
This would be a good basic start towads the script you wish to create - it shows how to set a stop loss and then move the stop loss by code conditions to provide the trailing aspect.
One word of caution - you cannot work with SetStopLoss and SetTrailStop on the same position and to scale out of your trade you would need to scale in first so you could then later refer to different signal names / parts of your overall position, we do have a sample for this technique as well :
All the best,
Comment
-
ATR targets in strategies
Hope this helps you. I have asked the same question and have now incorporated a target calculated from ATR on entry into my strategy because of the information available from the excellent support on this site.
and
Ben.Last edited by stocktraderbmp; 01-21-2012, 08:39 AM.
Comment
-
Yes! Bertrand. What you have above, this is the key! This code hits a target and then sets a new stop. Just had to make sure I set the default stop and target ticks way out to a large# in the variable section to make sure they don't interfere. Thank you much Sir.Originally posted by NinjaTrader_Bertrand View Post
The next thing would be taking a look at the reference sample I had posted a few posts back -
This would be a good basic start towads the script you wish to create - it shows how to set a stop loss and then move the stop loss by code conditions to provide the trailing aspect.
All the best,
I did want to replace the "SetStopLoss" with "SetTrailStop" and its compiling but it doesn't seem to be working properly. Any idea if there is anything wrong below in the code snippet that I've replaced with SetTrailStop?
Code:if (Position.MarketPosition == MarketPosition.Flat) {SetTrailStop(CalculationMode.Ticks, stoplossticks);} (Position.MarketPosition == MarketPosition.Long) {// Once the price is greater than entry price+2*ATR, set stop loss to recent bar close - 1ATR if (Close[0] > Position.AvgPrice + (ATR(14)[0]) * 2) {SetTrailStop(CalculationMode.Ticks, Close[0] - ATR(14)[0]); }
Comment
-
You are welcome, glad you could proceed with your envisioned script.
The issue is the SetTrailStop call by ticks and your inputted / calculated tick value, namely the
Close[0] - ATR(14)[0]
This value will be way to high to ever activate the trail part, as it's literally especting a tick value to trail by then and not a price value to work with as in your case > if you call SetStopLoss with this calculated value in OnBarUpdate() this would create the dynamic trail aspect by ATR you seek.
Comment
-
Oh ok i gotcha.
Just a couple other minor things...
On the strategy analyzer chart when doing a backtest, is there any way to have it print the target when its hit? Right now it only prints the buys and the stoploss.
Also in this code line......SetStopLoss(CalculationMode.Price, Close[0] - ATR(14)[0]); instead of using the close of the last completed bar is it possible to have it calculate the stop loss based on the actual live price?
Comment
-
Oh ya Calc on bar close to false, yes should have know that.Originally posted by NinjaTrader_Bertrand View PostHi zachj, so you're saying you never see your target execute at all in the backtest?
In realtime trading your script could run with CalculateOnBarClose = False, which means the Close[0] price is the price of the last tick seen and not the close price of the last completed bar.
http://www.ninjatrader.com/support/h...onbarclose.htm
And yes the target does execute as it should but just curious when im backtesting if I can get it to show target @ price on the strategy analyzer chart screen like it shows for buy price and stoploss price. Just so that I can see and analyze it quicker visually.
thank you
Comment
-
Oh its not exiting though, once it hits the target it triggers the stoploss. I would just like to see it print when the target is hit. Code snippet is below.
Code:(Position.MarketPosition == MarketPosition.Long) {// Once the price is greater than entry price+2*ATR, set stop loss to recent bar close - 1ATR if (Close[0] > Position.AvgPrice + (ATR(14)[0]) * 2) {SetStopLoss(CalculationMode.Ticks, Close[0] - ATR(14)[0]); }
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
666 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
377 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
110 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
580 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment