Announcement
Collapse
No announcement yet.
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
-
Thanks.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:
I've found this quite helpful on occasion.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
-
Thanks, ninZa. The number of times I forgot to put that in a script and so it failed to work defies my capacity for counting!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
-
You may want to make it 19, but that's not necessaryOriginally 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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
579 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment