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

MarketAnalyzer Column returning whole numbers

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

    MarketAnalyzer Column returning whole numbers

    I've created a MarketAnalyzer Column that calculates the Current Price - Previous close. It Prints the correct values to the console however, the column shows the values as something entirely different. Here is code and I've also attached the script if you want to test:

    Code:
            double prevClose = 0;
            double priceChange = 0;
            protected override void OnMarketData(Data.MarketDataEventArgs marketDataUpdate)
            {
                if (marketDataUpdate.IsReset){
                    CurrentValue = double.MinValue;
                    return;
                }
    
                if (marketDataUpdate.MarketDataType == Data.MarketDataType.Last){
                    if(marketDataUpdate.Price == null)return;
                    //if prevClose has not been set yet
                    if(prevClose == 0)return;
    
                    priceChange = Math.Round(marketDataUpdate.Price - prevClose,2);
                    //This prints the value as expected
                    Print(priceChange);
                    //However the value in the column does not display correctly
                    CurrentValue = priceChange;
                    return;
                }
                if (marketDataUpdate.MarketDataType == Data.MarketDataType.LastClose){
                    if(marketDataUpdate.Price != null){
                         prevClose = marketDataUpdate.Price;
                    }
                }            
    
            }
    Here is a screenshot of the values shown in my window vs. what Prints out:
    Attached Files
    Last edited by swcooke; 10-04-2019, 08:37 PM.

    #2
    Hello swcooke, thanks for your post.

    It looks like the DataType property is an int instead of a double. Add this to State.SetDefaults:

    DataType = typeof(double);

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

    Comment


      #3
      Hi Chris,

      Sorry for the late reply on this. I have followed your instructions but it still does not output the correct value in the MarketAnalyzer window even though I have made the suggested change. Attached is my simply column. Can you run this and let me know what I am doing wrong? Here it is: npImpact.zip

      Comment


        #4
        Hello swcooke,

        I was also able to reproduce.

        I'm seeing the text is being formatted in Format() override.

        You are using 'Core.Globals.FormatQuantity((long) value, false);' to return an int.


        Try printing on line 68:
        Print(string.Format("priceChange: {0}, FormatQuantity(): {1}", priceChange, Core.Globals.FormatQuantity((long) priceChange, false)));

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks! That solved the issue.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, Today, 09:40 AM
          6 responses
          27 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          13 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X