Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

diamond not painting correctly

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

    diamond not painting correctly

    Hey all,

    Working on a scalping-type indicator that points out the setup using a painted diamond on the bar that triggers it. Here's what I need to paint:

    Diamond on any bar that has its wick cross the mean of the Donchian channel but does not open nor close on that side. Thus only the wick crosses. E.g. Donchian mean is 100, the low of the bar is 95 (crosses) but the bar opened at 102 and closes at 105 (only wick touches the mean).

    I also would only like to paint the diamond if the ADX is above a certain threshold, and if the price is, for longs, at least two ticks above the EMA on the low or, for shorts, at least two ticks below the EMA on the high.

    I'm kinda bummed - I thought I wrote out the indicator logic very well. Yet it's just leaving me with this (attached image, red arrow shows the bar that SHOULD have a painted diamond), which is a blank panel at the bottom and no painted markers.

    Code:
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "RenkoScalper";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = false;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = false;
    DrawVerticalGridLines = false;
    PaintPriceMarkers = false;
    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;
    DonchianPeriod = 12;
    RequireOutsideWave = false;
    ADXPeriod = 6;
    RequireADXCutoff = false;
    ADXCutoff = 25;
    WavePeriod = 34;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    // Booleans
    bool fireLong = false;
    bool fireShort = false;
    bool valid = true;

    // Get Donchian mean 1 bar ago
    double meanValue = DonchianChannel(Close, DonchianPeriod).Mean[1];

    // Determine if buy or sell wick signal
    if ((Low[1] < meanValue)
    && (Open[1] > meanValue)
    && (Close[1] > meanValue))
    {
    fireLong = true;
    }
    else if ((High[1] > meanValue)
    && (Open[1] < meanValue)
    && (Close[1] < meanValue))
    {
    fireShort = true;
    }

    // Determine if signal is valid
    if (RequireADXCutoff)
    {
    // Last ADX reading
    double CurrentADX = ADX(Close, ADXPeriod)[1];

    // Lose validity if last ADX is under cutoff
    if (CurrentADX < ADXCutoff)
    valid = false;
    }
    if (RequireOutsideWave)
    {
    if (fireLong)
    {
    double HiEMA = EMA(High, WavePeriod)[1];
    if (Open[0] <= HiEMA)
    valid = false;
    }
    else if (fireShort)
    {
    double LoEMA = EMA(Low, WavePeriod)[1];
    if (Open[0] >= LoEMA)
    valid = false;
    }
    }

    // Last validity check
    if (fireLong)
    {
    double LoEMA = EMA(Low, WavePeriod)[1];
    if (Open[0] < (LoEMA + TickSize*2))
    valid = false;
    }
    else if (fireShort)
    {
    double HiEMA = EMA(High, WavePeriod)[1];
    if (Open[0] > (HiEMA - TickSize*2))
    valid = false;
    }

    // If valid, now let's paint our signal
    if (valid && fireLong)
    {
    Draw.Diamond(this, "LongSignal", true, 0, (Low[0] - TickSize*4), Brushes.Lime);
    PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\FireLong.wav");
    }
    else if (valid && fireShort)
    {
    Draw.Diamond(this, "LongSignal", true, 0, (High[0] + TickSize*4), Brushes.Red);
    PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\FireShort.wav");
    }
    }
    Attached Files

    #2
    Hello pappal,

    Thank you for your note.

    Is the issue that the red arrow should have been drawn on the bar prior to the one its drawn on, or that no Diamond is being drawn?

    If you could please provide more information on what the issue is that would be helpful.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AlanP View Post
      Hello pappal,

      Thank you for your note.

      Is the issue that the red arrow should have been drawn on the bar prior to the one its drawn on, or that no Diamond is being drawn?

      If you could please provide more information on what the issue is that would be helpful.

      I look forward to your reply.
      Hey Alan,

      Thanks for the follow-up. I drew the red arrow manually. The indicator is supposed to draw a diamond, but it draws nothing... I placed the red arrow there to show you where the indicator should have drawn a diamond but didn't.

      Comment


        #4
        Hello pappal,

        Likely the issue is its being drawn on the 2nd panel.

        Change,

        Code:
        IsOverlay	= false;
        To,

        Code:
        IsOverlay	= true;
        Please let us know if that does not resolve the issue.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by BarzTrading, Today, 07:25 AM
        2 responses
        15 views
        1 like
        Last Post BarzTrading  
        Started by devatechnologies, 04-14-2024, 02:58 PM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by tkaboris, Today, 08:01 AM
        0 responses
        3 views
        0 likes
        Last Post tkaboris  
        Started by EB Worx, 04-04-2023, 02:34 AM
        7 responses
        162 views
        0 likes
        Last Post VFI26
        by VFI26
         
        Started by Mizzouman1, Today, 07:35 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X