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

conditions not working

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

    conditions not working

    Hello,

    Can you please help me?

    I m trying to test a few conditions to enter. But It does not work properly; it seems it only takes one condition and ignores the others, resulting in multiple entries. I cannot spot the error because there is no message.

    Code:
    if(VOLMA(20)[0] < Volumes[0][0] && smaD[0] > smaD[1] && Closes[1][0] > smaD[0]){
                        Draw.VerticalLine(this, CurrentBar.ToString(), 0, Brushes.Green, DashStyleHelper.Solid, 4, true);
                        EnterLong(0, Quantity, "Long");
                    }​

    #2
    Hello Jorge.andres.o,

    The conditions that you have made are using just simple operators of greater or lesser values which would mean as long as the values continue to be greater or lesser the conditions will continue to be true.

    As a first step you could print out the values you are using in the condition so you can see why the condition is true, that would help to highlight what the values are each time a new order is submitted.

    If you are wanting to only place one trade another way would be to add a position check to the condition so it can only submit an order if you are flat. https://ninjatrader.com/support/help...marketposition
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse,

      Thank you for the reply. I have checked and the algorithm is only checking for one condition. In other words, the algorithm triggers if only one condition is true.

      Comment


        #4
        Hello Jorge.andres.o,

        Your if statement has 3 conditions and is using the && AND operator which means all three of those conditions would need to be true for the action to happen. You would need to use a Print in the condition and output the values so you can see what values are used each time the condition is true.

        Code:
        if(VOLMA(20)[0] < Volumes[0][0] && smaD[0] > smaD[1] && Closes[1][0] > smaD[0])
        {
        Print($"{VOLMA(20)[0]} < {Volumes[0][0]} && {smaD[0]} > {smaD[1]} && {Closes[1][0]} > {smaD[0]}");
        }
        JesseNinjaTrader Customer Service

        Comment


          #5
          Jesse,

          I did it and I saw the problem and fixed it.

          Thank you for your help

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,788 views
          0 likes
          Last Post aligator  
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          837 views
          0 likes
          Last Post emuns
          by emuns
           
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,292 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          12 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          11 responses
          62 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X