Advertisement
Guest User

Risk Calculator

a guest
Nov 27th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| Baller |
  3. //+------------------------------------------------------------------+
  4.  
  5. #property indicator_chart_window
  6. extern double StopLoss = 30;
  7. extern double RiskPercent = 2;
  8.  
  9. //
  10. //
  11. //
  12. //
  13. //
  14.  
  15. int init() { return(0); }
  16. int deinit() { return(0); }
  17. int start()
  18. {
  19. double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); if (Digits==3 || Digits==5) pipValue *= 10;
  20. double step = MarketInfo(Symbol(),MODE_LOTSTEP);
  21. int norm = 0;
  22. if (step==1) norm = 0;
  23. if (step==0.1) norm = 1;
  24. if (step==0.01) norm = 2;
  25. double minLot = MarketInfo(Symbol(),MODE_MINLOT);
  26. double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
  27. double lots = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
  28. lots = NormalizeDouble(lots,norm);
  29.  
  30. //
  31. //
  32. //
  33. //
  34. //
  35.  
  36. double actualRisk;
  37. string comment = DoubleToStr(StopLoss,0)+"SL "+DoubleToStr(RiskPercent,0)+"% risk "+DoubleToStr(lots,norm);
  38. if (lots<minLot)
  39. {
  40. actualRisk = (100*minLot*StopLoss*pipValue)/AccountBalance();
  41. comment = "lot size less than minimal allowed lot for risk and stop loss setting\n"+
  42. "calculated lot size : "+DoubleToStr(lots,norm)+" minimal allowed : "+DoubleToStr(minLot,norm)+"\n"+
  43. "risk with minimal lot size and stop loss set to : "+DoubleToStr(StopLoss,2)+"pips is : "+DoubleToStr(actualRisk,2)+"%";
  44. }
  45. Comment(comment);
  46. return(0);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement