Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with Indicator

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

    Problem with Indicator


    Hi,

    I'm fairly new to NT8 and have issues with the following script.
    1. It basically seem to mark all the bars even if they don't mee dthe conditions
    2. Also it doesn't seem to mark short trades and long only.
    Could you please kindly take a look at the following code and tell me where I've got it wrong?

    Here is what I would like the script to do (meet all the conditions):

    Low of current bar is below previous bar low
    AND
    High of previous bar is above previous bar close
    AND
    High of prev. bar is above 2 bars ago bar high
    AND
    Low of prev bar is above 2 bars ago bar Low
    AND
    Previous bar closes within bottom 30% of it's range

    If all conditions are true than place an indicator 1 tick above the Low of previous bar. This will indicate where to go short and that's where the LMT entry order is going to be placed

    Of course oposite would mark a long trade

    Code:
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "TestSignal";
    Calculate = Calculate.OnPriceChange;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    BarsBack = 2;
    AddPlot(Brushes.Orange, "EntryPlotLong");//This is Values[0][0]
    AddPlot(Brushes.Blue, "EntryPlotShort");//This is Values[1][0]
    }
    else if (State == State.Configure)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    if (CurrentBars[0] < BarsRequiredToPlot)//This just makes sure there are enough bars on the chart. Learn this stff by hitting F1 in NT8 and read help file.
    return;
    
    if ((Low[0] < Low [1]) && (High[1] > Close [1]) && (High[1] > High [2]) && (Low[1] > Low [2]) && ((High [1] - Close[1])) < ((High[1] - Low[1]) * 0.3) )
    Values[0][1] = (Low[1] + 1 * TickSize);
    Values[0][0] = Low[1];
    
    if ((High[0] > High [1]) && (Low[1] < Close [1]) && (Low[1] > Low [2]) && (High[1] < High [2]) && ((High [1] - Close[1])) > ((High[1] - Low[1]) * 0.3) )
    Values[0][1] = (High[1] - 1 * TickSize);
    Values[0][0] = High[1];
    
    }

    #2
    Hi Ludwik, thanks for posting.

    The conditions need brackets to include two lines. e.g.


    Code:
    if ((Low[0] < Low [1]) && (High[1] > Close [1]) && (High[1] > High [2]) && (Low[1] > Low [2]) && ((High [1] - Close[1])) < ((High[1] - Low[1]) * 0.3) )
    {
    
        Values[0][1] = (Low[1] + 1 * TickSize);
        Values[0][0] = Low[1];
    
    }
    
    
    if ((High[0] > High [1]) && (Low[1] < Close [1]) && (Low[1] > Low [2]) && (High[1] < High [2]) && ((High [1] - Close[1])) > ((High[1] - Low[1]) * 0.3) )
    {
    
    
        Values[0][1] = (High[1] - 1 * TickSize);
        Values[0][0] = High[1];
    
    }
    In C# you can exclude the brackets if it's only one line after the if statement. Also, see the Print(); method. This is invaluable for debugging and looking at your OnBarUpdate data and code flow while the script is running:


    Best regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    576 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 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
    553 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X