Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Arrowup/ArrowDown Error

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

    Draw.Arrowup/ArrowDown Error

    Hey guys, novice here I thought I would start with a basic project of creating a RSI Divergence indicator, but I just cannot get past this Draw Error, It feels like I am doing it right but I have no doubt I am missing something obvious.

    Thanks in Advance.

    Click image for larger version

Name:	image.png
Views:	128
Size:	23.5 KB
ID:	1307410


    Here is my code:

    using System;
    using System.Windows.Media;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies;

    public class MyRSIDivergenceIndicator : Indicator
    {
    private RSI rsiIndicator;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Detects bullish and bearish RSI divergences.";
    Name = "MyRSIDivergenceIndicator";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    AddPlot(Brushes.Orange, "RSIDivergencePlot");
    }
    else if (State == State.DataLoaded)
    {
    rsiIndicator = RSI(13, 3);
    }
    }
    protected override void OnBarUpdate()
    {
    if (CurrentBar < 50) return; // Ensure there are enough bars to perform the analysis

    // Use Draw.ArrowUp to indicate bullish divergences
    if (IsBullishDivergence())
    {
    Draw.ArrowUp(this, "BullDiv" + CurrentBar, 0, Low[0] - (2 * TickSize), Brushes.Green);
    }

    // Use Draw.ArrowDown to indicate bearish divergences
    if (IsBearishDivergence())
    {
    Draw.ArrowDown(this, "BearDiv" + CurrentBar, 0, High[0] + (2 * TickSize), Brushes.Red);
    }
    }

    private bool IsBullishDivergence()
    {
    int lookBackPeriod = 50; // Maximum look-back period
    int minimumLookBack = 5; // Minimum look-back period

    double lowestLowPrice = double.MaxValue;
    double lowestRSI = double.MaxValue;
    int lowestLowIndex = -1;

    // Search for the lowest low in price and RSI within the last 50 bars
    for (int i = minimumLookBack; i <= lookBackPeriod; i++)
    {
    if (Low[i] < lowestLowPrice)
    {
    lowestLowPrice = Low[i];
    lowestRSI = rsiIndicator[i];
    lowestLowIndex = i;
    }
    }

    // Check for bullish divergence within the last 5 to 50 bars
    if (CurrentBar - lowestLowIndex <= lookBackPeriod && CurrentBar - lowestLowIndex >= minimumLookBack)
    {
    if (Low[0] < lowestLowPrice && rsiIndicator[0] > lowestRSI)
    {
    return true; // Bullish divergence found
    }
    }

    return false;
    }

    private bool IsBearishDivergence()
    {
    int lookBackPeriod = 50; // Maximum look-back period
    int minimumLookBack = 5; // Minimum look-back period

    double highestHighPrice = double.MinValue;
    double highestRSI = double.MinValue;
    int highestHighIndex = -1;

    // Search for the highest high in price and RSI within the last 50 bars
    for (int i = minimumLookBack; i <= lookBackPeriod; i++)
    {
    if (High[i] > highestHighPrice)
    {
    highestHighPrice = High[i];
    highestRSI = rsiIndicator[i];
    highestHighIndex = i;
    }
    }

    // Check for bearish divergence within the last 5 to 50 bars
    if (CurrentBar - highestHighIndex <= lookBackPeriod && CurrentBar - highestHighIndex >= minimumLookBack)
    {
    if (High[0] > highestHighPrice && rsiIndicator[0] < highestRSI)
    {
    return true; // Bearish divergence found
    }
    }

    return false;
    }
    }​

    #2
    Hello binzel,

    May I confirm you created this script with the NinjaScript Editor by right-clicking the Indicators folder and selecting New Indicator?

    Have you modified the using statements that are added by default?

    (Try creating a new script and copying all of the using statements at the top to your script)
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    628 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    359 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    562 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X