Announcement

Collapse
No announcement yet.

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

    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]}");
        }

        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 NullPointStrategies, Today, 05:17 AM
          0 responses
          44 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          65 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X