Hi. I tried use ITesterExecutionControl function in my strategy code but something is wrong.
This function not working. I want to use this
https://www.dukascopy.com/client/javado ... ntrol.html and play / pause strategy from my own button.
How to put this strategy controller to my own buttons?
Yes, I can use context.pause() but how to control this function and play again in my function pause_play_btn_event()
This is my little code
package jforex;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.concurrent.Callable;
import com.dukascopy.api.*;
import com.dukascopy.api.system.tester.*;
import com.dukascopy.api.drawings.ICustomWidgetChartObject;
public class myStrategy_errorTester implements IStrategy, ITesterExecution {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
private IChart chart;
private ITesterExecutionControl executionControl = null;
JButton btn = new JButton(" test ");
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();
this.chart = context.getChart(Instrument.EURUSD);
ICustomWidgetChartObject obj = chart.getChartObjectFactory().createChartWidget();
obj.setFillOpacity(0.3f);
obj.setColor(Color.BLACK.darker());
JPanel panel = obj.getContentPanel();
panel.setLayout(null);
btn.setAlignmentX(Component.CENTER_ALIGNMENT);
btn.setBounds(20, 20, 120, 30);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
pause_play_btn_event();
} catch (Exception ex) {
// print error
}
}
});
panel.add(Box.createRigidArea(new Dimension(0,5)));
panel.add(btn);
panel.setSize(new Dimension(160, 160));
panel.setMinimumSize(new Dimension(160, 160));
panel.setMaximumSize(new Dimension(160, 160));
chart.add(obj);
}
@Override
public void setExecutionControl(ITesterExecutionControl executionControl) {
this.executionControl = executionControl;
}
private boolean _pause = false;
private int click = 0;
public void pause_play_btn_event() throws JFException {
if (click == 0) {
click = 1;
btn.setText(" Play ");
if (_pause == false) {
//context.pause();
print( 1 );
executionControl.pauseExecution();
_pause = true;
}
} else if (click == 1) {
click = 0;
_pause = false;
print( 2 );
btn.setText(" Pause ");
}
}
public void onAccount(IAccount account) throws JFException {}
public void onMessage(IMessage message) throws JFException {}
public void onStop() throws JFException {}
public void onTick(Instrument instrument, ITick tick) throws JFException {}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
public void print(Object o) {
console.getOut().println( o );
}
}
How does it looks like... I used ChartWidget.
