Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is wrong with this code for Supply and demand

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

    What is wrong with this code for Supply and demand

    I am trying to draw an arrow on the top of the bar, when it draw the supply/demand zone.
    It give me error that say "The name, Draw does does not exist on the current cc.
    Any good programmer out there who could correct it ?
    __________________________________________________ __________________________________________________ ____________
    using System;
    using System.Collections.Generic; // For List<>
    using NinjaTrader.Gui.Tools; // For GUI tools
    using NinjaTrader.NinjaScript; // For NinjaTrader scripting
    using System.Windows.Media; // For Brushes

    namespace NinjaTrader.NinjaScript.Indicators.Infinity
    {
    public class SupandDemwithLine : Indicator
    {
    region Zone Class

    public class Zone
    {
    public double h = 0.0; // high
    public double l = 0.0; // low
    public int b = 0; // bar
    public string t = ""; // type (supply/demand)
    public bool a = true; // active

    public Zone(double l, double h, int b, string t, bool a)
    {
    this.l = l;
    this.h = h;
    this.b = b;
    this.t = t;
    this.a = a;
    }
    }

    #endregion

    region Variables

    private List<Zone> Zones = new List<Zone>();
    private int barIndex = 0;

    #endregion

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Name = "SupandDemwithLine";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[barIndex] < 20)
    return;

    checkSupply();
    checkDemand();
    }

    private void checkSupply()
    {
    // Example detection logic (replace with actual)
    bool supplyZoneDetected = High[0] > High[1]; // Simplified logic

    if (supplyZoneDetected)
    {
    double supplyHigh = High[0];
    double supplyLow = Low[0];

    // Add zone
    Zones.Add(new Zone(supplyLow, supplyHigh, CurrentBar, "s", true));

    // Corrected: Use fully qualified Draw methods
    Draw.ArrowDown(this, $"SupplyArrow_{CurrentBar}", false, Time[0], supplyHigh + TickSize * 2, Brushes.Red);
    }
    }

    private void checkDemand()
    {
    // Example detection logic (replace with actual)
    bool demandZoneDetected = Low[0] < Low[1]; // Simplified logic

    if (demandZoneDetected)
    {
    double demandHigh = High[0];
    double demandLow = Low[0];

    // Add zone
    Zones.Add(new Zone(demandLow, demandHigh, CurrentBar, "d", true));

    // Corrected: Use fully qualified Draw methods
    Draw.ArrowUp(this, $"DemandArrow_{CurrentBar}", false, Time[0], demandLow - TickSize * 2, Brushes.Green);
    }
    }
    }
    }

    #2
    Hello,

    Thank you for your post.

    You are missing the necessary using statements at the top of the script. I recommend recreating this script by using the NinjaScript Wizard, which will generate the necessary using statements for you, then you can copy and paste over any custom logic.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    553 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    100 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    543 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    546 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X