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 cmoran13, 04-16-2026, 01:02 PM
    0 responses
    42 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    25 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    162 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    98 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    157 views
    2 likes
    Last Post CaptainJack  
    Working...
    X