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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        57 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        78 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        39 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        101 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        61 views
        0 likes
        Last Post PaulMohn  
        Working...
        X