Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bool inside if condition

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

    Bool inside if condition

    I am working on some strategies and instead of having to recode each entry type with each additional filter, I was hoping to have bools inside the conditiondal if statements such that I can choose to turn certain filters on and off.

    For example:

    if(SMA(33)>SMA(99)
    && if(CCIfilter == true)
    {CCI(6)>0}
    )
    {
    EnterLong("LongTrade");
    }

    Might be a little confusing, but the idea is, in this simple example, I want to be able to make the strategy enter long if the SMA 33 is greater than 99. I also want to have the ability from the strategy menu on my chart (when I apply it to the chart or strategy tester) to set "CCIfilter" to true, and use that as the filter also. I know I could write the if condition twice with the if(CCIFilter == true) above the whole if statement, but I'm working with 6-20 filters and it would be much simple if I could include those bools in one big if statement, all for the same long entrance, "LongTrade".

    Hope this makes some sense... and thank you for any help.

    #2
    if ( SMA(33) > SMA(99) && (CCIfilter == false || CCI(6)>0) )
    {
    EnterLong("LongTrade");
    }

    Comment


      #3
      So I willl set CCIFIlter as a public bool and allow it to be turned to false. If its false, then it will skip over CCI(6)>0 because the CCIfilter == false, so it uses that part of the OR statement. And if CCIFilter == true, it will skip over the CCI == false and use the CCI(6).... Awesome. Thank you much for the help -

      Comment


        #4
        No problem - can you click on the thanks icon so I get my very first one - hoorah!

        Comment


          #5
          Originally posted by jmflukeiii View Post
          So I willl set CCIFIlter as a public bool and allow it to be turned to false. If its false, then it will skip over CCI(6)>0 because the CCIfilter == false, so it uses that part of the OR statement. And if CCIFilter == true, it will skip over the CCI == false and use the CCI(6).... Awesome. Thank you much for the help -
          "short circuit boolean evaluation"

          Comment


            #6
            Originally posted by bayofislands View Post
            No problem - can you click on the thanks icon so I get my very first one - hoorah!

            How did you have any clue as to his request?

            I've been programming since 1987... and I couldn't follow his requirements...

            Comment


              #7
              Started programming in 1983; but don't believe the extra four years prove any benefit in this instance.

              Comment


                #8
                Yes I know my request was not that clear, but I tried my best. I speak English, not computer, unfortunately, and watching me program my strategies would probably make you all want to pull out your eyes in frustration. But I struggle through it, and make stuff that works. Its just probably considered real "ugly" programming.

                Thanks again for the help.

                Comment


                  #9
                  Originally posted by jmflukeiii View Post
                  Yes I know my request was not that clear, but I tried my best. I speak English, not computer, unfortunately, and watching me program my strategies would probably make you all want to pull out your eyes in frustration. But I struggle through it, and make stuff that works. Its just probably considered real "ugly" programming.

                  Thanks again for the help.
                  You would be surprised how many of us started from where you did. Now that you can make stuff work, it actually means that you understand programming logic at some level.

                  You just need to grab a book or two to straighten out your style and you would be very pleased with how much more you will be able to do.

                  Just my $0.02.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by usazencort, Today, 01:16 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post usazencort  
                  Started by kaywai, 09-01-2023, 08:44 PM
                  5 responses
                  603 views
                  0 likes
                  Last Post NinjaTrader_Jason  
                  Started by xiinteractive, 04-09-2024, 08:08 AM
                  6 responses
                  22 views
                  0 likes
                  Last Post xiinteractive  
                  Started by Pattontje, Yesterday, 02:10 PM
                  2 responses
                  21 views
                  0 likes
                  Last Post Pattontje  
                  Started by flybuzz, 04-21-2024, 04:07 PM
                  17 responses
                  230 views
                  0 likes
                  Last Post TradingLoss  
                  Working...
                  X