![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
|
Hello,
I'd like to find a work around for doing Boolean operations on integers. When a short-term and long-term SMA are rising, I'm doing something. However sometimes when the longer-term SMA turns to rising, the short term SMA is in the middle of rising. I don't want signals where the short-term SMA is in the middle of a rise when the longterm SMA turns to rise. I only want full signals where the short-term SMA turns to rise while the longterm SMA is rising also. So I'm creating logic that: - checks if the longterm SMA has turned to rise & the shortterm SMA is NOT rising at the turn: - sets a value to 1 For example: if (SMA(200)[0] > SMA(200)[1] && SMA(200)[1] < SMA(200)[2] && SMA(14)[0] < SMA(14)[1]) { value = 1; } if (value = 1 && SMA(14)[0] > SMA(14)[1] && SMA(14)[1] < SMA(14)[2]) { do something; } Value stays at 1 until longterm SMA changes direction, then recalculate. ---- Trouble is I can't use "value = 1" with "&&" Boolean operators. With some languages just changing the "&&" to "&" works, but this didn't happen either. Is there any way I can work around using Boolean logic with integers? Thanks, Jeremy
Last edited by jeremymgp; 01-03-2008 at 08:36 AM.
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Please try
if (value == 1 ... (2 '=' signs!)
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for your patience with my learning curve.
I'm trying to detect SMA turning points - what's the best way to do this? I'm using the logic: "if current bar[0] > previous bar[1] && previous bar[1] < previous bar [2]" then it's a turn. So far no luck. I've tried using Rising()/Falling() but am unable to access previous values, eg. if (Falling(SMA(60)[1])) doesn't work. I've also tried logic such as: if (SMA(200)[0] > SMA(200)[1] && SMA(200)[1] < SMA(200)[2]) { do something } but the "do something" doesn't happen. Thanks for your help, Jeremy |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
You want to do:
Code:
if (Falling(SMA(60))
// Do something
For your code: Code:
if (SMA(200)[0] > SMA(200)[1] && SMA(200)[1] < SMA(200)[2])
{
// Do something
}
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
|
It's the barsAgo that seems to be doing it. I'm setting background color as follows:
if (SMA(100)[0] > SMA(200)[0]) { BackColor = Color.PaleGreen; } and green bars of bgd color appear throughout the chart. As soon as I change it to: if (SMA(100)[0] > SMA(200)[1]) however, there's nothing. How can I apply logic using barsAgo to a whole chart, not just the present bar? |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|