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
Upside/Downside ATR
Collapse
X
-
Hi Chris, don't have anything on the internet for it, but pretty simple -
Upside ATR =20-period daily ATR + Current Low of Day
Downside ATR = Current Hi of Day - 20-period Daily ATR
If there is a gap open:
Upside ATR = 20-period daily ATR + previous close
Downside ATR = previous close - 20-period daily ATR
Will probably try to create myself, just need to read a bit on ninja script. Any guidance on where to start would be appreciated
Comment
-
Hello vstoichk,
I would suggest viewing the AddPlot() page of the Help Guide which demonstrates how plots are added, and how values are assigned to those plots.
AddPlot() - https://ninjatrader.com/support/help...t8/addplot.htm
Documentation for referencing system indicators can be found here - https://ninjatrader.com/support/help...indicators.htm
You may also wish to use the Strategy Builder to generate and learn syntax. If you have not used this tool before, I recommend starting with the resources below. The View Code button can be helpful for learning NinjaScript.
Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE
Conditions examples —https://ninjatrader.com/support/help...on_builder.htm
Actions examples — https://ninjatrader.com/support/help...us/actions.htm
We look forward to assisting.JimNinjaTrader Customer Service
Comment
-
Hi Jim,
Thanks for your post; Below is what I was able to come up with but think I'm missing something. Would you be able to help, not very experienced with this
public class UpsideDownsideATR : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "UpsideDownsideATR";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(Brushes.Indigo, "UpsideATR");
AddPlot(Brushes.Indigo, "DownsideATR");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
double AtrValue = ATR(Closes[1], 20)[0];
double prevClose = Close[1];
double DownsideATR;
double UpsideATR;
if (!Bars.BarsType.IsIntraday) return;
lastDate = currentDate;
currentDate = sessionIterator.GetTradingDay(Time[0]);
if (lastDate != currentDate || currentOpen == double.MinValue)
{
currentHigh = High[0];
currentLow = Low[0];
}
currentHigh = Math.Max(currentHigh, High[0]);
currentLow = Math.Min(currentLow, Low[0]);
if (currentLow > prevClose)
{
UpsideATR = prevClose + AtrValue;
DownsideATR = currentHigh - AtrValue;
else if (currentHigh < prevCLose)
UpsideATR = currentLow + AtrValue;
DownsideATR = prevClose - AtrValue;
else
UpsideATR = currentLow + AtrValue;
DownsideATR = currentHigh - AtrValue;
}
Values[0][0] = UpsideATR[0];
Values[1][0] = DownsideATR [0];
}
Comment
-
Hello vstoichk,
The snippet provided does not compile in its current form.
You will need to mind when curly braces should be open and closed, and you will also need to make sure that any variables that are referenced in the script are also created in the script.
I suggest starting small, and to create a new in indicator using the New Indicator Wizard, (Right click on Indicator's folder in the NinjaScript Editor and select New Indicator). Next you can assign Values[0][0] to a value like Close[0] and add plots following the AddPlot documentation page. Once that is working, I suggest comparing your code to existing indicators to get more familiar with the syntax.
We don't provide programming education services, but you may wish to reference the Programming Concepts page of the NinjaTrader 7 Help Guide and you also may wish to use the Strategy Builder to generate syntax. Using the Strategy Builder can help to see how it generates C# so you can write similar code.
We look forward to assiting.JimNinjaTrader Customer Service
Comment
-
Hi Jim,
With the below code it compiles but doesn't seem to plot anything. Do you have an idea why that might be? Thanks
protected override void OnBarUpdate()
{
if (Low[0] > Close[1])
{
Values[0][0] = Close[1] + ATR(20)[0] ;
Values[1][0] = High[0] - ATR(20)[0] ;
}
else if (High[0]< Close[1])
{
Values[0][0] = Low[0] + ATR(20)[0] ;
Values[1][0] = Close[1] - ATR(20)[0] ;
}
else
{
Values[0][0] = Low[0] + ATR(20)[0] ;
Values[1][0] = High[0] - ATR(20)[0] ;
}
}
Comment
-
Hello vstoichk,
If your indicator is not plotting or if you are running a strategy that automatically disables, please check the log tab of the Control Center for any errors that may have bee thrown by the script.
I can see that you are making a BarsAgo reference of 1 before ensuring the script has processed that many bars, so this would likely be your issue.
Making sure you have enough bars in the data series you are accessing - https://ninjatrader.com/support/help...nough_bars.htm
We look forward to assisting.JimNinjaTrader Customer Service
Comment
-
Originally posted by vstoichk View PostHi Chris, don't have anything on the internet for it, but pretty simple -
Upside ATR =20-period daily ATR + Current Low of Day
Downside ATR = Current Hi of Day - 20-period Daily ATR
If there is a gap open:
Upside ATR = 20-period daily ATR + previous close
Downside ATR = previous close - 20-period daily ATR
Will probably try to create myself, just need to read a bit on ninja script. Any guidance on where to start would be appreciated
ref: https://ninjatraderecosystem.com/use...andelier-stop/ as it was a bit hard to find using the search in the Eco-System. I had to shell out to Google!Last edited by koganam; 03-27-2020, 06:17 PM.
- Likes 1
Comment
-
Hi everyone,
I need to bring an important correction on how the stoploss is calculated.
In many presentations, Charles LeBeau described how to calculate its Chandelier Stoploss.
The parameters are:- Indicator used is the ATR with a period length of 22 periods, (ATR(22 periods));
- Previous highest High for long position (HH(22 periods)) or the lowest Low for short position (LL(22 periods))over the past 22 periods;
- Multiplicator for the ATR with a value of 3. (k)
For long positionStoploss (long) = HH(22 periods) -(k * ATR(22 periods))
if Stoploss (long) > Low(current bar) then Stoploss = Low(current bar)
For short positionStoploss (short) = LL(22 periods) + (k * ATR(22 periods))
if Stoploss (short) < High(current bar) then Stoploss = High(current bar)
The stoploss can be also ratchet, i.e. for long position the stoploss never reduces
and for short position the stoploss never increases.
Good luck.
References:
Stocks & Commodities V.24:11 (28-32)
Alexander Elder "Come into My Trading Room"
Last edited by Dan_D_Trader; 12-28-2023, 11:58 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by TheTradingMantis, 10-31-2017, 03:18 PM
|
5 responses
1,251 views
0 likes
|
Last Post
by TheAngryCube
Today, 04:06 PM
|
||
Started by Padan, Today, 02:02 AM
|
9 responses
23 views
0 likes
|
Last Post Today, 03:27 PM | ||
Started by spottysallrite, Today, 11:31 AM
|
7 responses
22 views
0 likes
|
Last Post Today, 03:26 PM | ||
Started by nandhumca, Today, 03:15 PM
|
1 response
4 views
0 likes
|
Last Post Today, 03:23 PM | ||
Started by PopovDS, 03-11-2024, 12:49 PM
|
3 responses
17 views
0 likes
|
Last Post
by PopovDS
Today, 03:16 PM
|
Comment