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!
See more
See less

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!)

    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.

            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Aviram Y, Today, 05:29 AM
            0 responses
            2 views
            0 likes
            Last Post Aviram Y  
            Started by quantismo, 04-17-2024, 05:13 PM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            34 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cls71, Today, 04:45 AM
            0 responses
            6 views
            0 likes
            Last Post cls71
            by cls71
             
            Started by mjairg, 07-20-2023, 11:57 PM
            3 responses
            218 views
            1 like
            Last Post PaulMohn  
            Working...
            X