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
How do I specify a rising sma for the last 10 bars?
Collapse
X
-
Hello relogical,
Thank you for your post.
As there is not a period input for rising, this information would need to be found with a loop.
For example:
Code:bool isRising = true; for (int i = 0; i<10; i++) { if (!Rising(SMA(19))) { isRising = false; } } if (isRising) { // has been rising for the last 10 bars // execute code }
Chelsea B.NinjaTrader Customer Service
-
Hi relogical,
You are correct, the Rising doesn't work that way. My apologies.
Code:bool isRising = true; for (int i = 0; i<10; i++) { if (SMA(19)[i] <= SMA(19)[i+1]) { isRising = false; } } if (isRising) { // has been rising for the last 10 bars // execute code }
Chelsea B.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHi relogical,
You are correct, the Rising doesn't work that way. My apologies.
Code:bool isRising = true; for (int i = 0; i<10; i++) { if (SMA(19)[i] <= SMA(19)[i+1]) { isRising = false; } } if (isRising) { // has been rising for the last 10 bars // execute code }
I deleted my own post (which is why there appears to be a gap here!) before you posted again, Chelsea, because I'd realised I'd made a mistake myself - relogical was asking about a rising SMA, not just pure price rises - and I didn't have time to correct it.
Although 'Rising' doesn't allow you to specify bar numbers, the function 'Slope' does, as in:
Code:Slope(SMA(19), 1, 0)
Comment
-
Hi arbuthnot,
Ah, couldn't confirm the name after I saw the post was deleted. Thanks for commenting on this, it made me realize the mistake.
The slope would measure between the first and last point, ignoring all points in between.So I guess its a question of granularity.Chelsea B.NinjaTrader Customer Service
Comment
-
Originally posted by ninZa View PostA very important statement must be put:
or
Cheers,
Pi
I would add that, in this specific example, given that the SMA parameter is 19 - as has been used in this thread - must be greater than the number of bars being checked for the 'rising' condition, I'd adjust this to:
if (CurrentBar < 19) return;
Comment
-
Originally posted by arbuthnot View PostThanks, ninZa. The number of times I forgot to put that in a script and so it failed to work defies my capacity for counting!
I would add that, in this specific example, given that the SMA parameter is 19 - as has been used in this thread - must be greater than the number of bars being checked for the 'rising' condition, I'd adjust this to:
if (CurrentBar < 19) return;
* Putting 10 is to make sure you have no errors.
* Putting 19 is to make sure you have no errors + you have a true SMA value
(for CurrentBar < 19, the value of SMA(19) still exists, but it's not accurate)
Thanks.
PiLast edited by ninZa; 12-26-2014, 07:46 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Gerik, 12-21-2023, 08:20 AM
|
15 responses
201 views
0 likes
|
Last Post
by Mindset
Today, 02:06 PM
|
||
Started by visvabalaji, Today, 02:04 PM
|
0 responses
3 views
0 likes
|
Last Post
by visvabalaji
Today, 02:04 PM
|
||
Started by spottysallrite, Today, 11:31 AM
|
6 responses
14 views
0 likes
|
Last Post Today, 01:53 PM | ||
Started by volIQ, Yesterday, 04:28 PM
|
2 responses
16 views
0 likes
|
Last Post
by volIQ
Today, 01:42 PM
|
||
Started by adeelshahzad, Today, 11:49 AM
|
5 responses
16 views
0 likes
|
Last Post Today, 01:27 PM |
Comment