Indicador de porcentaje

Responder
JimmyFX
Mensajes: 6
Registrado: 29 Mar 2020 21:56

Indicador de porcentaje

Mensaje por JimmyFX »

hola
tengo un indicador que me dice cuanto llevo ganando en las operaciones abiertas.
pero me lo pone en $ pero lo quiero en % con 0.00 como cifras.
aqui dejo el codigo el indicador a ver si alguien me puede ayudar con esto,

Código: Seleccionar todo

//+------------------------------------------------------------------+
//|                                                ProfitTracker.mq4 |
//|        Copyright © 2009, Jason Muchow ([email protected]) |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Jason Muchow ([email protected])"

#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);
}
Muchas Gracias
Adjuntos
ProfitTracker.mq4
(5.96 KiB) Descargado 96 veces
Avatar de Usuario
cdtrader
Mensajes: 588
Registrado: 28 Dic 2016 17:04

Re: Indicador de porcentaje

Mensaje por cdtrader »

Al final podrías poner return(msg*100/lo que hayas depositado);

Entiéndase que con lo que hayas depositado me refiero a lo que depositaste, no esas palabras.

El problema es que si fuiste depositando varias veces o retirando no sirve.

Otra forma es poner la cuenta en myfxbook o mql5 y de paso tienes estadísticas que te pueden resultar más útiles


Enviado desde mi iPad utilizando Tapatalk
Imagen
JimmyFX
Mensajes: 6
Registrado: 29 Mar 2020 21:56

Re: Indicador de porcentaje

Mensaje por JimmyFX »

hola

muchas gracias por tu respues

yo tengo un codigo q probablemente funcionaria, lo que no se como ponerlo a este indicador

Código: Seleccionar todo

ObjectSetText("profit_loss", DoubleToStr(pl_open*100/AccountBalance(), 1), Open_Font_Size);
algo asi
Avatar de Usuario
X-Trader
Administrador
Mensajes: 12781
Registrado: 06 Sep 2004 10:18
Contactar:

Re: Indicador de porcentaje

Mensaje por X-Trader »

En realidad muchas veces una buena búsqueda en la Red te resuelve los problemas. Con el indicador adjunto tienes resuelto el tema ;).

Saludos,
X-Trader
Adjuntos
i-profit.mq4
(15.03 KiB) Descargado 98 veces
"Los sistemas de trading pueden funcionar en ciertas condiciones de mercado todo el tiempo, en todas las condiciones de mercado en algún momento del tiempo, pero nunca en todas las condiciones de mercado todo el tiempo."
JimmyFX
Mensajes: 6
Registrado: 29 Mar 2020 21:56

Re: Indicador de porcentaje

Mensaje por JimmyFX »

a muchas gracias por la ayuda

pero necesito algo donde solo me marque el porciento que este conrriendo en el grafico

aqui encontre otro q se hacerca bastante pero solo tiene 2 digitos (0.0) si tuviero 3 (0.00)

aqui te lo dejo por si sabes alguna manera como arreglarlo

muchisimas gracias
Profit-Loss Meter.mq4
(3.32 KiB) Descargado 100 veces
Si te ha gustado este hilo del Foro, ¡compártelo en redes!


Responder

Volver a “Indicadores”