//+------------------------------------------------------------------+ //| Pipsometer 5 Desimal.mq5 | //| Copyright © 2007, 4kk4 | //| | //+------------------------------------------------------------------+ //---- Copyright #property copyright "Copyright © 2007, 4kk4" //---- link to the website of the author #property link "" //---- Indicator version number #property version "4.22" #property indicator_chart_window #property indicator_plots 0 //--- input parameters input color color1=clrCoral; input color color2=clrLightGreen; input bool allSymbols=false; input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; input ENUM_ANCHOR_POINT anchor = ANCHOR_RIGHT_LOWER; input int MagicNumber = 0; //--- Global variables for object names string pipsName = "lpm_pips"; string pipsToSlName = "lpm_pips_tosl"; string pipsRealizedName = "lpm_pips_realized"; string longLabelName = "lpm_longlabel"; string shortLabelName = "lpm_shortlabel"; string longName = "lpm_long"; string shortName = "lpm_short"; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Create objects ObjectCreate(0,pipsName,OBJ_LABEL,0,0,0); ObjectSetInteger(0,pipsName,OBJPROP_CORNER,corner); ObjectSetInteger(0,pipsName,OBJPROP_ANCHOR,anchor); ObjectSetString(0,pipsName,OBJPROP_TEXT,"pips"); ObjectSetInteger(0,pipsName,OBJPROP_COLOR,color1); ObjectSetInteger(0,pipsName,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,pipsName,OBJPROP_YDISTANCE,20); ObjectSetInteger(0,pipsName,OBJPROP_FONTSIZE,30); ObjectCreate(0,pipsToSlName,OBJ_LABEL,0,0,0); ObjectSetInteger(0,pipsToSlName,OBJPROP_CORNER,corner); ObjectSetInteger(0,pipsToSlName,OBJPROP_ANCHOR,anchor); ObjectSetString(0,pipsToSlName,OBJPROP_TEXT,"S"); ObjectSetInteger(0,pipsToSlName,OBJPROP_COLOR,color2); ObjectSetInteger(0,pipsToSlName,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,pipsToSlName,OBJPROP_YDISTANCE,57); ObjectSetInteger(0,pipsToSlName,OBJPROP_FONTSIZE,11); ObjectCreate(0,pipsRealizedName,OBJ_LABEL,0,0,0); ObjectSetInteger(0,pipsRealizedName,OBJPROP_CORNER,corner); ObjectSetInteger(0,pipsRealizedName,OBJPROP_ANCHOR,anchor); ObjectSetString(0,pipsRealizedName,OBJPROP_TEXT,"R"); ObjectSetInteger(0,pipsRealizedName,OBJPROP_COLOR,color1); ObjectSetInteger(0,pipsRealizedName,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,pipsRealizedName,OBJPROP_YDISTANCE,5); ObjectSetInteger(0,pipsRealizedName,OBJPROP_FONTSIZE,11); ObjectCreate(0,longLabelName,OBJ_LABEL,0,0,0); ObjectSetInteger(0,longLabelName,OBJPROP_CORNER,corner); ObjectSetInteger(0,longLabelName,OBJPROP_ANCHOR,anchor); ObjectSetString(0,longLabelName,OBJPROP_TEXT,"Long:"); ObjectSetInteger(0,longLabelName,OBJPROP_COLOR,color2); ObjectSetInteger(0,longLabelName,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,longLabelName,OBJPROP_YDISTANCE,90); ObjectSetInteger(0,longLabelName,OBJPROP_FONTSIZE,11); ObjectCreate(0,shortLabelName,OBJ_LABEL,0,0,0); ObjectSetInteger(0,shortLabelName,OBJPROP_CORNER,corner); ObjectSetInteger(0,shortLabelName,OBJPROP_ANCHOR,anchor); ObjectSetString(0,shortLabelName,OBJPROP_TEXT,"Short:"); ObjectSetInteger(0,shortLabelName,OBJPROP_COLOR,color2); ObjectSetInteger(0,shortLabelName,OBJPROP_XDISTANCE,20); ObjectSetInteger(0,shortLabelName,OBJPROP_YDISTANCE,70); ObjectSetInteger(0,shortLabelName,OBJPROP_FONTSIZE,11); ObjectCreate(0,longName,OBJ_LABEL,0,0,0); ObjectSetInteger(0,longName,OBJPROP_CORNER,corner); ObjectSetInteger(0,longName,OBJPROP_ANCHOR,anchor); ObjectSetString(0,longName,OBJPROP_TEXT,"L"); ObjectSetInteger(0,longName,OBJPROP_COLOR,color2); ObjectSetInteger(0,longName,OBJPROP_XDISTANCE,65); ObjectSetInteger(0,longName,OBJPROP_YDISTANCE,90); ObjectSetInteger(0,longName,OBJPROP_FONTSIZE,11); ObjectCreate(0,shortName,OBJ_LABEL,0,0,0); ObjectSetInteger(0,shortName,OBJPROP_CORNER,corner); ObjectSetInteger(0,shortName,OBJPROP_ANCHOR,anchor); ObjectSetString(0,shortName,OBJPROP_TEXT,"S"); ObjectSetInteger(0,shortName,OBJPROP_COLOR,color2); ObjectSetInteger(0,shortName,OBJPROP_XDISTANCE,65); ObjectSetInteger(0,shortName,OBJPROP_YDISTANCE,70); ObjectSetInteger(0,shortName,OBJPROP_FONTSIZE,11); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectDelete(0,pipsName); ObjectDelete(0,pipsToSlName); ObjectDelete(0,pipsRealizedName); ObjectDelete(0,longName); ObjectDelete(0,shortName); ObjectDelete(0,longLabelName); ObjectDelete(0,shortLabelName); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { ObjectSetString(0,shortName,OBJPROP_TEXT,IntegerToString(countOrders(POSITION_TYPE_SELL,allSymbols))); ObjectSetString(0,longName,OBJPROP_TEXT,IntegerToString(countOrders(POSITION_TYPE_BUY,allSymbols))); double profit, sl, realized; calcProfit(profit,sl,allSymbols); calcRealized(realized,allSymbols); string point_str_format = "%.1f"; //+ IntegerToString((int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS) ) + ObjectSetString(0,pipsName,OBJPROP_TEXT,sign(profit)+StringFormat(point_str_format,MathAbs(profit))); if (profit >= 0){ ObjectSetInteger(0,pipsName,OBJPROP_COLOR,color2); } else { ObjectSetInteger(0,pipsName,OBJPROP_COLOR,color1); } ObjectSetString(0,pipsToSlName,OBJPROP_TEXT, sign(sl)+StringFormat(point_str_format,MathAbs(sl))); ObjectSetString(0,pipsRealizedName,OBJPROP_TEXT,sign(realized)+StringFormat(point_str_format,MathAbs(realized))); return(rates_total); } //+------------------------------------------------------------------+ //| Calculate realized profit | //+------------------------------------------------------------------+ void calcRealized(double& out, bool aSymbols=false) { double profit=0; ulong ticket; HistorySelect(0,TimeCurrent()); for(int i=0; i0) { if(aSymbols || HistoryDealGetString(ticket,DEAL_SYMBOL)== _Symbol) { if(HistoryDealGetInteger(ticket,DEAL_MAGIC)==MagicNumber || MagicNumber == 0) { if(HistoryDealGetInteger(ticket,DEAL_ENTRY) == DEAL_ENTRY_OUT) { profit += HistoryDealGetDouble(ticket, DEAL_PROFIT); } } } } } double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT); out = profit / (SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) / SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE) * point); } //+------------------------------------------------------------------+ //| Calculate unrealized profit and stoploss pips | //+------------------------------------------------------------------+ void calcProfit(double& out, double& outsl,bool aSymbols=false) { double profit=0; double p=0; double sl=0; double s=0; for(int i=PositionsTotal()-1; i>=0; i--) { ulong ticket = PositionGetTicket(i); if(ticket>0) { if(PositionGetInteger(POSITION_MAGIC)==MagicNumber || MagicNumber == 0) { if(aSymbols || PositionGetString(POSITION_SYMBOL)==_Symbol) { p=0; s=0; double point = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_POINT); if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { p=(SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN))/point; if(PositionGetDouble(POSITION_SL)>0) { s=(PositionGetDouble(POSITION_SL)-PositionGetDouble(POSITION_PRICE_OPEN))/point; } } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { p=(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_ASK))/point; if(PositionGetDouble(POSITION_SL)>0) { s=(PositionGetDouble(POSITION_PRICE_OPEN)-PositionGetDouble(POSITION_SL))/point; } } sl+=s; profit+=p; } } } } out=profit/10; // For 5-digit broker adjustment outsl=sl/10; // For 5-digit broker adjustment } //+------------------------------------------------------------------+ //| Count open orders by type | //+------------------------------------------------------------------+ int countOrders(ENUM_POSITION_TYPE oType,bool aSymbols=false) { int count=0; for(int i=PositionsTotal()-1; i>=0; i--) { ulong ticket = PositionGetTicket(i); if(ticket>0) { if(PositionGetInteger(POSITION_MAGIC)==MagicNumber || MagicNumber == 0) { if(aSymbols || PositionGetString(POSITION_SYMBOL)==_Symbol) { if(PositionGetInteger(POSITION_TYPE)==oType) { count++; } } } } } return(count); } //+------------------------------------------------------------------+ //| Return sign of a value | //+------------------------------------------------------------------+ string sign(double value) { if(value>0) { return("+"); } if(value<0) { return("-"); } return(""); }