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

Different instrument issue

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

    Different instrument issue

    I am trying to make a check on a different instrument but having some issues.

    Here is the code snippet where I perform the test on the same instrument but different time frame. It works ok.

    SMA(BarsArray[InstrumentPosition["1-Minute"]], 200)[0] > High[0] + TickSize

    I then try to add the same test for a different instrument.

    SMA(BarsArray[InstrumentPosition["ES"]], 200)[0] > Highs[2][0] + 12.5

    I also tried the following but it didn't work either:
    SMA(BarsArray[2], 200)[0] > Highs[2][0] + 1 * 12.5

    Everything compiles and runs but I get no matches.

    I had to hard code the ES ticksize because I couldn't see anyway to retrieve it.

    #2
    Hi ct,

    You need to first Add() your secondary bar object. In the initialize section you would go
    Code:
    Add("ES 12-07", PeriodType.Minute, 5);
    Then in the OnBarUpdate section you can go
    Code:
    SMA(BarsArray[1], 200)[0] > Highs[1][0] + 1 * 12.5
    The indexing of BarsArray starts at 0. 0=primary bars; 1=secondary bars; etc.

    The way you can get the TickSize of your secondary bar object is to store it in another variable. You can go
    Code:
    if (BarsInProgress == 1)
         secondaryTickSize = TickSize;
    The value of BarsInProgress works the same way the indexing of BarsArray works. Now, because you don't need to set this same variable over and over again every time the bar updates, you can limit it to do it only once.
    Code:
    if (CurrentBar == 1 && FirstTickOfBar && BarsInProgress == 1)
         secondaryTickSize = TickSize;
    After you have the secondary bar object's tick size you can do this instead
    Code:
    SMA(BarsArray[1], 200)[0] > Highs[1][0] + 1 * secondaryTickSize
    Last edited by NinjaTrader_JoshP; 09-15-2007, 08:27 PM.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh

      Thanks. I forgot NT ticked on any instrument added. I had added a 1 minute same instrument and a one minute forced to ES. I thought I had tried that syntax but call me blind. I gave what you provided a try and it worked fine.

      Here is a question good one for ya. Any good solution for changing the contract month (ES 12-07) other than through a parm.


      Cliff

      Comment


        #4
        Sorry only way I know of is through param.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh
          Thanks for the reply. At least I know there isn't a better easy way.

          Regards

          Cliff
          New Zealand

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by BarzTrading, Today, 07:25 AM
          2 responses
          25 views
          1 like
          Last Post BarzTrading  
          Started by devatechnologies, 04-14-2024, 02:58 PM
          3 responses
          20 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by tkaboris, Today, 08:01 AM
          0 responses
          4 views
          0 likes
          Last Post tkaboris  
          Started by EB Worx, 04-04-2023, 02:34 AM
          7 responses
          163 views
          0 likes
          Last Post VFI26
          by VFI26
           
          Started by Mizzouman1, Today, 07:35 AM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X