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

Trouble with making indicator

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

    Trouble with making indicator

    Hi,

    I'm new to ninjascript but have done some stuff in MQL5 so I'm familiar with making some basic indicators.I'm trying to recreate an indicator that I've made before but can't seem to be able to convert it to Ninjascript.
    I've looked at the documentation but can't understand why this isn't working. It doesn't seem to load all the data and only draws a portion of it. I've loaded three days of data but the indicator just draws for a few bars.(60 or so) on a 5 minute chart.

    Code:
    protected override void OnStateChange()
    {
        if (State == State.SetDefaults)
        {
            Description                                    = @"";
            Name                                        = "BnB";
            Calculate                                    = Calculate.OnEachTick;
            IsOverlay                                    = false;
            DisplayInDataBox                            = true;
            DrawOnPricePanel                            = 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;
            AddPlot(new Stroke(Brushes.CadetBlue, 2), PlotStyle.Line, "Bulls");
            AddPlot(new Stroke(Brushes.OrangeRed, 2), PlotStyle.Line, "Bears");
            AddPlot(new Stroke(Brushes.White, 2), PlotStyle.Line, "Total");
        }
        else if (State == State.Configure)
        {
            AddDataSeries(null,BarsPeriodType.Volume, 1, MarketDataType.Ask);
            AddDataSeries(null,BarsPeriodType.Volume, 1, MarketDataType.Bid);
            AddDataSeries(null,BarsPeriodType.Tick, 1);
        }
        else if (State == State.DataLoaded)
        {
    
        }
    }
    
    protected override void OnBarUpdate()
    {
        if (CurrentBars[0] < BarsRequiredToPlot || CurrentBars[1] < BarsRequiredToPlot || CurrentBars[2] < BarsRequiredToPlot) return;
    
        if (BarsInProgress == 0)
        {
            //Update();
           /*  I tried with this first
    
            int thisBar = BarsArray[1].GetBar(Times[0][0]);
            int prevBar = BarsArray[1].GetBar(Times[0][1]);
    
                for (int i = prevBar; i <= thisBar; i++)
                {
                    if(Volumes[1].IsValidDataPointAt(i) && Volumes[2].IsValidDataPointAt(i))
                    {
                        Bulls[0] += BarsArray[1].GetVolume(i);
                        Bears[0] += BarsArray[2].GetVolume(i);
                        Total[0] = Bulls[0] + Bears[0];
                    }
                }
            */
        }
         //   Then I tried to do this instead
        if (BarsInProgress == 1)
        {
            Bulls[0] += Volumes[1][0];
            //if (CurrentBars[0] > 600 && CurrentBars[0] < 680) Print(Bulls[0]);
        }
        if (BarsInProgress == 2)
        {
            Bears[0] += Volumes[2][0];
        }
        if(BarsInProgress == 3)
        {
            Total[0] = Volumes[1][0] + Volumes[2][0];
        }
    }​

    #2
    Hello StevenTrades,

    Thank you for your post.

    I suggest adding print statements to your script to better understand its behavior. Each time you assign a value to a plot, it can be helpful to print out values such as CurrentBar, BarsInProgress, and the value assigned to that plot. This will show you when values are assigned and what bar they are being assigned on. For more information about using prints to debug your script's behavior:


    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Emily View Post
      Hello StevenTrades,

      Thank you for your post.

      I suggest adding print statements to your script to better understand its behavior. Each time you assign a value to a plot, it can be helpful to print out values such as CurrentBar, BarsInProgress, and the value assigned to that plot. This will show you when values are assigned and what bar they are being assigned on. For more information about using prints to debug your script's behavior:


      Please let us know if we may be of further assistance.
      Ok, but as you can see from the code I use print statements and that didn't really help me to figure it out because the print in "BarsInProgress == 1" for example shows that there is indeed values there but in the chart they don't show up with those values. Can you see if I made an error in the code? It looks fairly simple doesn't it?

      If I use similar logic in MQL5 it works on that platform but I don't know if Ninjatrader interprets things in another way. I don't have to worry about loading enough bars in MQL for example (because it just loads everything) but on Ninjatrader I do.Still it doesn't load more than just a few in the indicator? I tested this on live data by the way. Is there anything that is different if it is history or live?

      Comment


        #4
        Hello StevenTrades,

        Thank you for your reply.

        You mentioned that the print "for example shows that there is indeed values there but in the chart they don't show up with those values"
        Please provide an example of the print statement you are referring to, what value is being printed and for which CurrentBar index, and what value you are seeing in the chart. The only print I saw in the snippet you shared was commented out:
        Code:
         if (BarsInProgress == 1)
        {
        Bulls[0] += Volumes[1][0];
        //if (CurrentBars[0] > 600 && CurrentBars[0] < 680) Print(Bulls[0]);
        }​
        It is also only printing Bulls[0]. Please print the CurrentBar value as well as Time[0] in the print such as the following:
        Code:
        Print(Time[0] + " CurrentBar: " + CurrentBar + " Bulls[0]: " + Bulls[0]);
        This should help to get more insight as to which bars contain a value for Bulls[0] and what that value should be so you may compare it with those bar indexes/times on the chart as well.

        I look forward to your reply with the results.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your support. After downloading even more data and going offline to test, two out of three plots are working. The print in BarsInProgress = 1 now shows same values.

          The Total plot that runs on 1 tick doesn't seem to get the other two plot values? It just defaults to 2.

          It took forever to load though. I lost track after waiting for over 15 minutes and now only one 5 min chart (with 3 days of data) with only the indicator loaded takes up 10GB in memory (?!).

          Why does it take so long to load just three days of volume data? Metatrader 5 seems ultra fast compared to this.
          When I connect back to live, the indicator starts loading again and you have to wait for it to calculate all over again.
          It then went up to 20 GB of memory used(!). Is it supposed to be doing that? When Live it seems to be missing data again.

          I don't think I've seen a trading platform use up that much memory with only one indicator. Almost seems like memory leak or something.​
          The code is so simple, I don't understand why the platform is so slow?

          Click image for larger version

Name:	nt8.png
Views:	95
Size:	83.6 KB
ID:	1281475



          Click image for larger version

Name:	nt82.png
Views:	79
Size:	30.7 KB
ID:	1281476

          Click image for larger version

Name:	nt83.png
Views:	80
Size:	16.7 KB
ID:	1281477

          Comment


            #6
            Hello StevenTrades,

            Thank you for your reply.

            All of the data series you are loading require tick data, and depending on the number of days loaded on your chart this can easily be very resource-intensive. What is your main goal that you are looking to achieve with this script? It seems as though you are trying to use historical bid/ask volume data to get bullish volume, bearish volume, and total volume, correct? This is very similar to what the BuySellVolume indicator already does using OnMarketData() updates:

            You may be able to make a copy and modify this indicator to further suit your needs.

            With that said, the BuySellVolume indicator requires tick replay to be enabled for historical calculations. More information may be found at the links below:Otherwise, for more details about using historical bid and ask series, please see this page:


            Please let us know if we may be of further assistance.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Thank you for pointing me to the BuySellVolume indicator, I might be able to use that if nothing else helps.

              I still don't understand why this problem occurs though and loading 3 days of ticks really shouldn't be the issue here (and why doesn't BarsInprogress for Tick recognize the values from the other two?). Since I'm reviewing NT8 for a potential switch from Metatrader 5, I'm trying to convert some of the indicators I use. This part that I'm trying with now is just the basic part of the indicator. I haven't even started with the calculations and signals yet.

              I got to be honest here and say that from what I've seen so far a switch seems very unlikely.
              Metatrader 5 seems far superior to NT8. It starts up faster, it loads charts MUCH faster and 3 days of tick data doesn't take forever to load. It can load several weeks in just seconds. A trading platform shouldn't be this slow and hardware consuming. There have been older platforms with 32-bit that have been able to load data faster than from what I've seen NT8 can do. This is the slowest most memory consuming 64-bit trading platform I have ever seen honestly.

              What it tells me is that whoever is behind the design of this platform doesn't know what they are doing really.

              One chart with one indicator and it hogs up 10GB of RAM from loading a few days of ticks? Are you kidding me?!
              Then it goes up to twice that after going live again. Seems like there is something very wrong in that architecture. That just screams memory leaks to me.
              How can people even trade on this platform when simple indicators like the one I'm trying to make takes forever to load?
              It just doesn't seem right.​ At least I should be able to adjust how much data it should load or something but then again 3 days of data seems like it is a minimum really.

              Comment


                #8
                Hello StevenTrades,

                Thank you for your reply.

                The information on the following page, specifically "How Bars Data Is Referenced" might help to get a deeper understanding of what data points each BarsInProgress has access to:


                Even with Calculate set to OnEachTick, that only applies in real-time unless you have Tick Replay enabled. Otherwise, historical processing is done at the close of each bar. For more details on developing for Tick Replay:


                Ultimately to better understand your script and what part of your logic is leading to high RAM usage, you will need to go through a debugging process. We have tips on debugging at the following links:



                Other than prints, which would be helpful to understand what data points are available for each BarsInProgress calling OnBarUpdate(), you could also consider commenting out different portions of logic and testing until the high RAM usage is re-introduced. Whichever portions of logic are commented/uncommented can help you narrow down the potential cause of high resource usage. We have some best practices, including performance practices, listed in the help guide here as well:


                Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one-on-one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one-on-one educational services.​

                Please let us know if we may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for the suggestions.
                  I don't think the problem is the coding skills here. I've always been able to make my own indicators. It's not that hard really, at least not with MQL5 (which is C++ based).
                  The problem here is NT8 really. I've followed your documentation and done exactly what it tells me to do. The script is right there in the first post. It is not rocket science in it, it just loads some tick data. But the platform reacts by memory leakage or something similar. It shouldn't do that from just doing a simple thing as loading three series. I can load up those series in regular charts so why can't I do the same with Ninjascript without it hanging and taking up huge amounts of RAM? Just doesn't make sense.

                  I've seen enough to make the assumption that Ninjascript really isn't a good way to make indicators. If there is this much trouble just making those few things I'm doing in the script, then Ninjatrader is not worth it in my opinion. It should be more developer friendly for the users if it is going to cost me the money a license costs.

                  I've also read a few threads in the forum about users requesting things back in 2017, then again in 2020 and now it's 2023 and things are still not implemented. So Ninjatrader as a company doesn't seem to listen to their user base much. I've just gotten some really bad vibes from all of these things together so I won't be switching to NT8 in the end. Too many red flags for me.
                  I just can't justify the cost of NT8 based on these problems.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by fx.practic, 10-15-2013, 12:53 AM
                  5 responses
                  5,404 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by Shai Samuel, 07-02-2022, 02:46 PM
                  4 responses
                  95 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Started by DJ888, Yesterday, 10:57 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by MacDad, 02-25-2024, 11:48 PM
                  7 responses
                  159 views
                  0 likes
                  Last Post loganjarosz123  
                  Started by Belfortbucks, Yesterday, 09:29 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post Belfortbucks  
                  Working...
                  X