Logarithm & SMA Issue - futures io
futures io



Logarithm & SMA Issue


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Logarithm & SMA Issue

(login for full post details)
  #1 (permalink)
 srgtroy 
Legendary Market Wizard
Los Angeles, California Republic
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
 
srgtroy's Avatar
 
Posts: 1,936 since Jan 2011
Thanks: 1,375 given, 3,716 received

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 futures io?
For the experts of Metastock
Platforms and Indicators
TradingView help in improving Anchored Vwap
Platforms and Indicators
1 min chart v-shape scan help please
ThinkOrSwim
Experience with AGN (Introducing Broker)
Brokers
TD Sequential for NT or MW?
Platforms and Indicators
 
 
(login for full post details)
  #3 (permalink)
 Fat Tails 
Berlin, Europe
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,858 since Mar 2010
Thanks: 4,238 given, 26,770 received



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
The following user says Thank You to Fat Tails for this post:
 
(login for full post details)
  #4 (permalink)
 srgtroy 
Legendary Market Wizard
Los Angeles, California Republic
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
 
srgtroy's Avatar
 
Posts: 1,936 since Jan 2011
Thanks: 1,375 given, 3,716 received

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


futures io Trading Community Platforms and Indicators NinjaTrader > Logarithm & SMA Issue


Last Updated on June 22, 2011


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Our 12-year anniversary w/ $$,$$$ prizes (check soon)

August
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts