Guest User

Untitled

a guest
Oct 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. /*
  2. RiskManager.java
  3. version 1.0
  4. Copyright 2010 Quantisan.com
  5. */
  6.  
  7. package jforex;
  8.  
  9. import java.math.*;
  10.  
  11. import com.dukascopy.api.*;
  12.  
  13. public class RiskManager implements IStrategy {
  14. private IEngine engine;
  15. private IConsole console;
  16. private IContext context;
  17.  
  18. private double maxEquity = 0;
  19. private double[] lot = new double[Instrument.values().length];
  20.  
  21. @Configurable("Max. Drawdown Percentage [2%]")
  22. public double riskPct = 2.0;
  23.  
  24. public void onStart(IContext context) throws JFException {
  25. this.engine = context.getEngine();
  26. this.console = context.getConsole();
  27. this.context = context;
  28.  
  29. }
  30.  
  31. public void onAccount(IAccount account) throws JFException {
  32. double equity, lossPct;
  33.  
  34. equity = account.getEquity();
  35.  
  36. if (equity > maxEquity) {
  37. maxEquity = equity;
  38. return;
  39. }
  40.  
  41. lossPct = (equity - this.maxEquity) / this.maxEquity * 100.0;
  42. if (lossPct < (-1.0 * riskPct)) {
  43. console.getOut().println("Max. drawdown reached! Stopping strategy!");
  44. this.context.stop();
  45. }
  46. }
  47.  
  48. public void onMessage(IMessage message) throws JFException {
  49. }
  50.  
  51. public void onStop() throws JFException {
  52. }
  53.  
  54. public void onTick(Instrument instrument, ITick tick) throws JFException {
  55. }
  56.  
  57. public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
  58. }
  59. }
Add Comment
Please, Sign In to add comment