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 Radano, 06-10-2021, 01:40 AM
          19 responses
          606 views
          0 likes
          Last Post Radano
          by Radano
           
          Started by KenneGaray, Today, 03:48 AM
          0 responses
          4 views
          0 likes
          Last Post KenneGaray  
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          470 views
          0 likes
          Last Post tradingnasdaqprueba  
          Started by aa731, Today, 02:54 AM
          0 responses
          5 views
          0 likes
          Last Post aa731
          by aa731
           
          Started by Christopher_R, Today, 12:29 AM
          0 responses
          11 views
          0 likes
          Last Post Christopher_R  
          Working...
          X