Percentage indicator

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Percentage indicator

Postby JimmyFX » Sun Mar 29, 2020 4:23 pm

Hi there
I have an indicator that tells me how long I have been earning in open trades.
but it puts me in $ but I want it in % with 0.00 as figures.
here I leave the code the indicator to see if someone can help me with this


Code: Select all

#property indicator_chart_window

extern bool only_this_symbol = true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   run();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   deleteIcons();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   run();
//----
   return(0);
  }
//+------------------------------------------------------------------+

void deleteIcons() {
   for (int i=0;i<=ObjectsTotal();i++) {
      string name=ObjectName(i);
      if (StringFind(name,"pt_",0)!=-1) {
         ObjectDelete(name);
      }
   }
}

void run() {
   
   double profit_current,profit_hour,profit_day,profit_week,profit_month;
   
   profit_current=0;
   profit_hour=0;
   profit_day=0;
   profit_week=0;
   profit_month=0;
   
   int start_hour = iTime(Symbol(),PERIOD_H1,0);
   int start_day = iTime(Symbol(),PERIOD_D1,0);
   int start_week = iTime(Symbol(),PERIOD_W1,0);
   int start_month = iTime(Symbol(),PERIOD_MN1,0);
   
   int time_hour = 60*60;
   int time_day = time_hour*24;
   int time_week = time_day*7;
   int time_month = time_day*31;//todo fix it so that 30 day months, etc work properly
   
   int now = TimeCurrent();
   
   int iter_max = OrdersHistoryTotal();
   
   for (int i=0;i<=iter_max;i++) {
      if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
         int order_start = OrderOpenTime();
         double order_profit = OrderProfit()+OrderSwap();
         
         if (OrderSymbol()!=Symbol() && only_this_symbol) {
            // do nothing
         } else {
           
            if (order_start >= start_hour) {profit_hour+=order_profit;}
            if (order_start >= start_day) {profit_day+=order_profit;}
            if (order_start >= start_week) {profit_week+=order_profit;}
            if (order_start >= start_month) {profit_month+=order_profit;}
           
         }
      }
   }
   
   for (i=0;i<=OrdersTotal();i++) {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
         order_profit = OrderProfit()+OrderSwap()+OrderCommission();
         
         if (OrderSymbol()!=Symbol() && only_this_symbol) {
            // do nothing
         } else {
         
            profit_current += order_profit;
         
         }
     
      }
   }
   
   // create labels
   string font = "arial";
   string name;
   
   name="pt_name";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,"Beneficios",19,font,Black);
   prepare_label(name,3,45,155);
         
   name="pt_month";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,"Mes",15,font,Gray);
   prepare_label(name,3,55,135);
         
   name="pt_week";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,"Semana",15,font,Gray);
   prepare_label(name,3,22,115);
   
   name="pt_day";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,"Dia",15,font,Gray);
   prepare_label(name,3,66,95);
   
   name="pt_hour";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,"Hora",15,font,Gray);
   prepare_label(name,3,54,75);
   
   name="pt_l1";
   ObjectCreate(name,OBJ_LABEL,0,0,0);
   ObjectSetText(name,"_____________",15,font,Gray);
   prepare_label(name,3,20,68);
   
   name="pt_now";
   ObjectCreate(name,OBJ_LABEL,0,0,0);
   ObjectSetText(name,"$",19,font,Black);
   prepare_label(name,3,28,40);
   
   name="pt_l2";
   ObjectCreate(name,OBJ_LABEL,0,0,0);
   ObjectSetText(name,"__________________",15,font,Gray);
   prepare_label(name,3,0,33);
   
   /////////////////
   // Now set prices
   /////////////////
   name="pt_m$";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,money(profit_month),15,font,SteelBlue);
   if (profit_month<=0) {ObjectSet(name,OBJPROP_COLOR,Red);}
   prepare_label(name,3,100,135);
   
   name="pt_w$";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,money(profit_week),15,font,SteelBlue);
   if (profit_week<=0) {ObjectSet(name,OBJPROP_COLOR,Red);}
   prepare_label(name,3,100,115);
   
   name="pt_d$";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,money(profit_day),15,font,SteelBlue);
   if (profit_day<=0) {ObjectSet(name,OBJPROP_COLOR,Red);}
   prepare_label(name,3,100,95);
   
   name="pt_h$";
   ObjectCreate(name,OBJ_LABEL,200,200,200);
   ObjectSetText(name,money(profit_hour),15,font,SteelBlue);
   if (profit_hour<=0) {ObjectSet(name,OBJPROP_COLOR,Red);}
   prepare_label(name,3,100,75);
   
   name="pt_n$";
   ObjectCreate(name,OBJ_LABEL,0,0,0);
   ObjectSetText(name,money(profit_current),19,font,SteelBlue);
   if (profit_current<=0) {ObjectSet(name,OBJPROP_COLOR,Red);}
   prepare_label(name,3,100,40);
         
}
         
void prepare_label (string name,int corner,int x,int y) {
   ObjectSet(name,OBJPROP_CORNER,corner);
   ObjectSet(name,OBJPROP_XDISTANCE,x);
   ObjectSet(name,OBJPROP_YDISTANCE,y);
}

string money(double value) {
   string msg;
   msg = DoubleToStr(value,2);
   return(msg);
}
   
           


THX
JimmyFX
 
Posts: 9
Joined: Tue Mar 03, 2020 5:18 pm

Re: Percentage indicator

Postby Apprentice » Mon Mar 30, 2020 6:44 am

Your request is added to the development list.
Development reference 963.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36437
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Percentage indicator

Postby JimmyFX » Tue Mar 31, 2020 12:55 pm

does not work, here is an image of the error
Attachments
porcent.png
JimmyFX
 
Posts: 9
Joined: Tue Mar 03, 2020 5:18 pm

Re: Percentage indicator

Postby Apprentice » Wed Apr 01, 2020 6:20 am

Your request is added to the development list.
Development reference 985.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36437
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Percentage indicator

Postby Apprentice » Thu Apr 02, 2020 6:40 am

ProfitTracker.mq4
(6.83 KiB) Downloaded 237 times

Try this version.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36437
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Percentage indicator

Postby JimmyFX » Thu Apr 02, 2020 12:56 pm

just like that, thank you very much
JimmyFX
 
Posts: 9
Joined: Tue Mar 03, 2020 5:18 pm


Return to Indicator and Signal Requests

Who is online

Users browsing this forum: No registered users and 10 guests