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

Exposing a Plot Variable

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

    Exposing a Plot Variable

    Hi, I wonder if someone could help me with a problem.

    I'm developing an indicator for a 1 tick forex chart, which needs access to bid and ask data, and their time stamps.

    I've used OnMarketData(MarketDataEventArgs marketDataUpdate) in a separate timestamp indicator, but I'm using separate instances with different input series (ask and bid). (hopefully later just one).

    I've noticed that using last as the input series gives me the timestamp for both ask and bid, so I'm wondering how i can access this plot variable in the new indicator.

    There is probably a more effective way to access these four pieces of data, but I'm still learning!

    Thanks in advance
    I'm using NT8.

    #2
    Hello Rastus,

    Thanks for your post and welcome to the forums.

    You can add the dataseries of Ask values and of Bid values and access them directly. Please see: http://ninjatrader.com/support/helpG...dataseries.htm

    Using the syntax of AddDataSeries(string instrumentName, BarsPeriodType periodType, int period, MarketDataType marketDataType)
    For example:
    AddDataSeries("EURUSD", BarsPeriodType.Tick, 1, MarketDataType.Ask);
    AddDataSeries("EURUSD", BarsPeriodType.Tick, 1, MarketDataType.Bid);
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      Thankyou for your reply.
      I've been testing your example with
      Plot1
      [1] = Closes[1][1];

      So I can see that it works fine when the DataSeriesIndex (1) is the same as the input series(ask). But not if I change the input series.

      I think I'm confused by the input series thing.

      I need to access both ask and bid, but for now I can only access either, but not both.

      Thankyou.

      Comment


        #4
        Hello Rastus,

        Thanks for your reply.

        This line: Plot1[1] = Closes[1][1]; would put the previous bar of the 1st added dataseries into the previous plot location.

        You may want to review the helpguide section that covers multi time frame/series coding: http://ninjatrader.com/support/helpG...nstruments.htm

        To better assist, if possible, please post your full code.

        Alternatively, if you would prefer to not post in public you are welcome to e-mail your code to PlatformSupport[at]NinjaTrader[dot]Com. Please make the e-mail Atten:Paul and a link to this thread.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          I can see the same issue with plotting on the [0] bar as well.
          Here is my code, and a screenshot of the 'problem'.

          In case it affects your answer, what I'm trying to do, is use the ask and bid prices and their timestamps in the same indicator. It seems the Input Series is key to obtaining the correct data.

          Thankyou.

          Code:
           
          public class A1 : Indicator
          {
           
           
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = "My Indicator";
          Name = "A1";
          IsOverlay = false;
          IsSuspendedWhileInactive = true;
           
           
           
          AddPlot(Brushes.Red, "Plot0");
          AddPlot(Brushes.Blue, "Plot1");
           
          }
          else if (State == State.Configure)
          {
           
          AddDataSeries("GBPUSD", BarsPeriodType.Tick, 1, MarketDataType.Ask);
          AddDataSeries("GBPUSD", BarsPeriodType.Tick, 1, MarketDataType.Bid); 
          }
          }
           
           
           
          protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
          { 
           
          Plot0[0] = Closes[1][0];
          Plot1[0] = Closes[2][0];
           
          }
           
          protected override void OnBarUpdate()
          {
           
          }
          Attached Files

          Comment


            #6
            Hello Rastus,

            Thanks for your reply.

            I would advise moving your plot statements into the OnBarUpdate() method. Please note that the OnBarUpdate() method will be called by each data series (chart bars plus Bid plus Ask) and you may want to segment your coding according to the BarsInProgress. (The BarsInProgress is discussed in the multi time frame link previously provided).
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thanks Paul,

              Its all coming together now.

              Comment


                #8
                Hi Paul,

                I spoke too soon.
                I've been experimenting with the OnBarUpdate by plotting the ask (and bid) prices. But I still cant get it to match the input series. It looks like its skipping some ticks?

                Code:
                [COLOR=#0000ff]public[/COLOR][COLOR=#0000ff]class[/COLOR][COLOR=#080808]A1[/COLOR][COLOR=#000000] : [/COLOR][COLOR=#080808]Indicator[/COLOR]
                {
                 
                 
                [COLOR=#0000ff]private[/COLOR] [COLOR=#080808]Series[/COLOR]<[COLOR=#0000ff]double[/COLOR]> [COLOR=#080808]askSeries[/COLOR];
                 
                 
                [COLOR=#0000ff]protected[/COLOR] [COLOR=#0000ff]override[/COLOR] [COLOR=#0000ff]void[/COLOR] [COLOR=#080808]OnStateChange[/COLOR]()
                {
                [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]State[/COLOR] == [COLOR=#080808]State[/COLOR].[COLOR=#080808]SetDefaults[/COLOR])
                {
                [COLOR=#080808]Description[/COLOR] = [COLOR=#b22222]"My Indicator"[/COLOR];
                [COLOR=#080808]Name[/COLOR] = [COLOR=#b22222]"A1"[/COLOR];
                [COLOR=#080808]IsOverlay[/COLOR] = [COLOR=#0000ff]false[/COLOR];
                [COLOR=#080808]IsSuspendedWhileInactive[/COLOR] = [COLOR=#0000ff]true[/COLOR];
                 
                [COLOR=#080808]AddPlot[/COLOR]([COLOR=#080808]Brushes[/COLOR].[COLOR=#080808]Red[/COLOR], [COLOR=#b22222]"Plot0"[/COLOR]);
                 
                }
                [COLOR=#0000ff]else[/COLOR] [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]State[/COLOR] == [COLOR=#080808]State[/COLOR].[COLOR=#080808]Configure[/COLOR])
                {
                 
                [COLOR=#080808]askSeries[/COLOR] = [COLOR=#0000ff]new[/COLOR] [COLOR=#080808]Series[/COLOR]<[COLOR=#0000ff]double[/COLOR]>([COLOR=#0000ff]this[/COLOR], [COLOR=#080808]MaximumBarsLookBack[/COLOR].[COLOR=#080808]Infinite[/COLOR]);
                 
                [COLOR=#080808]AddDataSeries[/COLOR]([COLOR=#b22222]"GBPUSD"[/COLOR], [COLOR=#080808]BarsPeriodType[/COLOR].[COLOR=#080808]Tick[/COLOR], [COLOR=#ff8c00]1[/COLOR], [COLOR=#080808]MarketDataType[/COLOR].[COLOR=#080808]Ask[/COLOR]);
                 
                }
                }
                 
                 
                [COLOR=#0000ff]protected[/COLOR] [COLOR=#0000ff]override[/COLOR] [COLOR=#0000ff]void[/COLOR] [COLOR=#080808]OnBarUpdate[/COLOR]()
                { 
                [COLOR=#0000ff]if[/COLOR]([COLOR=#080808]BarsInProgress[/COLOR] == [COLOR=#ff8c00]1[/COLOR])
                [COLOR=#0000ff]return[/COLOR];
                 
                [COLOR=#0000ff]if[/COLOR]([COLOR=#080808]BarsInProgress[/COLOR] == [COLOR=#ff8c00]0[/COLOR]) 
                {
                [COLOR=#080808]askSeries[/COLOR][[COLOR=#ff8c00]0[/COLOR]] = [COLOR=#080808]Closes[/COLOR][[COLOR=#ff8c00]1[/COLOR]][[COLOR=#ff8c00]0[/COLOR]];
                [COLOR=#080808]Plot0[/COLOR][[COLOR=#ff8c00]0[/COLOR]] = [COLOR=#080808]askSeries[/COLOR][[COLOR=#ff8c00]0[/COLOR]];
                }
                 
                 
                }
                Attached Files

                Comment


                  #9
                  Its me again Paul

                  I've put this together, and it seems to be working fine.

                  I suppose the trial and error method, and searching the forums eventually works.

                  (EDIT: I think Update-every-tick, made the difference)

                  Code:
                  [COLOR=#0000ff]protected[/COLOR][COLOR=#0000ff]override[/COLOR][COLOR=#0000ff]void[/COLOR][COLOR=#080808]OnBarUpdate[/COLOR][COLOR=#000000]()[/COLOR]
                  { 
                  [COLOR=#0000ff]if[/COLOR]([COLOR=#080808]CurrentBars[/COLOR][[COLOR=#ff8c00]0[/COLOR]] < [COLOR=#ff8c00]2[/COLOR])
                  [COLOR=#0000ff]return[/COLOR];
                   
                   
                  [COLOR=#0000ff]if[/COLOR]([COLOR=#080808]BarsInProgress[/COLOR] == [COLOR=#ff8c00]1[/COLOR] || [COLOR=#080808]BarsInProgress[/COLOR] == [COLOR=#ff8c00]2[/COLOR])
                  [COLOR=#0000ff]return[/COLOR];
                   
                   
                  [COLOR=#0000ff]if[/COLOR]([COLOR=#080808]BarsInProgress[/COLOR] == [COLOR=#ff8c00]0[/COLOR]) 
                  {
                  [COLOR=#0000ff]if[/COLOR]([COLOR=#080808]Closes[/COLOR][[COLOR=#ff8c00]1[/COLOR]][[COLOR=#ff8c00]0[/COLOR]] == [COLOR=#ff8c00]0[/COLOR])
                  [COLOR=#080808]askSeries[/COLOR][[COLOR=#ff8c00]0[/COLOR]] = [COLOR=#080808]askSeries[/COLOR][[COLOR=#ff8c00]1[/COLOR]];
                  [COLOR=#0000ff]else[/COLOR]
                  [COLOR=#080808]askSeries[/COLOR][[COLOR=#ff8c00]0[/COLOR]] = [COLOR=#080808]Closes[/COLOR][[COLOR=#ff8c00]1[/COLOR]][[COLOR=#ff8c00]0[/COLOR]];
                   
                  [COLOR=#0000ff]if[/COLOR]([COLOR=#080808]Closes[/COLOR][[COLOR=#ff8c00]2[/COLOR]][[COLOR=#ff8c00]0[/COLOR]] == [COLOR=#ff8c00]0[/COLOR])
                  [COLOR=#080808]bidSeries[/COLOR][[COLOR=#ff8c00]0[/COLOR]] = [COLOR=#080808]bidSeries[/COLOR][[COLOR=#ff8c00]1[/COLOR]];
                  [COLOR=#0000ff]else[/COLOR]
                  [COLOR=#080808]bidSeries[/COLOR][[COLOR=#ff8c00]0[/COLOR]] = [COLOR=#080808]Closes[/COLOR][[COLOR=#ff8c00]2[/COLOR]][[COLOR=#ff8c00]0[/COLOR]];
                   
                   
                  [COLOR=#080808]Plot0[/COLOR][[COLOR=#ff8c00]0[/COLOR]] = [COLOR=#080808]askSeries[/COLOR][[COLOR=#ff8c00]0[/COLOR]];
                  [COLOR=#080808]Plot1[/COLOR][[COLOR=#ff8c00]0[/COLOR]] = [COLOR=#080808]bidSeries[/COLOR][[COLOR=#ff8c00]0[/COLOR]];
                  }
                  }
                  Last edited by Rastus; 02-15-2017, 07:43 PM.

                  Comment


                    #10
                    Hello,

                    Is that possible as of today's version to have the variables exposed with the real variable name (instead of plot0, plot1...)

                    If so, can you give us an example of how to make it please?

                    Thanks!

                    Comment


                      #11
                      Hello roblogic,

                      Public variables can be used to expose values to another NinjaScript without using Plots. We have a publicly available example called SampleBoolSeries that shows various ways to expose variables. I have provided a link below.

                      SampleBoolSeries - https://ninjatrader.com/support/help...alues_that.htm

                      Please let us know if you have any additional questions.
                      JimNinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Jim,

                        I downloaded the sample file you provided but I am still unable to access the "exposedvariable" of the sample from a Strategy.

                        Ideally I would like to have the "exposedvariable" value from the Strategy Builder when calling the indicator. Can this be done? Now I do that with plots, and I can access the the variables from the Stragegy Builder, but the names are plot0, plot1, plot2... which is not very handy when there are many exposed variables...

                        If it's not possible to call the "exposedvariable" from the Stragy Builder, how can I call it from the NS Editor?

                        Comment


                          #13
                          Hello roblogic,

                          The Strategy Builder is designed to use plots and cannot create syntax for accessing other public variables. The example from post #11 will show you how to create exposed variables in an indicator and access them from a strategy. This would involve using the NinjaScript Editor.

                          If you are simply trying to customize the Plot names, I would consider following how our included indicators create plots as they have custom names in the Strategy Builder.

                          For example in the MACD indicator, 3 plots are exposed and used in the script as follows:

                          Code:
                          [Browsable(false)]
                          [XmlIgnore]
                          public Series<double> Avg
                          {
                              get { return Values[1]; }
                          }
                          
                          [Browsable(false)]
                          [XmlIgnore]
                          public Series<double> Default
                          {
                              get { return Values[0]; }
                          }
                          
                          [Browsable(false)]
                          [XmlIgnore]
                          public Series<double> Diff
                          {
                              get { return Values[2]; }
                          }
                          I look forward to being of any further assistance.
                          JimNinjaTrader Customer Service

                          Comment


                            #14
                            Thanks Jim for the detailed information!. It works like a charm now!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by yertle, Yesterday, 08:38 AM
                            7 responses
                            28 views
                            0 likes
                            Last Post yertle
                            by yertle
                             
                            Started by bmartz, 03-12-2024, 06:12 AM
                            2 responses
                            21 views
                            0 likes
                            Last Post bmartz
                            by bmartz
                             
                            Started by funk10101, Today, 12:02 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post funk10101  
                            Started by gravdigaz6, Yesterday, 11:40 PM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by MarianApalaghiei, Yesterday, 10:49 PM
                            3 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X