![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
I have a problem with an indicator I'm working on. Basically, my indicator formula looks like following : Myindicator.Set(varA*varB) where varA and varB are double types(very basic). The thing is when I'm running it , it does not plot anything. I've checked the output window to point out the problem and it appears that it comes from my varA which is always equal to 0. I think the problem comes from the type of varA .Since the formula looks like Constant/(Period*(Period-1)*(Period+1)), it obviously returns 0.0 when Period is set to 20 for example. The correct value is 0.00000xxx. So I tried to change the value type to decimal in order to get the precision I need but when I do it, I'm forced to change the type of varB (also to decimal) and of course my indicator won't compile since Dataseries only holds double values. I don't know what to do anymore. Could anyone help me ? By the way ,why can't I print the values in the output window with my variables defined as decimals ? |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
kuroro13,
You should be able to print them. Print(var1.ToString()); Please check your variables through these prints first to see what values they are really at. Would have imagined doubles to work with your values to begin with. If you are using such a small decimal value you may consider normalizing it by removing some zeros.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you Josh for your answer.
I've checked all the code through the prints and i still have the same problem. Here is the first part of the code : public class filtre1 : Indicator { #region Variables // Wizard generated variables private int length = 20; // Default setting for Length // User defined variables (add any user defined variables below) private double f18=0.00; private double f20; private int f48=0; private int f38=0; #endregion /// <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.Red), PlotStyle.Line, "Plot0")); Add(new Line(Color.FromKnownColor(KnownColor.ControlDark), 0, "Zero")); CalculateOnBarClose = true; Overlay = false; PriceTypeSupported = false; arr0 = new double [301]; arr1 = new double [301]; arr2 = new int [301]; arr3 = new int [301]; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (f38 == 0) { f38=1; f40=0; if ((Length-1)>=2) { f30=Length-1; } else {f30=2;} f48=f30+1; f10=Close[0]; f18=12/(f48*(f48-1)*(f48+1)); Print(f18.ToString()); double f20=(f48+1)*0.5; Print(f20.ToString()); } When Length is set to 20 the output window shows me : 0 10.5 my f18 is always equal to 0 . I tried to normalize it by multipying it by a 1000 factor but then it returns me 1. I'm a little bit lost there.... |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
You could try this: f18=12.0/(f48*(f48-1)*(f48+1));
|
|
|
|
|
|
#5 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you Ralph !!!
It works smoothly now...but now you should give me a little explanation on why ?!!! :-) |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Hi kuroro13,
12 is an integer and if divided by a double, the double is converted to integer obviously, so your result is: 12/7980.0 -> 0. 12.0 is a double and so is the result: 12.0/7980.0 -> 0.0015 Regards Ralph |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| See more decimals in SMA | jmreal | Charting | 3 | 08-06-2008 07:05 AM |
| Use the rounded value instead of the exact value with decimals? | Ninja B | Automated Trading | 12 | 07-10-2008 02:06 PM |
| How to not display decimals | LG | General Programming | 4 | 04-18-2008 02:04 PM |
| FX Entry Decimals | trader2be | Connecting | 2 | 12-13-2007 09:24 PM |
| fractions/decimals | Gar | Miscellaneous Support | 3 | 05-24-2005 03:07 AM |