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 in real time not correct

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

    Indicator in real time not correct

    Hey guys. I have an indicator which works great when CalcOnBarClose = true (or in backtesting). The problem is one of the dataseries is not updating how I'd like it to when CalcOnBarClose = false (or when running a tick chart) and it's run live.

    In the code below, lastDotValue and lastDotUpOrDown are dataseries objects. TrailingMark is a plot.

    This bit of code is in OnBarUpdate() .. stuff not shown here is minimal.
    if (STUFF)
    {
    DrawDot(
    "MyDot");
    lastDotValue.Set(localMax - NumTrailingTicks*myTickSize);
    TrailingMark.Set(lastDotValue[
    0]);
    lastDotUpOrDown.Set(
    1); // 1 for down (blue)
    return;
    }
    // end if
    if (MORE STUFF)
    {
    DrawDot(
    "MyDot" + CurrentBar, true, 0, High[0]+1*myTickSize, Color.Orange);
    lastDotValue.Set(localMin + NumTrailingTicks*myTickSize);
    TrailingMark.Set(lastDotValue[
    0]);
    lastDotUpOrDown.Set(
    0); // 0 for up (orange)
    return;
    }
    // end if
    if(lastDotValue.ContainsValue(1))
    {
    lastDotValue.Set(lastDotValue[
    1]);
    lastDotUpOrDown.Set(lastDotUpOrDown[
    1]);
    }
    // end if
    else
    {
    lastDotValue.Set(Close[
    0]);
    lastDotUpOrDown.Set(
    0);
    }
    // end else
    TrailingMark.Set(lastDotValue[0]);

    What's happening is TrailingMark is not updating when run live. An IF condition will be met, I will GET MY DOT... but the TrailingMark plot is NOT UPDATED. I don't know if this has something to do with overwriting the dataseries objects or if it's my logic here. I have it where if one of the two if blocks are triggered and a dot is printed, then TrailingMark is also updated, and then we return out of OnBarUpdate() before we reach the bottom bit of code (which also sets TrailingMark). Running live it seems like somehow it's always getting to the bottom bit.

    Need some help, thanks guys.

    #2
    Let me clarify what I mean by TrailingMark plot not updating. It is keeping the previous value and not updating to the value calculated in the IF block. (I know we are successfully in the IF block because I get the dot).

    Comment


      #3
      Hello Locke,

      It may be helpful to create a toy version of this to demonstrate the issue. A toy would be a version that reduces the code to only what is needed to reproduce the issue with no other code in it. That means if it isn't completely necessary to reproduce the issue it is taken out.

      If you print the value one line after it is set, does that print have the correct value?

      Please create a toy version and post this.

      To export your script do the following:
      1. Click File -> Utilities -> Export NinjaScript
      2. Enter a unique name for the file in the value for 'File name:'
      3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
      4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


      By default your exported file will be in the following location:
      • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


      Below is a link to the help guide on Exporting NinjaScripts.
      http://www.ninjatrader.com/support/h...nt7/export.htm
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Attached it, there's nothing too crazy in it.

        With the print statement, I see that when running live, it DOES get set correctly, and then immediately gets set incorrectly (back to the previous value, probably down at the end of the OnBarUpdate() function).

        Any suggestions how to get around this would be awesome.
        (try it on any FX pair, that's how it's set with the tick sizes).
        Attached Files

        Comment


          #5
          Hello Locke,

          I ran the script and added a print to see what TrailingMark is set to.

          What prints in the code seems to be what is on the chart (rounded to tick size).

          How are you determining that the value is incorrect? Can I get a screenshot of what you are comparing?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            It's incorrect in that every time a new dot appears, the orange line (TrailingMarks plot) needs to update it's value and change. You would then get a line that is sort of a step function. What I am seeing is that I will get the dot, but the line will not change value. I think it's changing for one instant and then changing back immediately afterward.

            I attached a chart. You see the orange line stay horizontal, even though there are new dots. It looks like it did adjust once though, so by some coincidence the calc was probably the last instant of being calc'd in that bar and it wasn't given a chance to be overwritten.

            Remember to run this with CalcOnBarClose = false (the default).
            Attached Files

            Comment


              #7
              Hello,

              So it looks like the plot gets set in the conditions on lines 79 and 91. But then you overwrite this on the next tick on line 108.

              My recommendation is that you check to see if the plot has a value, if it does not, then set it to lastDotValue[0].

              if (!TrailingMark.ContainsValue(0))
              TrailingMark.Set(lastDotValue[0]);
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Yeah it's weird though. Because even if the condition is satisfied for the entirety of the bar, it looks like it still overwrites it.


                I can already see I have to mess with the logic to keep the other dataseries correct also. I may have add a flag to see if a dot gets printed. But you helped me narrow it down and found the problem. Thanks for all your help Chelsea.

                Comment


                  #9
                  Hello Locke,

                  By setting Calculate on bar close to false, you end up running OnBarUpdate for every tick received while that bar was open. This means that on the next tick it gets overwritten.

                  I think you may be expecting OnBarUpdate to only run once, but this is not the case when Calculate on bar close is set to false.

                  Did you try my suggestion? Did this not work?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Yes, Chelsea, sorry, that works. I want it to calc on every tick, this is what I'm looking for. It's my first time programming for it, so I have to think a little differently in my setup. Thanks very much for your assistance.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Jonafare, 12-06-2012, 03:48 PM
                    5 responses
                    3,986 views
                    0 likes
                    Last Post rene69851  
                    Started by Fitspressorest, Today, 01:38 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post Fitspressorest  
                    Started by Jonker, Today, 01:19 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post Jonker
                    by Jonker
                     
                    Started by futtrader, Today, 01:16 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post futtrader  
                    Started by Segwin, 05-07-2018, 02:15 PM
                    14 responses
                    1,792 views
                    0 likes
                    Last Post aligator  
                    Working...
                    X