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

indicator not showing real time value repeated count it show's same random number

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

    indicator not showing real time value repeated count it show's same random number

    Click image for larger version

Name:	Screenshot (21).png
Views:	93
Size:	179.6 KB
ID:	1256888

    facing new issue on indicator not showing real time value repeated count it show's same random number . i am attact screenshot for you ref . pls tell how to solve this

    -------------------------------------------------------------------

    using System;
    using System.Collections.Generic;
    using System.Windows.Media;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.DrawingTools;
    using NinjaTrader.NinjaScript.Indicators;

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class TickRepetitionCounter : Indicator
    {
    private Dictionary<double, int> tickCounts;
    private double lastTickValue;
    private DateTime lastTradingDate;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Tick Repetition Counter";
    Name = "TickRepetitionCounter";
    Calculate = Calculate.OnEachTick;
    IsOverlay = true;
    tickCounts = new Dictionary<double, int>();
    }
    }

    protected override void OnBarUpdate()
    {
    DateTime currentTradingDate = Time[0].Date;

    if (currentTradingDate != lastTradingDate)
    {
    tickCounts.Clear();
    lastTradingDate = currentTradingDate;
    }

    double currentTickValue = Close[0];

    int currentTickCount = tickCounts.ContainsKey(currentTickValue) ? tickCounts[currentTickValue] : 0;
    tickCounts[currentTickValue] = currentTickCount + 1;

    lastTickValue = currentTickValue;

    PrintTickCounts();
    }

    private void PrintTickCounts()
    {
    RemoveDrawObjects();

    int yOffset = 0;

    foreach (KeyValuePair<double, int> tickCount in tickCounts)
    {
    string label = "Value: " + tickCount.Key + "\tNumber of Times Repeated: " + tickCount.Value;

    Draw.Text(this, label, yOffset.ToString(), 0, tickCount.Key, Brushes.White);
    yOffset -= 15;
    }
    }
    }
    }​

    #2
    Hello alagu,

    Looking at the code provided its not really clear what you are trying to do with this logic to provide a solution. If the values you pictured are not correct based on what you are trying to do you would need to use Prints to find out what part of your logic is not working as expected.

    JesseNinjaTrader Customer Service

    Comment


      #3
      i would plan to design this indicator for each and every tick by tick LTP how many times repeated and it will be counted.

      ex.
      LTP | LTP repeated count
      1879 | 34
      1881 | 38
      1885 | 60

      Comment


        #4
        Hello alagu,

        If that is what you want you would have to make sure the logic you wrote accomplishes that task. You can use Print statements in your code to make sure its working how you wanted. Our support can't debug the code you provided for you but we can make suggestions at resources. If there is a specific part of the code you provided that you found is not working and had a specific question about that part of the code we could go further into that.

        I would suggest making sure that you are printing the right thing with Draw.Text, it looks like you may have used the incorrect paramters:

        Draw.Text(this, label, yOffset.ToString(), 0, tickCount.Key, Brushes.White);


        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello alagu,

          If that is what you want you would have to make sure the logic you wrote accomplishes that task. You can use Print statements in your code to make sure its working how you wanted. Our support can't debug the code you provided for you but we can make suggestions at resources. If there is a specific part of the code you provided that you found is not working and had a specific question about that part of the code we could go further into that.

          I would suggest making sure that you are printing the right thing with Draw.Text, it looks like you may have used the incorrect paramters:

          Draw.Text(this, label, yOffset.ToString(), 0, tickCount.Key, Brushes.White);


          https://ninjatrader.com/support/help.../draw_text.htm
          already modified this code many time. but still this code provided what evary i want that thinks .i you don't mind pls check and reprogram this code

          i want real time each and evary value how many time repeated .for your ref pls view attached fig

          Click image for larger version

Name:	Screenshot 2023-06-21 205826.png
Views:	86
Size:	30.0 KB
ID:	1256900

          ---------------------------------------------------------------------------------------------------------------------------------------------------------------

          using System;
          using System.Collections.Generic;
          using System.Windows.Media;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.NinjaScript.DrawingTools;
          using NinjaTrader.NinjaScript.Indicators;

          namespace NinjaTrader.NinjaScript.Indicators
          {
          public class TickRepetitionCounter : Indicator
          {
          private Dictionary<double, int> tickCounts;
          private double lastTickValue;
          private DateTime lastTradingDate;

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = "Tick Repetition Counter";
          Name = "TickRepetitionCounter";
          Calculate = Calculate.OnEachTick;
          IsOverlay = true;
          tickCounts = new Dictionary<double, int>();
          }
          }

          protected override void OnBarUpdate()
          {
          DateTime currentTradingDate = Time[0].Date;

          if (currentTradingDate != lastTradingDate)
          {
          tickCounts.Clear();
          lastTradingDate = currentTradingDate;
          }

          double currentTickValue = Close[0];

          int currentTickCount = tickCounts.ContainsKey(currentTickValue) ? tickCounts[currentTickValue] : 0;
          tickCounts[currentTickValue] = currentTickCount + 1;

          lastTickValue = currentTickValue;

          PrintTickCounts();
          }

          private void PrintTickCounts()
          {
          RemoveDrawObjects();

          int yOffset = 0;

          foreach (KeyValuePair<double, int> tickCount in tickCounts)
          {
          string label = "Value: " + tickCount.Key + "\tNumber of Times Repeated: " + tickCount.Value;

          Draw.Text(this, label, yOffset.ToString(), 0, tickCount.Key, Brushes.White);
          yOffset -= 15;
          }
          }
          }
          }​​

          Comment


            #6
            Hello alagu,

            Our support does not provide programming or debugging services, if you want someone to check your code and debug/fix it you would need to hire someone to do that. You would otherwise need to debug the code yourself by using prints and making sure that you are using the correct values in the drawings.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by memonic, Yesterday, 01:23 PM
            2 responses
            11 views
            0 likes
            Last Post memonic
            by memonic
             
            Started by merc410, Today, 03:41 AM
            2 responses
            10 views
            0 likes
            Last Post merc410
            by merc410
             
            Started by sugalt, 04-30-2024, 04:02 AM
            2 responses
            13 views
            0 likes
            Last Post sugalt
            by sugalt
             
            Started by Ndakotan1313, 03-14-2024, 05:02 PM
            2 responses
            63 views
            0 likes
            Last Post blaise_code  
            Started by claxxical, 05-30-2017, 12:30 PM
            37 responses
            4,462 views
            0 likes
            Last Post Padan
            by Padan
             
            Working...
            X