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

Simple Index

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

    Simple Index

    Hi, i want to create a Currency "Index", say, an EUR index, i dont know how effective will it be, just want to ask if just adding the pairs is the right approach for doing so, say:

    Add("$EURUSD", PeriodType.Day, 1);
    Add("$EURGBP", PeriodType.Day, 1);
    Add("$EURAUD", PeriodType.Day, 1);
    Add("$EURJPY", PeriodType.Day, 1);

    =================

    Index.Set( (Closes[1][0] +Closes[2][0] + Closes[3][0] + Closes[4][0] ) / 4 );

    is this the right way? thank you!

    #2
    Hello kabott,

    Thanks for your post.

    Yes, adding the instruments in the initialize() would be the correct way to add the data.

    The plotting of Index.Set however would be related to the chart's data series which you have not included in the calculation (and this may be okay, just wanted to point that out) so I would suggest adding a BarsInProgress check before the set statement to only plot when called by the chart bars. Also, you would want to perform a currentBars[] check before trying to access the data to ensure the data is there or you will generate a bar index error. I am assuming the chart bars are daily or lower.

    if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1 || CurrentBars[4] < 1) return; // do not process until at least 1 bar loaded

    if (BarsInProgress != 0) return; // only plot when chart bars call OnBarUpDate()

    Index.Set( (Closes[1][0] +Closes[2][0] + Closes[3][0] + Closes[4][0] ) / 4 );


    References:


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi, Paul, this is what ive got and nothing shows Up

      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "EUR_INDEX"));


      Add("$EURUSD", PeriodType.Day, 1);
      Add("$EURGBP", PeriodType.Day, 1);
      Add("$EURCAD", PeriodType.Day, 1);
      Add("$EURAUD", PeriodType.Day, 1);




      Overlay = true;
      CalculateOnBarClose= true;
      }


      protected override void OnBarUpdate()
      {
      if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1 || CurrentBars[4] < 1) return; // do not process until at least 1 bar loaded

      if (BarsInProgress != 0) return; // only plot when chart bars call OnBarUpDate()

      EUR_INDEX.Set( (Closes[1][0] +Closes[2][0] + Closes[3][0] + Closes[4][0] ) / 4 );

      Comment


        #4
        Hello kabott,

        Thanks for your reply.

        As your code shows, you have Overlay set to true which means the plot would be placed in the price panel. If the plot is there, it could be at a significantly different level then whatever instrument you are using on the chart's bars, so I would advise setting overlay false to place the plot in an indicator panel.

        I do not know what your chart bars are so if they are less than daily bars, you may need to increase the "days to load" as the added daily bars can only load as many days as you have specified in the charts data series. I would suggest at least 30 days of data.

        If these do not resolve the issue, please post your entire code file.

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by AveryFlynn, Today, 04:57 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Max238, Today, 01:28 AM
        4 responses
        37 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by r68cervera, Today, 05:29 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by geddyisodin, Today, 05:20 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by timko, Today, 06:45 AM
        2 responses
        14 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Working...
        X