Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Show the Price of a draw object

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

    How to Show the Price of a draw object

    I have an indicator that plots horizontal lines on the chart. However, even though I have PaintPriceMarkers set to true, it still doesn't show the price. Here is the code:

    private double entryBar;
    private double prevATRBar;
    private double highestHigh;
    private double lowestLow;
    private double atrX2;
    private double stopLoss;
    private double Target;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "aStopTrgtDemo";
    Calculate = Calculate.OnBarClose;
    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;
    MaxLookBackPeriod = 10;
    RewardMultiplier = 1.5;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < MaxLookBackPeriod)
    return;
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 12) { Size = 12, Bold = false };
    int lwstlwindx = LowestBar(Low, MaxLookBackPeriod);
    double lwstlw = MIN(Low, MaxLookBackPeriod)[0];

    int hghsthghindx = HighestBar(High, MaxLookBackPeriod);
    double hghsthgh = MAX(High, MaxLookBackPeriod)[0];



    if (EMA(144)[0] > EMA(390)[0] )
    {
    Draw.Text(this,"L",true,"L",lwstlwindx,lwstlw - (TickSize * 4),0,Brushes.Black,myFont,TextAlignment.Center,Bru shes.Transparent,Brushes.Black,1);

    if (Close[1] <= SMA(9)[1] && Close[0] > SMA(9)[0])
    {
    entryBar = Close[0] + .5;
    prevATRBar = ATR(7)[1];
    lowestLow = MIN(Low, MaxLookBackPeriod)[0];
    atrX2 = prevATRBar * 2;
    stopLoss = lowestLow - atrX2;
    Target = entryBar + ((entryBar - stopLoss) * RewardMultiplier);

    Draw.HorizontalLine(this, "Stop", true, stopLoss, Brushes.Red, DashStyleHelper.Solid,2);
    Draw.HorizontalLine(this, "Target", true, Target, Brushes.Lime, DashStyleHelper.Solid,2);
    }

    }

    else if (EMA(144)[0] < EMA(390)[0])
    {
    Draw.Text(this,"H",true,"H",hghsthghindx,hghsthgh + (TickSize * 4),0,Brushes.Black,myFont,TextAlignment.Center,Bru shes.Transparent,Brushes.Black,1);

    if (Close[1] >= SMA(9)[1] && Close[0] < SMA(9)[0])
    {
    entryBar = Close[0] - .5;
    prevATRBar = ATR(7)[1];
    highestHigh = MAX(High, MaxLookBackPeriod)[0];
    atrX2 = prevATRBar * 2;
    stopLoss = highestHigh + atrX2;
    Target = entryBar - ((stopLoss - entryBar) * RewardMultiplier);

    Draw.HorizontalLine(this, "Stop", true, stopLoss, Brushes.Red, DashStyleHelper.Solid,2);
    Draw.HorizontalLine(this, "Target", true, Target, Brushes.Lime, DashStyleHelper.Solid,2);
    }
    }

    }

    #2
    Hello jamestrader21x,

    Thanks for your post.

    From the help guide for the property PaintPriceMarkers: Definition If true, any indicator plot values display price markers in the y-axis. So price markers are used for plots only, not for draw objects. Reference: https://ninjatrader.com/support/help...icemarkers.htm

    You would need to use an add-on that provides a method overload to draw lines with the price. NinjaTrader_Jim has created such an add on that installs as another set of drawing tools that will automatically show the price value of the line (Vertical, horizontal, line, ray, et. etc.) You can optionally add labels (manually not through Ninjascript)

    Once installed you can then access with NS methods using DrawLL, for example:
    DrawLL.LabeledArrowLine(this, "test", 0, Low[0], 10, High[10], Brushes.Gold);
    DrawLL.LabeledHorizontalLine(this, "testb", Close[0], false, "Test1");

    Here is a brief video on the manual use of the drawing tool add-on: https://paul-ninjatrader.tinytake.co...Ml8xMTUyMDkxMg


    This add-on is publicly available on our NinjaTrader Ecosystem website:
    Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

    Note — To import NinjaScripts you will need the original .zip file.

    To Import:
    1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
    2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
    3. Select the downloaded .zip file
    4. NinjaTrader will then confirm if the import has been successful.

    Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

    Comment


      #3
      Thanks for the help, Paul! I updated the my indicator.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      578 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