NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-03-2008, 08:34 AM   #1
jeremymgp
Member
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
Default Boolean log with integers

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.
jeremymgp is offline  
Reply With Quote
Old 01-03-2008, 08:44 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Please try
if (value == 1 ...
(2 '=' signs!)
NinjaTrader_Dierk is offline  
Reply With Quote
Old 01-03-2008, 10:24 PM   #3
jeremymgp
Member
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
Default

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
jeremymgp is offline  
Reply With Quote
Old 01-03-2008, 11:44 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

You want to do:
Code:
if (Falling(SMA(60))
     // Do something
In order to access previous returns on this you could try saving the values in some temporary bools.

For your code:
Code:
if (SMA(200)[0] > SMA(200)[1] && SMA(200)[1] < SMA(200)[2])
{
     // Do something
}
I don't see why it wouldn't work. If the "do something" isn't executing then it is simply the condition hasn't evaluated to true. For your "do something" just place a Print line to see what is going on. Also print out the values of SMA(200)[0], [1], and [2] before the if so you can manually check it out.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-04-2008, 07:23 AM   #5
jeremymgp
Member
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
jeremymgp is offline  
Reply With Quote
Old 01-04-2008, 07:36 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Please read the following post for an answer.

http://www.ninjatrader-support.com/v...ead.php?t=3170
NinjaTrader_Ray is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 04:24 AM.