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
Variable (Int) referenced through a Double
Collapse
X
-
Thanks Jim, I was able to work around this. I added a Math.Round, but I still needed to separate the division out into another double, not really sure why:
double atr = (ATR(Variable2)[0]);
double atr1 = atr/Variable4;
double atr2 = Math.Round(atr1);
int atr3= (int)atr2;
int variable3 = Variable1 + atr3;
double donchianchannel= StdDev(variable3)[0];Last edited by contrlr; 10-05-2017, 03:48 PM.
-
Hello contrlr,
Without the full code, we are only limited to guessing the cause of the issue you are experiencing and if the variables used in calculation have valid values.
Modifying your code to use whole numbers in place of the variables used shows the NinjaScript "works" and does not crash.
Code:double atr = 1 + (ATR(14)[0] / 2); int variable3 = (int)atr; Print(variable3); double donchianchannel= StdDev(variable3)[0];
I've included a link to our forum thread on debugging tips: https://ninjatrader.com/support/foru...ead.php?t=3418
Other development tips can be found here: https://ninjatrader.com/support/foru...splay.php?f=31
Leave a comment:
-
The Variable is for the period, I want to add/subtract from the period based off another indicators value. Min allowed for Variable4 is 1
Leave a comment:
-
Originally posted by contrlr View PostI think I have located the problem. In my actual model there is one more variable, Shown below as Variable 4 (I checked assigning it both double and int). When I go and optimize this variable, I get a crash. However, optimizing Variable1 and Variable2 do not give me a crash, and they give different results.
double atr = Variable1 + (ATR(Variable2)[0] / Variable4);
int variable3 = (int)atr;
double donchianchannel= StdDev(variable3)[0];
I've used this language before, with no problems. The only difference is in this instance it is later conversion to an int.
Leave a comment:
-
I think I have located the problem. In my actual model there is one more variable, Shown below as Variable 4 (I checked assigning it both double and int). When I go and optimize this variable, I get a crash. However, optimizing Variable1 and Variable2 do not give me a crash, and they give different results.
double atr = Variable1 + (ATR(Variable2)[0] / Variable4);
int variable3 = (int)atr;
double donchianchannel= StdDev(variable3)[0];
I've used this language before, with no problems. The only difference is in this instance it is later conversion to an int.
Leave a comment:
-
Hello contrlr,
Thanks for your reply.
Type casting (which you have already demonstrated and I have copied below) is what you are looking for. I've added a semicolon to end the line which I believe was merely a typo while copying your code.
double atr = Variable1 + ATR(Variable2)[0];
int variable3 = (int)atr;
Leave a comment:
-
ATR and StdDev were examples used strictly for name space. I am not concerned with int rounding or calculating to the nearest whole number, but more so that my variable for StdDev could be altered based on the value of another indicators value.
I understand I could recode each base indicator to accept double values, but for my purposes, there are multiple indicators I'd like to use to evaluate for alteration of my Variable1, and a simple nested conversion would save time.
So I am looking to combine my Variable1 (Int) with the value of some Indicator (Double) into one referable Int for use in the base Indicator (ex StdDev)
Leave a comment:
-
Hello contrlr,
Welcome to the forums!
You are correct in that you can cast a double as an int to have the value converted and assigned to a variable of type int. There will be data loss, however, as integers do not contain decimal values.
I believe there may be some confusion behind what you are trying to accomplish.
double atr = ATR(Variable2)[0];
double stddev = StdDev(Variable1 + atr)[0];
What period are you expecting to use for StdDev() when you say you "would like my Int for StdDev (Variable1) to be adjusted for the value returned for ATR?"
The syntax for these methods are publicly available in our help guide. I will provide a link to the ATR syntax and the StdDev() syntax for your reference. We also have some documentation that covers C# syntax used with NinjaScripts that may be worth reviewing.
ATR - https://ninjatrader.com/support/help..._range_atr.htm
StdDev - https://ninjatrader.com/support/help...ion_stddev.htm
Programming Concepts - https://ninjatrader.com/support/help...g_concepts.htm
I look forward to being of further assistance.
Leave a comment:
-
Variable (Int) referenced through a Double
Having trouble with the following code example. In this example, I would like my Int for StdDev (Variable1) to be adjusted for the value returned for ATR
double atr = ATR(Variable2)[0];
double stddev = StdDev(Variable1 + atr)[0];
---
I have tried converting to an int as such, but it gives me a circular reference and crashes:
double atr = Variable1 + ATR(Variable2)[0];
int variable3 = (int)atr
double donchianchannel= StdDev(variable3)[0];Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by andrewtrades, Today, 04:57 PM
|
1 response
9 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
6 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
8 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Leave a comment: