//+------------------------------------------------------------------+ //| Dials MM.mq4 | //| Copyright © 2007, MQLService | //| http://www.mqlservice.com | //| $Id: //mqlservice/mt4files/experts/indicators/Dials MM.mq4#1 $ //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MQLService" #property link "http://www.mqlservice.com" #property indicator_chart_window //---- input parameters extern double Risk=1.0; extern int StopLoss=20; //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { Comment(""); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { double mrisk = AccountFreeMargin()*Risk/100.0; double risk1l = MarketInfo(Symbol(), MODE_TICKVALUE)*StopLoss; Comment("Risk is ", DoubleToStr(Risk, 2)," % = ", DoubleToStr(mrisk, 2),"$\nStop loss is ",StopLoss," pips = ", DoubleToStr(risk1l, 2), "$ with 1 lot\nPosition size should be ", DoubleToStr(normalize_volume(mrisk/risk1l), 2)," lots"); return(0); } double normalize_volume(double lots){ // Adjust trade volume to broker double step = MarketInfo(Symbol(), MODE_LOTSTEP); double min = MarketInfo(Symbol(), MODE_MINLOT); double max = MarketInfo(Symbol(), MODE_MAXLOT); if(max > 0) lots = MathMin(lots, max); if(step > 0) double result = MathFloor(lots/step)*step; else result = 0; if(result < min) if(min>0) return(min); else return(lots); else if(result > 0) return(result); else return(lots); } //+----------- Coded by Michal Rutka @ MQLService.com ---------------+