NexusFi: Find Your Edge


Home Menu

 





ATRpercentage


Discussion in NinjaTrader

Updated
    1. trending_up 2,244 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 3 attachments




 
Search this Thread

ATRpercentage

  #1 (permalink)
 Fried Tomato 
Vancouver
 
Experience: Intermediate
Platform: NinjaTrader
Trading: GLD
Posts: 4 since Apr 2012
Thanks Given: 1
Thanks Received: 1

Hi guys

I am not a programmer (although am learning) and I got an ATRpercentage indicator from this site. The ATR percentage calculates the ATR as a percentage of price. The indicator program plots both ATR and ATR percentage and therefore cannot be used in strategies when I am comparing ATR to ATRpercentage, because to ATR is part of the ATRpercentage program.

Anyone know how to remove the ATR "piece" of programming from the indicator so that only the ATR percentage will be outputted.

The following is a snippet of code. I have played around with it, but notice that if I get the ATRpercentage to be plotted only, then it is incorrect. I have no idea why??

protected override void OnBarUpdate()
{
if (CurrentBar == 0)
{
Value.Set(High[0] - Low[0]);
}
else
{
double trueRange = High[0] - Low[0];
trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
double atr =(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period));
Value.Set(atr);

double price = Close[0]; // the median price is used. You can replace Median with Close
double atrp = atr / price * 100;
ATRperc.Set(atrp);

}

Any help would be fantastic.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Increase in trading performance by 75%
The Elite Circle
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
26 thanks
Tao te Trade: way of the WLD
23 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #3 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 387


You could just comment out the code not needed...

There are 2 ways to do comments

// does just this line, everything after the two slashes is a comment

/*
is how you do a range of comment, everything between the first slash-star up to the star-slash is a comment
*/


The Value.Set is what is drawing the ATR value

you could put // infront of them... I added them below....



Fried Tomato View Post
Hi guys

I am not a programmer (although am learning) and I got an ATRpercentage indicator from this site. The ATR percentage calculates the ATR as a percentage of price. The indicator program plots both ATR and ATR percentage and therefore cannot be used in strategies when I am comparing ATR to ATRpercentage, because to ATR is part of the ATRpercentage program.

Anyone know how to remove the ATR "piece" of programming from the indicator so that only the ATR percentage will be outputted.

The following is a snippet of code. I have played around with it, but notice that if I get the ATRpercentage to be plotted only, then it is incorrect. I have no idea why??

protected override void OnBarUpdate()
{
if (CurrentBar == 0)
{
// commented out Value.Set(High[0] - Low[0]);
}
else
{
double trueRange = High[0] - Low[0];
trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1])));
double atr =(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period));
// commented out Value.Set(atr);

double price = Close[0]; // the median price is used. You can replace Median with Close
double atrp = atr / price * 100;
ATRperc.Set(atrp);

}

Any help would be fantastic.


Reply With Quote
Thanked by:
  #4 (permalink)
 Fried Tomato 
Vancouver
 
Experience: Intermediate
Platform: NinjaTrader
Trading: GLD
Posts: 4 since Apr 2012
Thanks Given: 1
Thanks Received: 1

Thanks Tulanch. I had already tried this and that is when the ATRpercentage value is plotted incorrectly. I have no idea why? Any other ideas? I was wondering whether it had something to do with the code that is in the "Properties" section of the coding. (I am quite familiar with writing strategies, but indicators are very new to me - and like I say I have no coding background).

Started this thread Reply With Quote
  #5 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 387

If you commented exacly the lines listed and it still is not working, there is other code invovled... can you post the entire .cs file?

Note: there are times if you access data using references other than [0], for example Close[1], you may find it necessary to use

if(CurrentBar < 1)
return;

but your code looked to me like it handled that...

Another thing, there are times it helps to remove the indie under devlelopmenet from the chart, and re-add it rather than just doing a refreash (F5)

Here is another good resource... when I first started out with indies, I found the NT help docs very useful... search for "indicator basic concepts" click on the "Educational Resources" link and then on the "Developing Indicators" link.
I know its rather basic, but it does explain things well.

The following code was generated by the NT wizard... just click on create new a indicator and check the overlay box, then press the next buttons till you get the code to display...

Note the name "Plot0" is how this example adds a plot draw item that you are having issues with, notice how "Plot0" is referenced in 3 places.... initialize, onbarupdate and in the properties..


/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0")); // <<<<here
Overlay = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Plot0.Set(Close[0]); // <<<<here
}

#region Properties

// //////////////////////////////////////////////
// here is where it is defined if you wil
// how it is brought to the indicator dialog for setting related items such as color or sytle from the UI
// //////////////////////////////////////////////

[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}

Reply With Quote
Thanked by:
  #6 (permalink)
 Fried Tomato 
Vancouver
 
Experience: Intermediate
Platform: NinjaTrader
Trading: GLD
Posts: 4 since Apr 2012
Thanks Given: 1
Thanks Received: 1

Hi Tulanch, thanks for references, still fiddling with this thing I just can't seem to wrap my head around these indicators. I see in the properties section there are references to data one bar ago [1] you mentioned [1] can effect the if (CurrentBar . . . ) line, does that include when it is in this properties section??

I have attached the file, as you can see it is not much code. I am also trying to compare to other code that works (specifically a Bollinger Bandwidth indicator). I see a huge difference in how it is written and I think adding to my confusion.

Any additional thoughts??

Attached Files
Elite Membership required to download: ATRpercentage.zip
Started this thread Reply With Quote
  #7 (permalink)
 tulanch 
Salt Lake City, UT
 
Experience: Intermediate
Platform: SC, NT, MT
Broker: AMP
Trading: NQ ES YM Bonds
Posts: 265 since Mar 2010
Thanks Given: 50
Thanks Received: 387

units....that is the issue here....if you will, you're trying to draw miles and inches at the same time....

the units for the percentage range between 0 and 100

the units for ATR are based on the ticksize and bar range (high-low)

With the 6E the units currently are around 1.2938 and a bar that has 4 ticks higher would be 1.2942, so these units would be significantly smaller than the % values. ( for example 0.0004)

so this indie was actually working as designed, just the view scale was not set to pick up all the drawn items.

In the attached version I commented out the Value.set lines using //tulanch

the Value.set is weird.. sort of a short cut/hack... but the since first plot is named "ATR" (look inside initialize) and there is already an ATR data series ( the indicator provided by NT you could call from inside this indicator), I would guess if you tried to use ATR.Set the compiler would complain with some compiler error.

If the first plot was named "ATRvalues" instead of "ATR" the Value.set could more correctly and clearly be
ATRvalues.set


To see what is being drawn you need to adjust the view scale... you know how to use the little F icon/button on the upper right side of a panel when the view can be adjusted?

I just ran this indie against the 6E and the percentage came out to 90, but the lines drawn are at 50 max ... so I then zoomed out using the y axis drag feature... eventually the purple line became flat and I could see all the horizontal lines too

hope this make sense...

Attached Files
Elite Membership required to download: ATRpercentage.zip
Reply With Quote
Thanked by:
  #8 (permalink)
 Fried Tomato 
Vancouver
 
Experience: Intermediate
Platform: NinjaTrader
Trading: GLD
Posts: 4 since Apr 2012
Thanks Given: 1
Thanks Received: 1

Yep, I agree the indicator was working exactly as it was designed, just I wanted to separate the two lines ie the ATRpercentage and the ATR because I wanted that ATRpercentage to output a number so that I could run a strategy or even output it to the Market Analyzer. I though it was necessary to remove the ATR from the plot BUT . . .

I deleted the version I had and imported the one you attached, but I prefer the "units" used before (it is how I have manually been calculating this stuff) so I changed it a little, so that the Value.Set(atr) was once again included ie removed"//", but I left the rest and the only thing I see differently is the line "//Value.Set(High[0] - Low[0])" ie you essentially removed it. The plot obvioulsy is the same as before, with the two lines, but for some reason (????) it computes the ATRpercentage (same value as before) and successfully outputs to the market analyzer and also is able to use it in my strategy when I run the strategy analyzer. Like I say I have no idea why but I am really

I spent most of yesterday going over those lessons on Ninjatrader that you recommended. I will get there . . . just like I did manage to learn the Strategy Analyzer stuff. But still seems a little like gibberish at the mo'.

Thanks for all your help!!

To anyone who wants the indicator as I am presently using it I am including it here.

And for anyone who wonders what it can be used for. It is great on daily and weekly charts to indicate when to trade systems that are dependent on high volatility. When the ATRpercentage > ATR (I like 10 period) it indicates high volatility.

Attached Files
Elite Membership required to download: ATRpercentage.zip
Started this thread Reply With Quote
Thanked by:




Last Updated on October 29, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts