Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- RiskManager.java
- version 1.0
- Copyright 2010 Quantisan.com
- */
- package jforex;
- import java.math.*;
- import com.dukascopy.api.*;
- public class RiskManager implements IStrategy {
- private IEngine engine;
- private IConsole console;
- private IContext context;
- private double maxEquity = 0;
- private double[] lot = new double[Instrument.values().length];
- @Configurable("Max. Drawdown Percentage [2%]")
- public double riskPct = 2.0;
- public void onStart(IContext context) throws JFException {
- this.engine = context.getEngine();
- this.console = context.getConsole();
- this.context = context;
- }
- public void onAccount(IAccount account) throws JFException {
- double equity, lossPct;
- equity = account.getEquity();
- if (equity > maxEquity) {
- maxEquity = equity;
- return;
- }
- lossPct = (equity - this.maxEquity) / this.maxEquity * 100.0;
- if (lossPct < (-1.0 * riskPct)) {
- console.getOut().println("Max. drawdown reached! Stopping strategy!");
- this.context.stop();
- }
- }
- 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 {
- }
- }
Add Comment
Please, Sign In to add comment