Announcement

Collapse
No announcement yet.

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 charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          51 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          142 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          160 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 05-10-2026, 08:12 PM
          0 responses
          96 views
          0 likes
          Last Post CarlTrading  
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          275 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Working...
          X