Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Boolean log with integers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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, 09:36 AM.

    #2
    Please try
    if (value == 1 ...
    (2 '=' signs!)
    DierkNinjaTrader Customer Service

    Comment


      #3
      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

      Comment


        #4
        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.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          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?

          Comment


            #6
            Please read the following post for an answer.

            http://www.ninjatrader-support.com/v...ead.php?t=3170
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by frslvr, Today, 04:29 PM
            0 responses
            11 views
            0 likes
            Last Post frslvr
            by frslvr
             
            Started by wjadevries, Today, 04:18 PM
            0 responses
            5 views
            0 likes
            Last Post wjadevries  
            Started by shahabjet1, Today, 03:47 PM
            2 responses
            12 views
            0 likes
            Last Post shahabjet1  
            Started by JTizz, Today, 03:21 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by EB Worx, Today, 02:49 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X