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

Need Help with Indicator

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

    Need Help with Indicator

    Hi,

    I'm trying to develop a variant of the ratio indicator (attached). The modifications I need are for it to be able to:

    1. Enter my own multiples for each security so the baseline is 1 initially, and the ratio deviates from this amount. For example, if SPY is $200 and QQQ is $100, I want to be able to assign a multiple of 2 to QQQ so the initial ratio is 1. I know how to do this.

    2. However, I also want the multiple to be recalculated and the ratio reset every EOD. To achieve this, within the OnBarUpdate() function, I'd like to have a "If New Day... Then... Recalculate The Multiplier" using yesterday's closes for both securities.

    Would an if(Bars.FirstBarofSession) work here?

    3. Where I'm really stuck though is in getting the previous closes for both securities. I'm new to NT and have no clue how to deal with two securities in one script. If it was just one security, I guess this could be done:

    lastclose1 = Bars.GetDayBar(1).Close

    How would I get the closing price of the second security though?

    Any help will be much appreciated. Thanks in advance!
    Attached Files

    #2
    Problem solved! Disregard this.

    Got the second problem fixed by using an if (Bars.FirstBarOfSession && Bars.SessionBreak) and it seems to work.

    With the third, I declared two data series using Add(SPY, BarsPeriods...) and then am calling the previous days closing values using Closes[0/1][1].

    Comment


      #3
      wuilengh,

      1. Enter my own multiples for each security so the baseline is 1 initially, and the ratio deviates from this amount. For example, if SPY is $200 and QQQ is $100, I want to be able to assign a multiple of 2 to QQQ so the initial ratio is 1. I know how to do this.

      I would first suggest learning about multi-series scripts here as you can construct these ratios from the prices of both instruments.

      2. However, I also want the multiple to be recalculated and the ratio reset every EOD. To achieve this, within the OnBarUpdate() function, I'd like to have a "If New Day... Then... Recalculate The Multiplier" using yesterday's closes for both securities.

      Would an if(Bars.FirstBarofSession) work here? <--- -Yes, this would work.

      3. Where I'm really stuck though is in getting the previous closes for both securities. I'm new to NT and have no clue how to deal with two securities in one script. If it was just one security, I guess this could be done:

      There is a sample of a multi-instrument strategy that comes with NinjaTrader. You can find it in Tools > Edit NinjaScript > SampleMultiInstrument.

      You can also read more here : http://www.ninjatrader.com/support/h...nstruments.htm
      Adam P.NinjaTrader Customer Service

      Comment


        #4
        Adam,

        Just a quick follow up regarding Bars.FirstOfSession. Does this still trigger if I'm late for the open (say 9:38 for US equities) and launch my strategy/indicator after then?

        Comment


          #5
          wuilengh,

          I don't believe that is the case. It would only return true if its the first bar of the session. What are you trying to accomplish with it?

          Please note that indicators / strategies will iterate over historical bars all the way to the present bar. This first bar of session would still return true on historical bars I believe.
          Adam P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sastrades, 01-31-2024, 10:19 PM
          13 responses
          203 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by reynoldsn, Today, 04:40 PM
          0 responses
          4 views
          0 likes
          Last Post reynoldsn  
          Started by Philippe56140, 04-27-2024, 02:35 PM
          6 responses
          54 views
          0 likes
          Last Post bltdavid  
          Started by ETFVoyageur, Yesterday, 06:05 PM
          7 responses
          45 views
          0 likes
          Last Post ETFVoyageur  
          Started by betsuni_123, Today, 04:20 PM
          0 responses
          12 views
          0 likes
          Last Post betsuni_123  
          Working...
          X