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

Converting Dollar denoted stock to Euros

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

    Converting Dollar denoted stock to Euros

    Hi,

    I am attempting to create and indicator which converts a dollar denoted stock chart to a Euro denoted stock chart. So, for each data value the value of the stock needs to be divided by the $EURUSD value at that time. To do this I need to access this value. What is the syntax to accomplish this?

    Thanks

    #2
    wachtwoord, you will have to add in an additional data series with the $EURUSD data and then use that data to divide with. This will take some custom coding.

    Please see this help guide page for how to get started - http://www.ninjatrader.com/support/h...nstruments.htm.

    Let me know if you have any other questions.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thank you, that link helped a lot. I am however still having a problem. This is my code:
      Code:
      [Description("Converts the stock price from Dollar to Euro")]
          public class EuroConvertor : Indicator
          {
              #region Variables
              // Wizard generated variables
                  private int myInput0 = 1; // Default setting for MyInput0
              // User defined variables (add any user defined variables below)
              #endregion
      
              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
                  Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                  Overlay                = true;            
                  Add("$EURUSD", PeriodType.Day, 1);
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.             
                  Plot0.Set(Close[0]/Closes[1][0]);            
              }
      The error message it gives is:
      Code:
         Error   on calling 'OnBarUpdate' method for indicator 'EuroConvertor' on bar 0: You   are accessing an index with a value that is invalid since its out of range.   I.E. accessing a series [barsAgo] with a value of 5 when there are only 4   bars on the chart.
      when I try it with the ticker itself (so MSFT if I have selected MSFT) it works and gives a nice straight line at one like expected.

      What am I doing wrong?

      (and ps: how can I access a console so I can print some message for myself to debug?)

      Thanks again

      Comment


        #4
        wachtwoord, please try adding this line of code to the top of your script:
        Code:
        if (CurrentBar < 2)
        return;
        Usually, this error occurs when you're checking bar values x amount of bars ago, like Close[1]. As the script runs through the bars, this would yield an exception for the very first bar because Close[1] doesn't exist yet.

        The above check will skip over the first few bars so this error doesn't occur.

        As for the console, you can get to the print window by going to Tools -> Output Window and use the Print() method to send output to that window.

        Please let me know if you have any other questions.
        AustinNinjaTrader Customer Service

        Comment


          #5
          I have never been able to get this working. Adding that line of code does not change the behavior of the indicator.

          Does anyone have a clue how to get this working? Getting it working outside of Ninja Trader is fine too. I just want to see US stock quotes denoted in Euro's....

          Comment


            #6
            Hello,

            This should produce the results you are looking for

            Code:
            if(CurrentBars[1] < 1)
              return;
            			
            if(BarsInProgress == 0)
              {			
              Plot0.Set(Close[0]/Closes[1][0]);       
              }
            We use CurrentBars[1] to check that we have enough Daily data for the EUR/USD to calculate.

            Then we also use a BarsInProgress check to ensure that the plot is updating on the primary data series.
            MatthewNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by lorem, Yesterday, 09:18 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by WHICKED, Today, 12:56 PM
            2 responses
            15 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by Felix Reichert, Today, 02:12 PM
            0 responses
            1 view
            0 likes
            Last Post Felix Reichert  
            Started by Tim-c, Today, 02:10 PM
            0 responses
            1 view
            0 likes
            Last Post Tim-c
            by Tim-c
             
            Started by cre8able, Today, 01:16 PM
            2 responses
            9 views
            0 likes
            Last Post cre8able  
            Working...
            X