//+------------------------------------------------------------------+ //| Money Management.mq4 | //| iPhoks | //| | //+------------------------------------------------------------------+ #property copyright "iPhoks 2012" #property link "ЦЦЦ.Gdetovseti.sru :D" #property indicator_chart_window extern int Percent2=2; //Определяемый риск при каждой сделке extern int Percent6=6; //Общий месячный риск по депозиту extern double Lot=0.01; //Объем, которым осуществляется или планируется торговля extern color UpKeepLine=White; //Цвет верхней запретной линии extern color DownKeepLine=White; //Цвет нижней запретной линии extern int DrawType=4; //Тип отображения линий extern bool CountingByOrder=false; //false-расчет Percent2 по отнашению к Bid, true-оносительно заданной цены extern double CountingPrice=0; //Цена для расчета Percent2 при CountingByOrder=true extern double BeginningDeposit=0; //Начальный депозит, если ноль примет за начальный текущиий депозит extern bool FullRiskOption=false; double PUp,PDown; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete("PUp"); ObjectDelete("PDown"); Comment(""); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- if (AccountBalance()>BeginningDeposit) BeginningDeposit=AccountBalance(); double P6=(BeginningDeposit*Percent6/100)-(BeginningDeposit-AccountBalance()); double PricePips=MarketInfo(Symbol(),MODE_TICKVALUE); double SumRisk=0; if (FullRiskOption==true) { if (OrdersTotal()>0) { for (int i=1; i<=OrdersTotal();i++) { OrderSelect(i-1,SELECT_BY_POS); if (OrderStopLoss()!=0) SumRisk=SumRisk+(MathAbs(OrderStopLoss()-OrderOpenPrice())*100000); } double FullRisk=SumRisk*100/AccountBalance(); string FR="Full Risk = "+DoubleToStr(FullRisk,3)+"%"; } else FR="Full Risk = 0%"; } else FR="Full Risk Option - Off"; Comment("1 Pips Price = "+DoubleToStr(PricePips*Lot,2)+"$" +"\n"+"Rezerve of 6% = "+DoubleToStr(P6,2)+"$" +"\n"+"Current Lot = "+DoubleToStr(Lot,2) +"\n"+FR); if (CountingByOrder==false) { PUp=Bid+((AccountFreeMargin()*Percent2/100)/(PricePips*Lot)*Point); PDown=Ask-((AccountFreeMargin()*Percent2/100)/(PricePips*Lot)*Point); } else { PUp=CountingPrice+((AccountFreeMargin()*Percent2/100)/(PricePips*Lot)*Point); PDown=CountingPrice-((AccountFreeMargin()*Percent2/100)/(PricePips*Lot)*Point); } ObjectCreate("PUp",OBJ_HLINE,0,0,PUp); ObjectSet("PUp",OBJPROP_PRICE1,PUp); ObjectSet("PUp",OBJPROP_COLOR,UpKeepLine); ObjectSet("PUp",OBJPROP_STYLE,DrawType); ObjectCreate("PDown",OBJ_HLINE,0,0,PDown); ObjectSet("PDown",OBJPROP_PRICE1,PDown); ObjectSet("PDown",OBJPROP_COLOR,DownKeepLine); ObjectSet("PDown",OBJPROP_STYLE,DrawType); if (P6<=0) Alert("Loss more than 6%"); //---- return(0); } //+------------------------------------------------------------------+