Hello:
I am trying to create a strategy that uses the ZigZag indicator in a different data series. I did have succes creating a strat that works with no issues when having the indicator utilize the current data series, but when I try to code it so that the ZigZaig indicator uses a different series, I am getting an error. The issue is when the strat attempts to grab the indicators hi/lo bar value an error is generated indicating that there is no object referenced.
Here is an example of the code. It contains the setup and I point out the line where the error occurs. Any help is greatly appreciated.
private ZigZag zzTest; //Instantiate the variable zzTest private struct zzposclr { public int clr; public int bar; } //Create a structure type if (State == State.SetDefaults){ //BLAH //BLAH } else if (State == State.Configure) { AddDataSeries(BarsPeriodType.Minute, 5); //Add series ZigZag(BarsArray[1],DeviationType.Points, 0.5, false); //setup zigzag inputs and use it on series BarsArray[1] } protected override void OnBarUpdate() { if(State == State.Historical) return; if (CurrentBars[0] < 1) return; if(BarsInProgress!=1) return; //Only interested in dealing with series1 (5 Min TF) zzT(); //Call Function } private int zzT() { int cnt = 0; // setup counter to 0 /Instantiate peakx[] structured //initial size doesn't matter, this will be resized in loop below zzposclr[] peakx = new zzposclr[1]; for (int i = 1; i < 13; i++) // 13 bars is more than enuf. { //Get the corresponding bar values for any HIbar/LowBar results from ZigZag // THE ERROR HAPPENS AT FOLLOWING LINE// // COMPILER INDICATE THAT THERE'S NO OBJECT REFERENCED int hZZ = zzTest.HighBar(0, i, 100); //<<===ERROR HERE int lZZ = zzTest.LowBar(0, i, 100); //Populate structured peakx[] elements values. //1st resize peakx[] //2ns set Hi/Lo Peak # of Bars to peakx[].bar //3rd set Color/Direction of bar to peakx[].clr Long/Short (OP_BUY/OP_SELL); if (hZZ != -1) { Array.Resize(ref peakx, cnt+1); peakx[cnt].clr=OP_BUY; peakx[cnt].bar=hZZ; cnt++; } if (lZZ != -1) { Array.Resize(ref peakx, cnt+1); peakx[cnt].clr=OP_SELL; peakx[cnt].bar=lZZ; cnt++; } } //Sort the struct array so we get the correct order sequence //of bars that represent the LAST FOUR PEAKS/VALLEYS Array.Sort<zzposclr>(peakx, (a,b) => a.bar.CompareTo(b.bar)); //The result is a struct array that contains the last 4 ZZ peaks/valley //peakx[x].bar <== the # of bar of peak/valley stored here //peakx[x].clr <== corresponding color/directiom stored here. OP_BUY=Green OP_SELL=RED //where x= 0 to 3. The size of peakx[] is larger but we only need 4 items. }
Jess
Comment