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 show up and disapear without any errors.

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

    Indicator show up and disapear without any errors.

    Hello,

    I have a few issues with my code:



    1) The indicator keep showing up and than disapear without any errors. I just cut or add the number of days and its coming back.

    2) I have spikes in the data, any idea how i could get rid of them?

    BI386
    CDL3877
    dif-0,25
    BI387
    CDL3877
    dif-0,25
    BI388
    CDL3877,25
    dif25,5
    BI389
    CDL3902,5
    dif0
    BI390
    CDL3874,75
    dif0

    3) On some chart the indicator is updating live at every trade and on another chart it will update only on bar change.

    TY
    Last edited by frankduc; 02-26-2021, 06:03 AM.

    #2
    Hello frankduc,

    Thanks for your post.

    I see that you have opened several threads on this topic. We ask that you keep correspondence in the same thread with the same technician as opening multiple threads will cause multiple technicians to work the same ticket, and this affects our ability to assist others.

    Thanks for your understanding.

    There are several logical issues looking at this loop.

    1. You are initializing the LastIndexChecked variable before your loop enters. The loop will always start from 0. Is this intended? Did you mean to make this a class level variable instead?
    2. You are setting the plot value of the current bar (Value[0]) instead of the plot value for the bar associated with the index in your loop. Did you mean to change this index so it reflects the actual bar index in your loop? Note that you can convert BarsAgo references to literal bar indexes by subtracting the index from CurrentBar. I.E. Close[CurrentBar-YourIndex]
    3. LastIndexChecked is unused in your loop, what is it's purpose? Did you mean to use it for breaking out of the loop?
    4. Why are you looping to CurrentBar+1? The most current bar index is CurrentBar.

    Our recommendation is the same in which we told you here: https://ninjatrader.com/support/foru...93#post1142593

    You could accomplish your goal by looping over bars in OnBarUpdate. The intended loop would do the following:

    1. Loops from "LastIndexChecked" to CurrentBar. "LastIndexChecked" can be 0 when the script starts.
    2. Assigns price values to a plot and applies the difference from "offset" variable (currently 0).
    3. Checks if there is a gap, save the index where the gap was found to a variable, and also save/update the distance of the gap to a variable "offset", and then breaks the loop.

    The next time the loop is run, it will start where the gap was found and will then adjust with each price by the offset found, and assign the values to the plot.
    I suggest remaining on this path and to work towards your goal in segments. I also suggest to perform rubber-duck-debugging to understand how each line is used and also to follow along what indexes the loop processes so you can understand where it is processing, where it is identifying gaps, how it is calculating your offset, and how the plot values are being assigned.

    With each index the loop processes, you can update your LastIndexChecked variable.

    Your loop then needs to find an index where a gap is or when there is a session break.

    When a gap is found, you can:

    1. Update your class level offset variable
    2. Update the plot value associated with this index with your offset
    3. Break the loop

    When there is not a gap or session break, you can set the plot value associated with the this index, with your offset applied.

    This would be the most amount of help we could offer without writing the code for you. If this is too difficult and you require services to have code written for you, NinjaScript Consulting Services would be advised.

    Historical data on the chart is what is built from the data provider's data. If you have spikes in data with realtime data, you can use Realtime Tick Filter to filter out ticks that exceed a certain threshold. However, it is not clear that the "data spikes" you mention are because of underlying data, or because of your offset calculation.

    Realtime Tick Filter - https://ninjatrader.com/support/help...ick_filter.htm

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,

      1. You are initializing the LastIndexChecked variable before your loop enters. The loop will always start from 0. Is this intended? Did you mean to make this a class level variable instead?
      It was suggested by Brandon but i dont understand why doing this. I could loop from 0 to ChartBars.ToIndex and it will return the same. Why making it a class variable? Its doing what it is suppose to do and return the right values.

      2. You are setting the plot value of the current bar (Value[0]) instead of the plot value for the bar associated with the index in your loop. Did you mean to change this index so it reflects the actual bar index in your loop? Note that you can convert BarsAgo references to literal bar indexes by subtracting the index from CurrentBar. I.E. Close[CurrentBar-YourIndex]
      Are you talking about : Value[barIndex] = candle;? Cause i dont know why i would do that, its returning nothing.

      3. LastIndexChecked is unused in your loop, what is it's purpose? Did you mean to use it for breaking out of the loop?
      I dont know what he meant by using LastIndexChecked.

      4. Why are you looping to CurrentBar+1? The most current bar index is CurrentBar.
      Because for a reason i cant explain it is missing the most recent value traded, so on some chart, it is updating live and other charts updating as a new bar appearing.

      Sorry i dont understand your recommandation, it is not clear. Ok i am an amateur coder, but OBU is not simple to use. Ecosystem suck, half of them are amateurs coder like me. If you want to lose money its the best place.

      No spikes are from offset calculation.

      TY


      Comment


        #4
        Hello frankduc,

        LastIndexChecked would be a variable that keeps track of the last index the loop has checked. If this is a class level variable, the value will be remembered. If you set it to 0 before the loop starts, the loop always starts at bar 0 and does not start back from the last index it was at.

        Your loop processes various bars indexes, and is not assigning the plot value associated with the current bar index in the loop. Value[0] = SOMEVALUE; always assigns the plot value associated with the current bar the script is processing. You will need to convert the BarsAgo 0 reference to a literal bar index.

        You will need to think of your way through how the loop needs to be written, and you will need to have a full understanding of what indexes you are working with. Rubber-Duck-Debugging would mean to understand each line, and to read off the code and explain to yourself what the code is doing and what indexes are being worked with, etc.

        The advise I gave is a plain English explanation of what can be done. As long as the code is written following this procedure I am confident you will be able to move forward on your own.

        You have a choice here, keep trying the approach suggested and take careful steps to make sure the code is doing exactly what you expect and need it to, otherwise, if this is too difficult, the other option would be to hire someone to write the code for you. If you want to poll the community for recommended consultants, we can leave the thread open for their feedback.

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          Jim,

          Soon or later i will get the hang of it. Its more easy to solve a problem when you understand what is happening.

          What i am doing now is: I work from the first bar of the left chart of the last bar at the right side of the chart.

          The close of the first bar - the open of the second bar = result (eg. 9-10 = -1)
          Than the result (offset) is added to the close price of the first bar. (eg. 9+ (-1) = 8) 8 is now the first value of candle.
          Than the close of the second bar - the open of the third bar (eg. 10- 8 = 2) 12 is now the second value of candle and it goes on till it reach the end of the chart.

          Now i succeeded in removing the spikes. I dont know if its gonna solve the disappearance of the indicator from time to time.

          Your loop processes various bars indexes, and is not assigning the plot value associated with the current bar index in the loop. Value[0] = SOMEVALUE; always assigns the plot value associated with the current bar the script is processing. You will need to convert the BarsAgo 0 reference to a literal bar index.
          The part about assigning the plot value associated with the current bar index in the loop brings a lot of confusion to me. Cause barIndex is starting at the left side of the chart at 0 and is increasing to (...) the right side of the chart. barsAgo is irrelevant? I mean BA is going in the other side, why would i need it? SOMEVALUE is it not my candle variable?

          Thanks for the input.





          Comment


            #6
            Hello frankduc,

            Value[0] means the plot value associated with the current bar that OnBarUpdate is processing, not the index that is used in your loop. OnBarUpdate iterates with each bar, starting from bar 0 on the left, to the last bar on the right.

            If you want to set a plot value for the bar index that the loop is processing, you need to subtract that index from CurrentBar. I.E. Value[CurrentBar-BarIndexOfLoop] = SOMEVALUE;

            SOMEVALUE is just a placeholder name for the value you assign to the plot.
            JimNinjaTrader Customer Service

            Comment


              #7
              Jim,

              Thanks for the explanation. I thought Value[0] =candle; meant that the [zero] was the first value in my serie of values inside variable candle. Is there examples somewhere of how it is used ? Some indicator you can switch the plot value and see the result in the chart.

              The issue about chart update is resolve.

              The only mystery remaining is why my yellow line keep vanishing after a certain time. Some cycle keep switching off my indicator. There is no error message related.

              Frank

              Comment


                #8
                Hello frankduc,

                BarsAgo indexes are explained here - https://ninjatrader.com/support/help...ice_series.htm

                For your remaining issues, I recommend testing on a chart that has 0 bars to load and to use the Playback Connection to test. This way, you can monitor how your loop is working when the indicator starts processing data, and you can follow your logic taking debugging steps to check your work as the calculations are made.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Stanfillirenfro, Today, 07:23 AM
                1 response
                2 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                2 responses
                19 views
                0 likes
                Last Post cmtjoancolmenero  
                Started by olisav57, Yesterday, 07:39 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by cocoescala, 10-12-2018, 11:02 PM
                7 responses
                943 views
                0 likes
                Last Post Jquiroz1975  
                Started by oviejo, Today, 12:28 AM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X