//+------------------------------------------------------------------+ //| FX Money Manager v2.mq4 | //| Belomor | //| belomor@inbox.ru | //+------------------------------------------------------------------+ #property copyright "Belomor" #property link "belomor@inbox.ru" #property indicator_chart_window //---- input parameters extern double Risk=2.5; extern double Open_Price=0.1; extern double Stop_Loss; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- Comment(""); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { Comment(""); return(0); } double PointCost() { double result; double BasePointCost; string BaseString; string String1; string String2; //+------------------------------------------------------------------+ BasePointCost=MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_POINT); BaseString=StringSubstr(Symbol(),3,3); String1="USD"+BaseString; String2=BaseString+"USD"; //+------------------------------------------------------------------+ if(BaseString=="USD") result=BasePointCost; //+------------------------------------------------------------------+ else if(MarketInfo(String1,MODE_BID)!=0) result=BasePointCost*(1/MarketInfo(String1,MODE_BID)); //+------------------------------------------------------------------+ else result=BasePointCost*MarketInfo(String2,MODE_ASK); //+------------------------------------------------------------------+ return(result); } double RiskInPoints() { double result; result=MathAbs(Open_Price-Stop_Loss)/Point; return(result); } double PoseSize() { double result; double PoseSize; double RP; RP=RiskInPoints(); if(PointCost()>0&&RP>0) { PoseSize=(AccountBalance()*Risk/100)/(RP*PointCost()); result=MathFloor(PoseSize*10)/10; } else result=0; return(result); } double AbsoluteRisk() { double result; double AR; AR=PoseSize()*RiskInPoints()*PointCost(); result=NormalizeDouble(AR,2); return(result); } double RelativeRisk() { double result; result=100*AbsoluteRisk()/AccountBalance(); return(result); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { string Comm="\nMONEY MANAGEMENT\n"; //---- Comm=Comm+"Current balance: "+DoubleToStr(AccountBalance(),2)+" USD \n"; Comm=Comm+"Risk on one position: "+DoubleToStr(Risk,2)+" % \n"; Comm=Comm+"Open Price: "+DoubleToStr(Open_Price,MarketInfo(Symbol(),MODE_DIGITS))+" \n"; Comm=Comm+"Stop Loss: "+DoubleToStr(Stop_Loss,MarketInfo(Symbol(),MODE_DIGITS))+" \n"; if(PointCost()==0) { Comm=Comm+"Do not know such a kind of instrument \n"; return(0); } Comm=Comm+"Point Cost per One Lot: "+DoubleToStr(NormalizeDouble(PointCost(),2),2)+" USD \n"; Comm=Comm+"Risk in pips: "+DoubleToStr(RiskInPoints(),0)+"\n"; Comm=Comm+"Recommended Position Size: "+DoubleToStr(PoseSize(),2)+" lot \n"; Comm=Comm+"Absolute Risk: "+DoubleToStr(AbsoluteRisk(),2)+" USD \n"; Comm=Comm+"Relative Risk: "+DoubleToStr(RelativeRisk(),2)+" % \n"; Comm=Comm+"Deviation from optimum: "+DoubleToStr((100-100*RelativeRisk()/Risk),2)+" % \n"; Comment(Comm); //---- return(0); } //+------------------------------------------------------------------+