NexusFi: Find Your Edge


Home Menu

 





Logarithm & SMA Issue


Discussion in NinjaTrader

Updated
    1. trending_up 1,949 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Logarithm & SMA Issue

  #1 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722

I'm new to NinjaScript and not the world's greatest programmer so if this is a stupid question please excuse me.

I would like to plot the value of the 21 period SMA of the logarithms of the close values of each bar.

However, the Math.Log function won't let me use a DataSeries value. And the SMA function won't let me use a double value. How can I get around this.

Plot0.Set(SMA(Math.Log(Close[0])), 21)); is a no go.

Here's some simple code I tried to get around it but it didn't work. It should help illustrate the problem though.

double cl = Close[0];
double Lcl = Math.Log(cl);
DSOne.Set(Lcl);
Plot0.Set(SMA(DSOne,
21));

Any help would be greatly appreciated!

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Futures True Range Report
The Elite Circle
Exit Strategy
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



srgtroy View Post
I'm new to NinjaScript and not the world's greatest programmer so if this is a stupid question please excuse me.

I would like to plot the value of the 21 period SMA of the logarithms of the close values of each bar.

However, the Math.Log function won't let me use a DataSeries value. And the SMA function won't let me use a double value. How can I get around this.

Plot0.Set(SMA(Math.Log(Close[0])), 21)); is a no go.

Here's some simple code I tried to get around it but it didn't work. It should help illustrate the problem though.

double cl = Close[0];
double Lcl = Math.Log(cl);
DSOne.Set(Lcl);
Plot0.Set(SMA(DSOne,
21));

Any help would be greatly appreciated!

You need to declare a new DataSeries in the Variables section, for example
 
Code
private DataSeries logPrice;
then initialize this DataSeries object in the Initialize() Section
 
Code
logPrice = new DataSeries(this);
Then you can use it in OnBarUpdate():
 
Code
logPrice.Set(Math.Log(Input[0]));
Value.Set(SMA(logPrice, 21)[0]);
The point is that you need a DataSeries object to be able to apply the SMA; you cannot apply it to a variable of type double.

But what do you want to do with a SMA of the logarithm of price?

You cannot display it on the main panel, and for intraday charts you definitely do not need it.

Reply With Quote
Thanked by:
  #4 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722

Thanks for the help.

I did setup the necessary DataSeries info in the Variables and Initialize sections. That didn't turn out to be the problem. Nevertheless, you're example helped me figure it out. I noticed the first letter in logPrice was not capitalized, so I changed all the first letters I had to small caps and it worked.

Thanks, again.

Started this thread Reply With Quote




Last Updated on June 22, 2011


© 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