We are having problems to get an indicator working that is loading 4 IBar input parameters using 2 periods.
Here is what we do:
public void onStart(IIndicatorContext _context) {
context = _context;
console = _context.getConsole();
InputParameterInfo inputASK = new InputParameterInfo("PriceASK", InputParameterInfo.Type.BAR);
inputASK.setOfferSide(OfferSide.ASK);
InputParameterInfo inputBID = new InputParameterInfo("PriceBID", InputParameterInfo.Type.BAR);
inputBID.setOfferSide(OfferSide.BID);
InputParameterInfo inputASKHelper = new InputParameterInfo("PriceASKHelper", InputParameterInfo.Type.BAR);
inputASKHelper.setOfferSide(OfferSide.ASK);
inputASKHelper.setPeriod(Period.ONE_MIN);
InputParameterInfo inputBIDHelper = new InputParameterInfo("PriceBIDHelper", InputParameterInfo.Type.BAR);
inputBIDHelper.setOfferSide(OfferSide.BID);
inputBIDHelper.setPeriod(Period.ONE_MIN);
indicatorInfo = new IndicatorInfo("MultiPeriodsTest", "MultiPeriodsTest", "TEST", false, false, true, 4, 0, 3);
inputParameterInfos = new InputParameterInfo[] {
inputASK, inputBID, inputASKHelper, inputBIDHelper
};
outputParameterInfos = new OutputParameterInfo[] {
new OutputParameterInfo("Out1", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
{{
setColor(Color.GREEN);
//setColor2(Color.DARKGREEN);
}},
new OutputParameterInfo("Out2", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
{{
setColor(Color.RED);
//setColor2(Color.DARKRED);
}},
new OutputParameterInfo("Out3", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
{{
setColor(Color.BLUE);
//setColor2(Color.DARKBLUE);
}}
};
}
.....
public IndicatorResult calculate(int startIndex, int endIndex) {
console.getOut().println("calculate called!");
//... calculate logic follows here...
}
.....
In the above example, as you can see, we load the ASK and BID bars of the currently selected timeframe and in addition the ASK and BID bars of a preset HELPER-timeframe (here ONE_MIN).
With this setup we experience the following indicator behaviour:
A) When the current timeframe in the chart is set to the HELPER-timeframe, calculate(int startIndex, int endIndex) is called and the code is executed as intended and the log-message "calculate called!" triggered at the start of the method is written to the output. (in this example when selected timeframe on chart is ONE_MIN)
B) When the
current timeframe in the chart is set to something other than the HELPER-timeframe (example: FIVE_MINS), the
calculate-code is not called anymore.
Best,
RR.