Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bar to close at the bottom 30% of it's size

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

    Bar to close at the bottom 30% of it's size

    Hi,
    Chris L told me to debug in a previous post so that's what I'm trying to do right now.
    I'm trying to perform the above action but NT8 seem to mark all the bars all the chart instead of ones which mach the condition of closing either at the bottom 30% for shorts or top 30% for longs.
    Not sure where the issue issue is:

    Code:
     if ((High [1] - Close[1]) > (High[1] - Low[1]) * 0.3); // if the bar closes at bottom 30% of it's range then mark short
    {
    Values[0][1] = (Close[1] + 1 * TickSize); //Place indicator at Close +1
    }
    
    if ((High [1] - Close[1]) < (High[1] - Low[1]) * 0.3); // if the bar closes at top 30% of it's range then mark long
    {
    Values[0][0] = (Close[1] - 1 * TickSize); //Place indicator at Close -1
    }

    #2
    Hello Ludwik,

    There is a semi-colon after your if condition.

    That would mean if the condition is true, do no operation.

    The action block in the curly braces is not attached to your condition because of the semi-colon and will all run.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Ludwik, thanks for the follow up.

      Using Print() is invaluable for debugging and looking at the data and code flow of OnBarUpdate, use it like this:


      if ((High[1] - Close[1]) > (High[1] - Low[1]) * 0.3); // if the bar closes at bottom 30% of it's range then mark short
      {
      Print("Condition True");
      Print("High[1] - Close[1] " + High[1] - Close[1]);
      Print("High[1] - Low[1]) * 0.3 " + High[1] - Low[1]) * 0.3);
      Values[0][1] = (Close[1] + 1 * TickSize); //Place indicator at Close +1
      }

      You will find what is wrong by doing this.

      And the Semi-colon as Chelsea mentioned.

      Kind regards,
      -ChrisL
      Last edited by NinjaTrader_ChrisL; 03-14-2022, 11:10 AM.

      Comment


        #4
        Fixed it all. Thanks for advice

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        331 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        549 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        550 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X