Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible to open chart from from inside a custom indicator script?

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

    Is it possible to open chart from from inside a custom indicator script?

    Hi,

    I am new to ninja script. Is it possible to open chart window from another instrument from an indicator which is already loaded on to a different chart?

    e.g. I have a chart open for EURUSD and my indicator is on it based on some calculation I would like to open GBPUSD and load my indicator on that chart as well..

    Regards
    Azhar

    #2
    Hello azh_ali,

    Thanks for your first post and welcome to the NinjaTrader forums!

    Yes, you can add your indicator to any chart you wish. The platform actually makes a copy of your indicator for instance of use so while your indicator is on one chart it can be used on other charts and with different settings as each instance is unique and does not affect the performance of the other instances.


    Comment


      #3
      Thanks for the reply Paul.

      You misunderstood me. I know you can add the indicators on any chart you want. My question was regarding the Ninja Trader API.

      I have developed an indicator which I have loaded onto the chart. All working fine. My indicator is doing some calculation and based on the result I would like to open a different chart of another instrument and also load my custom indicator on it. I want to do this all automated using the NinjaScript code without any human intervention.

      Is that possible?

      Regards
      Azhar

      Comment


        #4
        Hello azh_ali,

        Thanks for your reply.

        Yes, i misunderstood.

        There is no means to create a chart from an indicator.

        Comment


          #5
          Hi Paul,

          While I was waiting for a reply. I have found you can add more than one series to a chart from another instrument which will also serve the purpose for me but I am having some issue regarding how the calculation is working.
          Here is an example.


          I have a Chart for GBPUSD of 1 second. I added another series onto the same chart using my indicator like below:

          Code:
          else if (State == State.Configure)
          {
          AddDataSeries("GBPUSD",BarsPeriodType.Tick, 720);
          }
          OnBarUpdate function I checking some values

          Code:
          if(BarsInProgress ==0){
          double v1 = WilliamsR(180)[0];
          double v2 = WilliamsR(720)[0];
          
          if(BarsInProgress ==1){
          double v3 = WilliamsR(BarsArray[1], 180)[0];
          double v4 = WilliamsR(BarsArray[1], 720)[0];
          }}
          Any idea why v3 and v4 returns the same value when BarInProgress = 1? whereas when BarInProgress == 0 they return different value?
          Now occasionally they can return the same value but I am getting them same in every single update.

          Regards
          Azhar

          Comment


            #6
            Hello azh_ali,

            Thanks for your reply.

            It looks like you have embedded BarsInPrpogress == 1 inside of a check for BasrInProgress == 0.

            if(BarsInProgress ==0)
            {
            double v1 = WilliamsR(180)[0];
            double v2 = WilliamsR(720)[0];

            if(BarsInProgress ==1)
            {
            double v3 = WilliamsR(BarsArray[1], 180)[0];
            double v4 = WilliamsR(BarsArray[1], 720)[0];
            }
            }



            I would suggest separating them:

            if(BarsInProgress ==0)
            {
            double v1 = WilliamsR(180)[0];
            double v2 = WilliamsR(720)[0];
            }

            if(BarsInProgress ==1)
            {
            double v3 = WilliamsR(BarsArray[1], 180)[0];
            double v4 = WilliamsR(BarsArray[1], 720)[0];
            }

            Comment


              #7
              thanks for the reply. They are separate that was a typo in the forum post.

              Comment


                #8
                Hello azh_ali,

                Thanks for your reply.

                Do you have CurrentBars check in place before assigning the doubles? If so what is it set to?

                Comment


                  #9
                  Here is the full code of the indicator. I added the indicator on GBPUSD tick chart.
                  Code:
                  public class TestIndicator : Indicator
                  {[INDENT]protected override void OnStateChange()[/INDENT][INDENT]{[/INDENT][INDENT=2]if (State == State.SetDefaults)
                  {[/INDENT][INDENT=3]Description = @"Enter the description for your new custom Indicator here.";
                  Name = "TestIndicator";
                  Calculate = Calculate.OnPriceChange;
                  IsOverlay = false;
                  DisplayInDataBox = true;
                  DrawOnPricePanel = true;
                  DrawHorizontalGridLines = true;
                  DrawVerticalGridLines = 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;[/INDENT][INDENT=2]}
                  else if (State == State.Configure)
                  {[/INDENT][INDENT=3]AddDataSeries("GBPUSD",BarsPeriodType.Tick, 720);[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT][INDENT]protected override void OnBarUpdate()
                  {[/INDENT][INDENT=2]if (State == State.Realtime)
                  {[/INDENT][INDENT=3]if (BarsInProgress == 0)
                  {[/INDENT][INDENT=4]double v1 = WilliamsR(180)[0];
                  double v2 = WilliamsR(720)[0];
                  Print(string.Format("First Bar v1 = {0} ", v1));
                  Print(string.Format("First Bar v2 = {0} ", v2));[/INDENT][INDENT=3]}
                  
                  if (BarsInProgress == 1)
                  {[/INDENT][INDENT=4]double v3 = WilliamsR(BarsArray[1], 180)[0];
                  double v4 = WilliamsR(BarsArray[1], 720)[0];
                  Print(string.Format("Second Bar v3 = {0} ", v3));
                  Print(string.Format("Second Bar v4 = {0} ", v4));[/INDENT][INDENT=3]}
                  //Add your custom indicator logic here.[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT]
                   
                  
                  }
                  Code:
                  Sample Output
                  First Bar v1 = -34.0909090909309
                  First Bar v2 = -24.5901639344417
                  Second Bar v3 = -28.0478683620053
                  Second Bar v4 = -28.0478683620053
                  
                  First Bar v1 = -31.8181818181887
                  First Bar v2 = -22.9508196721359
                  Second Bar v3 = -27.9730740463728
                  Second Bar v4 = -27.9730740463728
                  
                  First Bar v1 = -27.2727272727548
                  First Bar v2 = -19.6721311475607
                  Second Bar v3 = -27.8234854151095
                  Second Bar v4 = -27.8234854151095
                  You can see v3 and v4 are always same whereas v1 and v2 are not. Not sure why.

                  Comment


                    #10
                    Hello azh_ali,

                    Thanks for your reply.

                    You said, "I added the indicator on GBPUSD tick chart.". I thought you said earlier that you were applying to a 1 second chart.

                    Can you confirm what is the chart you are applying the indicator to and the bar settings you are using.

                    Comment


                      #11
                      Sorry indicator was added on the GBPUSD 1 second chart.

                      Comment


                        #12
                        Hello azh_ali,

                        Thanks for your reply.

                        Using this code and applying to a 1 second chart:

                        else if (State == State.Configure)
                        {
                        AddDataSeries(Data.BarsPeriodType.Tick, 720);
                        }
                        }

                        protected override void OnBarUpdate()
                        {

                        if (State != State.Realtime) return;

                        if(BarsInProgress ==0)
                        {
                        double v1 = WilliamsR(180)[0];
                        double v2 = WilliamsR(720)[0];
                        Print ("V1: "+v1+" "+"V2: "+v2);
                        }

                        if(BarsInProgress ==1)
                        {
                        double v3 = WilliamsR(BarsArray[1], 180)[0];
                        double v4 = WilliamsR(BarsArray[1], 720)[0];
                        Print ("V3: "+v3+" "+"V4: "+v4);
                        }
                        }


                        I also created a chart with both data series and applied the 4 instances of the WilliamsR as sometimes you need to see what is happening.

                        Click image for larger version

Name:	azh_ali-1.PNG
Views:	311
Size:	114.5 KB
ID:	1156976

                        You do see that the higher time frame (720 tick) is changing but it does not change as much as the 1 second and this would be expected.



                        Comment


                          #13
                          First of all thank you for taking time and helping me here.
                          Secondly, I would like to apologise for a mistake in the code I posted. I have added the indicator on GBPUSD 1 second chart and second series is also GBPUSD 1 second. Its for testing only so I can compare the results but in reality second series will be a different instrument.

                          else if (State == State.Configure)
                          {
                          AddDataSeries(Data.BarsPeriodType.Second, 720);
                          }


                          So after fixing that in my code. I now see slightly different values between V3 and V4 but they differ alot from V1 and V2 and I want to know why that is. I also also checked number of CurrentBars and for some reason CurrentBars[1] is always 443. See my output. If not identical they should be pretty close to each other. No?

                          Click image for larger version

Name:	Capture6.PNG
Views:	322
Size:	1,008.1 KB
ID:	1156986​​


                          Comment


                            #14
                            Hello azh_ali,

                            Thanks for your reply.

                            If I understand correctly, you are applying the indicator to a 1 second chart and you are adding now a 720 second data series?

                            If that is the case, just like the 720 tick series I would expect the slower time frame to have different values that are slower to change.

                            Comment


                              #15
                              Hi Paul,

                              Thanks for recent comment. I feel stupid now. Yes i was adding 720 sec series where I thought 720 was number of bars to load. Don't know what I was thinking. All sorted now and values match exactly.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              563 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              329 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              547 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              547 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X