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

Converted indicator from NT7 to NT8 compiled, no errors, still not working.

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

    Converted indicator from NT7 to NT8 compiled, no errors, still not working.

    Converted another indicator from NT7 to NT8. This one is compiling, no errors in logs, but is still not putting any info on the chart. The original NT7 code works fine. NT8 code is below.

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Indicators.MackPATS
    {
        public class ShowBidAskwh : Indicator
        {
            private bool displayText = true;
            private int endbarsago = -12;
            private int startbarsago = -3;
            private int thickness = 1;
            private Brush bidColor = Brushes.Red;
            private Brush askColor = Brushes.Blue;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Puts a horizontal line at the ask price";
                    Name                                        = "ShowBidAskwh";
                    Calculate                                    = Calculate.OnEachTick;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = false;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = false;
                    DrawVerticalGridLines                        = false;
                    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;
                    // DisplayText                    = true;
                    // bidColor                    = Brushes.Red;
                    // askColor                    = Brushes.Blue;
                    // Endbarsago                    = -12;
                    // Startbarsago                    = -3;
                    // Thickness                    = 1;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom indicator logic here.
            }
    
            protected override void OnMarketData(MarketDataEventArgs e)
            {
                double a=e.Ask;
                double b=e.Bid;
                double TValue = Instrument.MasterInstrument.PointValue * TickSize;
                double SpreadCost = (a-b)/TickSize * TValue;
                /*removed currency symbol - some users don't trade $ denom instruments so it could be misleading.
                You can convert whatever symbols currency into your own trading currency but it's way too complicated
                for this small piece of code.
                */
                string v = "Ask/Bid Spread:\n"+SpreadCost.ToString("0.00");
    
    
                if(displayText)
                    Draw.TextFixed(this, "text",v,TextPosition.TopLeft);
    
    
                {
    
                if ( e.MarketDataType == MarketDataType.Ask)
                {
                    Draw.Line(this, "ask", false, startbarsago, e.Price , endbarsago, e.Price, AskColor, DashStyleHelper.Solid, Thickness);
    
                }
                else if (e.MarketDataType == MarketDataType.Bid)
                {
                    Draw.Line(this, "bid", false, startbarsago, e.Price, endbarsago, e.Price, BidColor, DashStyleHelper.Solid, Thickness);
                }
                }
            }
    
            #region Properties
            [NinjaScriptProperty]
            [Display(Name="DisplayText", Description="Display Text", Order=1, GroupName="Parameters")]
            public bool DisplayText
            { 
                get { return displayText; }
                set { displayText = value; }
            }
    
            [NinjaScriptProperty]
            [XmlIgnore]
            [Display(Name="BidColor", Description="Bid Color", Order=2, GroupName="Parameters")]
            public Brush BidColor
            { 
                get { return bidColor; }
                set { bidColor = value; }
            }
    
            [Browsable(false)]
            public string BidColorSerializable
            {
                get { return Serialize.BrushToString(BidColor); }
                set { BidColor = Serialize.StringToBrush(value); }
            }            
    
            [NinjaScriptProperty]
            [XmlIgnore]
            [Display(Name="AskColor", Description="Ask Color", Order=3, GroupName="Parameters")]
            public Brush AskColor
            {
                get { return askColor; }
                set { askColor = value; }
            }
    
            [Browsable(false)]
            public string AskColorSerializable
            {
                get { return Serialize.BrushToString(AskColor); }
                set { AskColor = Serialize.StringToBrush(value); }
            }            
    
            [NinjaScriptProperty]
            [Display(Name="Endbarsago", Description="Negative nos extends line further into the future.", Order=4, GroupName="Parameters")]
            public int Endbarsago
            {
                get { return endbarsago; }
                set { endbarsago = value; }
            }
    
            [NinjaScriptProperty]
            [Display(Name="Startbarsago", Description="Negative nos pushes line start to the right.", Order=5, GroupName="Parameters")]
            public int Startbarsago
            {
                get { return startbarsago; }
                set { startbarsago = value; }
            }
    
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="Thickness", Description="Thickness of line", Order=6, GroupName="Parameters")]
            public int Thickness
            {
                get { return thickness; }
                set { thickness = value; }
            }
            #endregion
    
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private MackPATS.ShowBidAskwh[] cacheShowBidAskwh;
            public MackPATS.ShowBidAskwh ShowBidAskwh(bool displayText, Brush bidColor, Brush askColor, int endbarsago, int startbarsago, int thickness)
            {
                return ShowBidAskwh(Input, displayText, bidColor, askColor, endbarsago, startbarsago, thickness);
            }
    
            public MackPATS.ShowBidAskwh ShowBidAskwh(ISeries<double> input, bool displayText, Brush bidColor, Brush askColor, int endbarsago, int startbarsago, int thickness)
            {
                if (cacheShowBidAskwh != null)
                    for (int idx = 0; idx < cacheShowBidAskwh.Length; idx++)
                        if (cacheShowBidAskwh[idx] != null && cacheShowBidAskwh[idx].DisplayText == displayText && cacheShowBidAskwh[idx].BidColor == bidColor && cacheShowBidAskwh[idx].AskColor == askColor && cacheShowBidAskwh[idx].Endbarsago == endbarsago && cacheShowBidAskwh[idx].Startbarsago == startbarsago && cacheShowBidAskwh[idx].Thickness == thickness && cacheShowBidAskwh[idx].EqualsInput(input))
                            return cacheShowBidAskwh[idx];
                return CacheIndicator<MackPATS.ShowBidAskwh>(new MackPATS.ShowBidAskwh(){ DisplayText = displayText, BidColor = bidColor, AskColor = askColor, Endbarsago = endbarsago, Startbarsago = startbarsago, Thickness = thickness }, input, ref cacheShowBidAskwh);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.MackPATS.ShowBidAskwh ShowBidAskwh(bool displayText, Brush bidColor, Brush askColor, int endbarsago, int startbarsago, int thickness)
            {
                return indicator.ShowBidAskwh(Input, displayText, bidColor, askColor, endbarsago, startbarsago, thickness);
            }
    
            public Indicators.MackPATS.ShowBidAskwh ShowBidAskwh(ISeries<double> input , bool displayText, Brush bidColor, Brush askColor, int endbarsago, int startbarsago, int thickness)
            {
                return indicator.ShowBidAskwh(input, displayText, bidColor, askColor, endbarsago, startbarsago, thickness);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.MackPATS.ShowBidAskwh ShowBidAskwh(bool displayText, Brush bidColor, Brush askColor, int endbarsago, int startbarsago, int thickness)
            {
                return indicator.ShowBidAskwh(Input, displayText, bidColor, askColor, endbarsago, startbarsago, thickness);
            }
    
            public Indicators.MackPATS.ShowBidAskwh ShowBidAskwh(ISeries<double> input , bool displayText, Brush bidColor, Brush askColor, int endbarsago, int startbarsago, int thickness)
            {
                return indicator.ShowBidAskwh(input, displayText, bidColor, askColor, endbarsago, startbarsago, thickness);
            }
        }
    }
    
    #endregion
    6.5.0

    #2
    Hi HombreLobo, thanks for your note.

    That code works fine for me, move the chart into the future and I can see the two lines being drawn. If you want the lines to be drawn on the bars, change the start/endbars ago to positive instead of negative.

    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    3 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Working...
    X