Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating a forex correlation chart with no primary instrument?

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

    Creating a forex correlation chart with no primary instrument?

    I'm using the 10 major USD-based forex pairs in an indicator script to create a correlation chart showing the correlation values of the 10 individual currencies all plotted on the same chart. First question: how do I create a new chart because I have to choose an instrument first and of course I don't want to show any instrument.

    I'm translating this from a MetaTrader script where the scripting paradigm is totally different - I've got the code written in NinjaScript now, but I just can't implement it on a chart.

    Is there some way that I could use $EURUSD and then code in the indicator that it should by default use the 9 other currency pairs as well but not show any of them, only the correlation values I calculate?

    Thanks

    #2
    Hello,

    Thank you for your note.

    Unfortunately, You have to have a primary data series for the chart.

    The creation of synthetic instruments are currently not supported in NinjaTrader.

    However what you could do is have a primary data series and then add all these 10 data series into the calculation using multi series NinjaScript and then plot this calculation in a sub panel. Alternatively you can plot this in the main panel and then change the colors of the Primary data series to Transparent thus hiding this data series and then set this to a left scale and then have your indicator plotted with a right scale in the main window. This may give you the effect your looking for.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Next question

      Thanks Brett.

      Now I know how to put it on the chart, can you tell me how to change the time frame of the other currencies that I add without having to recompile?

      This is the initialize() code where I hard-code the 5 min timeframe.

      I would like to set tthe timeframe for these added instruments based on the timeframe of the primary $EURUSD instrument that the chart shows.

      Code:
              protected override void Initialize()
              {
                  this.Overlay = true;
                  Add("$GBPUSD", PeriodType.Minute, 5);
                  Add("$AUDUSD", PeriodType.Minute, 5);
                  Add("$USDCHF", PeriodType.Minute, 5);
                  Add("$USDJPY", PeriodType.Minute, 5);
                  Add("$NZDUSD", PeriodType.Minute, 5);
                  Add("$USDCAD", PeriodType.Minute, 5);
                  Plot plotUSD = new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.Line, "USD");
                  Plot plotEUR = new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "EUR");
                  Plot plotGBP = new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "GBP");
                  Plot plotAUD = new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "AUD");
                  Plot plotCHF = new Plot(Color.FromKnownColor(KnownColor.Gray), PlotStyle.Line, "CHF");
                  Plot plotJPY = new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "JPY");
                  Plot plotNZD = new Plot(Color.FromKnownColor(KnownColor.Turquoise), PlotStyle.Line, "NZD");
                  Plot plotCAD = new Plot(Color.FromKnownColor(KnownColor.Brown), PlotStyle.Line, "CAD");
                  Add(plotUSD);
                  Add(plotEUR);
                  Add(plotGBP);
                  Add(plotAUD);
                  Add(plotCHF);
                  Add(plotJPY);
                  Add(plotNZD);
                  Add(plotCAD);
              }
      Last edited by adamus; 08-25-2010, 04:49 PM.

      Comment


        #4
        adamus, unfortunately you can't dynamically add series - you could for example setup a string input for the Bars.Period.Value field and enter as needed then to align with what you've chosen for the primary.

        Comment


          #5
          OK, I'll do it like that then - although it will have the MetaTrader fans scoring points for their platform.

          Can you put that on the list of desirable enhancements? I suspect there are major reasons why it can't be implemented for NT7 though - I'd be interested to know.

          Comment


            #6
            Thanks for the feedback - the Add() is done in the Initialize(), as there's no bars object yet here you wouldn't know the primary value until the OnStartUp() call, first OnBarUpdate() bar.

            Comment


              #7
              Hi Bertrand, I figured that one out for myself - I was wondering why the development team hasn't worked out a way for NinjaTrader to be able to access a reference to the Bars object in Initialize(). Or vice-versa, Add() in StartUp().

              Comment


                #8
                Thanks again for the feedback, I could not go into specifics unfortunately but this is the current approach, I'll forward your input so we can review it at a later stage.

                Comment


                  #9
                  adamus, try this:

                  In Variables

                  PHP Code:
                  private int barValue; 
                  
                  In Initialize()

                  PHP Code:
                  barValue = Math.Max(1, base.BarsPeriod.Value);
                  Add("$GBPUSD", BarsPeriod.Id, barValue); 
                  
                  I'd love to hear from you or the NT team why that shouldn't work as I have it in a few indis. NT7 b20.

                  Comment


                    #10
                    Originally posted by MXASJ View Post
                    PHP Code:
                    barValue = Math.Max(1, base.BarsPeriod.Value);
                    Add("$GBPUSD", BarsPeriod.Id, barValue); 
                    
                    mxasj, that seems to do it - it just takes a bit of figuring out to see whether the lines displayed correlate with the chart it's based on. Carry on pushing the envellope, man! Good move.

                    My next question is probably a lot simpler - how do I use a parameter to turn each of the lines on or off? I'm doing this in Initialize() but it has no effect.

                    Code:
                    if (showGBP) plotGBP.Pen.Color = Color.FromKnownColor(KnownColor.Transparent);
                    if (showAUD) plotAUD.Pen.Color = Color.FromKnownColor(KnownColor.Transparent);
                    if (showCHF) plotCHF.Pen.Color = Color.FromKnownColor(KnownColor.Transparent);
                    etc

                    Comment


                      #11
                      adamus I don't use charts much, so hopefully someone else can chime in.

                      Comment


                        #12
                        Hello,

                        Unfortunately variable may or may not work in Initialize() and therefor not officially supported.

                        Only recommendation I could have would be to add this logic to OnStartUp() instead of Initialize().



                        Let me know if I can be of further assistance.
                        BrettNinjaTrader Product Management

                        Comment


                          #13
                          Originally posted by adamus View Post
                          Code:
                          if (showGBP) plotGBP.Pen.Color = Color.FromKnownColor(KnownColor.Transparent);
                          if (showAUD) plotAUD.Pen.Color = Color.FromKnownColor(KnownColor.Transparent);
                          if (showCHF) plotCHF.Pen.Color = Color.FromKnownColor(KnownColor.Transparent);
                          etc
                          Brett,

                          I put this code in OnStartUp() but it doesn't have any effect there either.

                          Will this code actually change the plot, if it's in the right place? I have only limited experience with indicators.

                          showAUD, showCHF etc are parameter which I checked with Print() debug statements.

                          Comment


                            #14
                            Hello,

                            I will try this on my side later today and let you know the results as I have not had to do this yet.

                            Thank you for your patience.
                            BrettNinjaTrader Product Management

                            Comment


                              #15
                              adamus, please check into the attached, it should not plot i.e Plot color transparent as per the bool.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

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