PDA

View Full Version : Different instrument issue


ct
09-15-2007, 07:53 PM
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.

NinjaTrader_Josh
09-15-2007, 08:24 PM
Hi ct,

You need to first Add() your secondary bar object. In the initialize section you would go Add("ES 12-07", PeriodType.Minute, 5);Then in the OnBarUpdate section you can go SMA(BarsArray[1], 200)[0] > Highs[1][0] + 1 * 12.5The 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 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.if (CurrentBar == 1 && FirstTickOfBar && BarsInProgress == 1)
secondaryTickSize = TickSize;
After you have the secondary bar object's tick size you can do this instead
SMA(BarsArray[1], 200)[0] > Highs[1][0] + 1 * secondaryTickSize

ct
09-15-2007, 09:30 PM
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

NinjaTrader_Josh
09-15-2007, 09:47 PM
Sorry only way I know of is through param.

ct
09-15-2007, 09:49 PM
Josh
Thanks for the reply. At least I know there isn't a better easy way.

Regards

Cliff
New Zealand