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

MTF indicator calling plot is giving Close[0]

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

    MTF indicator calling plot is giving Close[0]

    Hello,

    I'm using a MTF indicator to call another indicator with plotted results in the range of -12 to+12.

    I'm using this for the two bar series.
    OnStartUp section:
    Code:
     _ncc18LTF = NewCriteriaCheck_v18newa(BarsArray[0],12,14,34,26,9,7); 
    _ncc18HTF = NewCriteriaCheck_v18newa(BarsArray[1],12,14,34,26,9,7);
    OnBarUpdate section:

    Code:
    if (BarsInProgress == 0 && _ncc18LTF.TriggerSignal.ContainsValue(0))
    {
    	Decision_Plot[0]=_ncc18LTF.TriggerSignal[0];
    } 
    Decision_Plot_MTF[0] = _ncc18HTF.TriggerSignal[0];
    Plots produce closing price only on the second plot but not the range I'm expecting as in the indicator with the 3 lineplots. The single maroon plot at 0.03 value is using the same method from a different indicator. How do I prevent the Close[0] or Input[0] from affecting the plot? Also, something must be preventing my plot from being exposed in the called indicator because I don't get both plots - in the bottom panel. or only zero in the 3rd panel
    Attached Files
    Last edited by zeller4; 06-28-2015, 08:51 PM.

    #2
    Hello zeller4,

    Thanks for your post.

    Just to confirm, the indicator you are calling is sometimes returning the close price, is this correct?

    An indicator will return the close price when it does not have a value for that bar. In your code I am seeing that you have a check for ContainsValue(0) on the _ncc18LTF.TriggerSignal object (containing an indicator).

    Is Decision_Plot the plot that is sometimes including the close price?

    Is Decision_Plot_MTF[0] the plot that is sometimes including the close price?

    The plots if placed by one indicator should also be in the same panel. (It is not supported to have an indicator plot on multiple panels).

    There are no labels in your screen shot. Which panel is the indicator this code is in?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea B.

      Yes, you are correct. I'm attaching a new screenshot image. See the panel 3 blue indicator.

      If you'd like I can zip the files to your email but the NewCriteriaCheck file is rather complex. I've made the plots from that file - shown as gray, gold, red to be called by the MTF file shown in blue. The plots in the MTF file are never set to close[0], that's why I can't understand and I've checked the called indicator isn't setting anything as close[0].

      The Decision_Plot should be reading the BIP==0 plot and the Decision_Plot_MTF should be reading the BIP==1 MTF plot. As it is currently, it produces no BIP0 plot and the BIP1 blue plot is Close[0]. The TriggerSignal from the NewCriteriaCheck file is the gold plot.

      Thx,
      Kirk
      Attached Files
      Last edited by zeller4; 06-29-2015, 09:43 AM.

      Comment


        #4
        Hello Kirk,

        An indicator will return the close price when it does not have a value for that bar. It does not require that you set the plot to the close price. This happens automatically if there is not a value for that bar.

        Let me know if this does not make sense.

        BIP (BarsInProgress) lets you know which dataseries added directly to the script is in progress. However, this is not the data series itself.

        A plot will only have values for the primary data series and will not sync to a secondary series by default. (Though it is possible to do)
        http://ninjatrader.com/support/forum...ead.php?t=3572


        If you print the value of the indicator you are setting to the plot one line above where this is set, is this returning the close price or the correct value?

        My thoughts are on the plot that is not showing, this is not being set because the indicator does not have a value. Your code explicitly says do not set the plot if the indicator does not have a value for that plot. However, the other plot does not have this check and when there is no value it is returning the close price instead as this is what happens by default.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Well, Chelsea, I tried the print statements with the .ContainsValue so even though the called indicator gives plots, the calling one is not receiving any data to print or plot. But now it is providing some print data...

          Also, I modified the SampleDataSeries (attached) . I left the original secondary and primary series in the strategy file but the secondarySeries - line 80
          Code:
          secondarySeries = new DataSeries(SMA(BarsArray[1], 50));
          isn't giving it's value so I'm not sure what else I'm not doing right. See the new screenshot.

          I set three drawtextfixed windows from the various BIP sections so I could understand what's giving values and what isn't. Occasionally, I'm still getting the close[0] - see the left textbox.

          Please review and tell me where else I need to revise.
          Thanks,
          Kirk
          Attached Files
          Last edited by zeller4; 06-29-2015, 01:51 PM.

          Comment


            #6
            Hello zeller4,

            The line:
            secondarySeries = new DataSeries(SMA(BarsArray[1], 50));

            is not valid code. I would not expect this to work.


            However:
            (in Initialize())
            secondarySeries = new DataSeries(this);
            (in OnBarUpdate)
            secondarySeries.Set(SMA(BarsArray[1], 50)[0]);

            should work fine.


            Why are you duplicating an already existing dataseries?

            Also, a dataseries is not automatically a plot. It can hold values but doesn't plot. Adding a plot both creates a dataseries and also plots on the chart.



            Below is a link to the help guide on the DataSeries class.
            http://ninjatrader.com/support/helpG...ries_class.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello zeller4,

              The line:
              secondarySeries = new DataSeries(SMA(BarsArray[1], 50));

              is not valid code. I would not expect this to work.
              Why are you duplicating an already existing dataseries?
              Chelsea,
              Unfortunately, that line of code is in the SampleDataSeries.cs file from the earlier link you gave me. http://ninjatrader.com/support/forum...ead.php?t=3572

              I'm merely trying to emulate code from NT that should teach me how to sync indicators.
              Any other help you can provide from the previous code I sent you would be appreciated.
              Thanks,
              Kirk
              Last edited by zeller4; 06-29-2015, 02:57 PM.

              Comment


                #8
                Hi zeller4,

                I actually did not know that would work and I have learned something. Nice.

                Back to the prints. At this time are you getting the correct value in your prints from the indicator on every bar?

                In your previous post it sounds like sometimes you get a print and sometimes you do not.

                Also, what are you printing?

                I am seeing the following in your code:
                primary2Series.Set(_ncc18LTF.TriggerSignal[0]);

                if (FirstTickOfBar){
                Print("=BIP0===============");
                Print("=SampleDataSeries_v01=");
                Print("primary2Series: " +primary2Series[0]);
                }

                Does this mean you are wanting the value of _ncc18LTF.TriggerSignal[0]?

                Is this _ncc18LTF.TriggerSignal[0] value that is set on every bar?
                Does Print(_ncc18LTF.TriggerSignal[0]); print the correct value on every bar? (is this printing the close price?)

                (I am not able to test your code without an export that has all needed dependencies)
                Last edited by NinjaTrader_ChelseaB; 06-30-2015, 08:10 AM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Back to the prints. At this time are you getting the correct value in your prints from the indicator on every bar?
                  In your previous post it sounds like sometimes you get a print and sometimes you do not.
                  I'm getting print statements - I posted a .txt file of the output window.
                  Also, what are you printing?
                  I'm getting print statements of the current values of primary2series and secondary2series along with a line that tells me which BIP it came from.

                  I am seeing the following in your code:
                  primary2Series.Set(_ncc18LTF.TriggerSignal[0]);

                  if (FirstTickOfBar){
                  Print("=BIP0===============");
                  Print("=SampleDataSeries_v01=");
                  Print("primary2Series: " +primary2Series[0]);
                  }

                  Does this mean you are wanting the value of _ncc18LTF.TriggerSignal[0]?
                  Yes, is that not the right way to get it? BTW, I changed the requested dataseries to UltimateCondition...
                  Is this _ncc18LTF.TriggerSignal[0] value that is set on every bar?
                  Does Print(_ncc18LTF.TriggerSignal[0]); print the correct value on every bar? (is this printing the close price?)
                  Yes, it's set on every bar but I'm also looking for the secondary2series from the BIP1 - I want it updated on every bar or tick even though it won't change until the next BIP1 bar update
                  (I am not able to test your code without an export that has all needed dependencies)
                  That's fine, let's see how this round goes.

                  New questions:
                  1) is this line for the purpose of syncing?
                  Code:
                  secondarySeries = new DataSeries(SMA(BarsArray[1], 50));
                  2) can this line be used for the purpose of syncing?
                  Code:
                  secondary2Series = NewCriteriaCheck_v18newa(BarsArray[1],12,14,34,26,9,7).UltimateCondition;
                  3) how can I get this to produce a plot in panel 2?
                  Code:
                  FROM INITIALIZE:
                  _ncc18LTF = NewCriteriaCheck_v18newa(12,14,34,26,9,7);
                  Add(_ncc18LTF);
                  _ncc18LTF.PanelUI = 2;
                  4) since the bip? window is showing a closing price for primary2series and secondary2series, is that all that's needed for syncing?

                  Thanks for your help.
                  Kirk
                  Attached Files
                  Last edited by zeller4; 06-30-2015, 05:13 PM.

                  Comment


                    #10
                    Hello zeller4,

                    If you want to see a value for every tick, you would want to set the series even if it already has a value.

                    The point of synchronizing a dataseries to a secondary bar series is so that you can store calculated values to this series. In your script, it looks like you want the value of _ncc18LTF.TriggerSignal[0] and NewCriteriaCheck_v18newa(BarsArray[1],12,14,34,26,9,7).UltimateConditio[0]. If this is the case, it is not necessary to duplicate this information to a local dataseries. These dataseries already exist and can already be called.

                    I did, however, want to make a demonstration of creating a secondary series and populating this secondary series with duplicated values from an indicator call. Attached is the script and a link to a video demonstrating how this works.

                    http://screencast.com/t/FpptAqxprfwI

                    (edit)
                    Recreated video with sound
                    http://screencast.com/t/ptjfuHxK


                    1) Yes, the line secondarySeries = new DataSeries(SMA(BarsArray[1], 50)); syncs the secondarySeries to the BarsArray[1] bars.

                    2) Yes, the line secondary2Series = NewCriteriaCheck_v18newa(BarsArray[1],12,14,34,26,9,7).UltimateCondition; should work fine to sync the seconary series. (Because this just creates an empty dataseries that is synced to BarsArray[1] using any indicator would work the same)

                    3) Your code should already be correct to set the indicator that is added to the chart to panel 2.

                    The following for me worked correctly:
                    In #region Variables:
                    private SMA mySMA;
                    In Initialize():
                    mySMA = (SMA) SMA(4);
                    Add(mySMA);
                    mySMA.PanelUI = 2;
                    mySMA.Plots[0].Pen = new Pen(Color.Blue);
                    Attached Files
                    Last edited by NinjaTrader_ChelseaB; 07-01-2015, 09:48 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Chelsea,
                      I'm working on your sample tonight and have reviewed the video explanation. Congratulations! for a fantastic explanation and extra effort and time spent in preparing this video and test file.
                      I rate your responses A++!
                      Thanks again,
                      Kirk

                      Comment


                        #12
                        Chelsea,
                        I've duplicated what you did and will now try in my own indicator. Last questions: 1) is doing this secondary syncing identical for indicator files as it is for strategy files? I've attached an indicator version of your file to see if this can be done with plots in an indicator. 2) do you have a way to incorporate OnStartUp() section that you could demonstrate? Or please verify I'm using the correct syntax in the attached code. Also, I'm providing a screenshot with your setup with the two MACD plots that compare to mine. They aren't exact at the time of loading, but soon after resume the same values.
                        Thanks again,
                        Kirk
                        Attached Files
                        Last edited by zeller4; 07-01-2015, 07:40 PM.

                        Comment


                          #13
                          Hello Kirk,

                          While secondarySeries is synchronized to the secondary series, Plot1_MTF is not.

                          This means that Plot1_MTF has a different size than secondarySeries, meaning the datapoints are different. (Plot1_MTF is synchronized to the primary not the 5 minute series.)

                          (You may be overwriting the last value of the previous plot which I don't think would be accurate for displaying on a chart because it would show on the wrong bar)
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            What's the proper way to update this plot so the line uses historical data before the live data is available?
                            I moved the Plot setting to BIP1.
                            Code:
                             if (BarsInProgress == 1)
                            			{
                            				Print("\r\n"+Times[0][0]+" | BIP1 | MACD(BarsArray[0], 7, 14, 9).Avg[0]: "+Math.Round(MACD(BarsArray[0], 7, 14, 9).Avg[0], 5));
                            				Print(Times[1][0]+" | BIP1 | secondarySeries[0]: "+Math.Round(secondarySeries[0], 5));
                            				if (secondarySeries != null || secondarySeries.ContainsValue(0))
                            				Plot1_MTF[0] = secondarySeries[0];
                            				
                            				Print(Times[1][0]+" | BIP1 | Plot1_MTF[0]: "+Math.Round(Plot1_MTF[0], 5));
                            				
                            			}
                            Is that what you meant?
                            While secondarySeries is synchronized to the secondary series, Plot1_MTF is not.
                            thanks
                            Attached Files

                            Comment


                              #15
                              Hello Kirk,

                              Unless you have some check preventing execution in historical data, then the script is automatically going to process historical data before processing live data. (All scripts do this automatically)

                              Also, when I say that the "While secondarySeries is synchronized to the secondary series, Plot1_MTF is not." I am saying that secondarySeries is synchronized to BarsArray[1] (5 min), while Plot1_MTF is synchronized to BarsArray[0] (what ever the chart series is, 1 min based on your screenshot). They have a different number of bars.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              26 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, Yesterday, 09:53 PM
                              2 responses
                              49 views
                              0 likes
                              Last Post wzgy0920  
                              Started by Kensonprib, 04-28-2021, 10:11 AM
                              5 responses
                              191 views
                              0 likes
                              Last Post Hasadafa  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,230 views
                              0 likes
                              Last Post xiinteractive  
                              Working...
                              X