Hello,
I was trying to draw pivot without other values and more importantly period separator from within my code.
Please, consider the following strategy :
package jforex;
import java.awt.Color;
import com.dukascopy.api.Configurable;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IChart;
import com.dukascopy.api.IChartObject;
import com.dukascopy.api.IChartPanel;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.IUserInterface;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.IndicatorInfo;
import com.dukascopy.api.indicators.OutputParameterInfo.DrawingStyle;
public class PivotEx implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
private IChart chart;
private IIndicator fourHoursPivot;
@Configurable("Show")
public boolean showEx = true;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
this.userInterface = context.getUserInterface();
chart = context.getChart(context.getSubscribedInstruments().iterator().next());
fourHoursPivot = indicators.getIndicator("PIVOT");
fourHoursPivot.setOptInputParameter(0, Period.FOUR_HOURS);
fourHoursPivot.setOptInputParameter(1, true);
printIndicatorInfos(fourHoursPivot);
if (showEx) {
chart.add(fourHoursPivot, new Object[] { Period.FOUR_HOURS, true },
new Color[]{ Color.GREEN, Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(),
Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(),
Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.brighter()},
new DrawingStyle[] { DrawingStyle.LINE, DrawingStyle.NONE, DrawingStyle.NONE, DrawingStyle.NONE,
DrawingStyle.NONE, DrawingStyle.NONE, DrawingStyle.NONE, DrawingStyle.NONE, DrawingStyle.NONE,
DrawingStyle.NONE, DrawingStyle.NONE, DrawingStyle.NONE, DrawingStyle.NONE, DrawingStyle.NONE},
new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
} else {
chart.add(fourHoursPivot, new Object[] { Period.FOUR_HOURS, true },
new Color[]{ Color.GREEN, Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(),
Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(),
Color.GREEN.darker(), Color.GREEN.darker(), Color.GREEN.darker(), Color.BLUE.darker() },
new DrawingStyle[] { DrawingStyle.LINE },
new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
}
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
chart.removeIndicator(fourHoursPivot);
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
private void printIndicatorInfos(IIndicator ind){
IndicatorInfo info = ind.getIndicatorInfo();
context.getConsole().getOut().println(String.format("%s: input count=%s, optional input count=%s, output count=%s",
info.getTitle(), info.getNumberOfInputs(), info.getNumberOfOptionalInputs(), info.getNumberOfOutputs()));
for (int i = 0; i < ind.getIndicatorInfo().getNumberOfInputs(); i++){
context.getConsole().getOut().println(String.format("Input %s: %s - %s", i, ind.getInputParameterInfo(i).getName(), ind.getInputParameterInfo(i).getType()));
}
for (int i = 0; i < ind.getIndicatorInfo().getNumberOfOptionalInputs(); i++){
context.getConsole().getOut().println(String.format("Opt Input %s: %s - %s", i, ind.getOptInputParameterInfo(i).getName(), ind.getOptInputParameterInfo(i).getType()));
}
for (int i = 0; i < ind.getIndicatorInfo().getNumberOfOutputs(); i++){
context.getConsole().getOut().println(String.format("Output %s: %s - %s", i, ind.getOutputParameterInfo(i).getName(), ind.getOutputParameterInfo(i).getType()));
}
}
}
The exception thrown
Exception in drawOutput method: java.lang.IllegalArgumentException: null Stroke @ com.dukascopy.indicators.PivotIndicator.doDrawOutput(PivotIndicator.java:575)
Thank you