Scripts: Exposición

 

Exposición:

Este script lee todas posiciones abiertas y calcula su exposición para cada moneda.

Autor: Ivan Ivanov

 
Automated-Trading:

Exposición:

Autor: IvanBG

Y por qué se necesita una secuencia de comandos de este tipo, cuando hay una pestaña listo en el terminal donde se muestran todos los activos.

 
sergey1294:

Y por qué se necesita un script así cuando hay una pestaña preparada en el terminal donde se muestran todos los activos.

Desconozco la idea del autor,

pero como respuesta a tu pregunta, el código del script se puede utilizar para obtener esta información mediante programación,

no se puede leer desde la pestaña.

 
Urain:

Desconozco la intención del autor,

pero como respuesta a tu pregunta, el código del script puede ser usado para obtener esta información programáticamente,

no se puede contar desde una pestaña.

Bueno, si en este sentido, entonces sí, el ejemplo no está mal. Estaría bien que los desarrolladores dieran acceso programático a esta pestaña.
 
Urain:

Desconozco la intención del autor,

pero como respuesta a tu pregunta, el código del script puede ser usado para obtener esta información programáticamente,

no se puede contar desde una pestaña.

La idea es exactamente así: utilizar este código y ponerlo en otro programa.

Y que el terminal de la misma información: sí, pero sólo está disponible en la pantalla, pero no como datos que se pueden utilizar (leer programáticamente).

De hecho, yo tengo este código en mi programa. Y el skipt lo hice sólo para difundir la idea.

 
IvanBG:

La idea es exactamente la misma: utilizar este código y ponerlo en otro programa.

Y que el terminal dé la misma información: sí, pero sólo está disponible en la pantalla, pero no como datos que se puedan utilizar (leer programáticamente).

De hecho, yo tengo este código en mi programa. Y el skipt hecho sólo para difundir la idea.

Ya veo, entonces para mayor claridad también se podría mostrar una tabla con gráficos en el gráfico, sería más bonito.
[Eliminado]  
sergey1294:
Bueno, si en este sentido, entonces sí, el ejemplo no está mal. Si, no estaría mal que los desarrolladores dieran acceso al programa a esta pestaña.
+1
 

No puedo lanzar Exposure. Necesito ver el número de ventas y compras en la versión más simple del indicador para MT5. Lo he descargado tanto en el terminal y por separado desde el sitio y trató de ejecutarlo - no se muestra en el campo de trabajo.

 

Hola, este script no parece funcionar.


Lo coloco en el gráfico e inmediatamente lo elimina..y luego en la pestaña Expertos dice

"2019.08.14 19:19:31.762 exposure (GBPUSD,H2) array out of range in 'exposure.mq5' (63,34)"


 
No compatible con la plataforma MT5
 

He encontrado este hoy. Alguien lo convirtió a Mt5. Gracias a quien lo hizo.

Funciona en Mt5. Y lo estoy modificando. Me gustaría añadir cuando haya terminado

Script : iExposure MT5.mq5

//+------------------------------------------------------------------+
//|iExposure.mq4
//| Copyright 2007-2014, MetaQuotes Software Corp. |
//| http://www.mql4.com
//+------------------------------------------------------------------+
#property copyright "2007-2014, MetaQuotes Software Corp."
#property link      "http://www.mql4.com"
#property strict

#property indicator_separate_window
#property indicator_plots 0
#property indicator_buffers 1
#property indicator_minimum 0.0
#property indicator_maximum 0.1

#define  SYMBOLS_MAX 1024
#define  DEALS          0
#define  BUY_LOTS       1
#define  BUY_PRICE      2
#define  SELL_LOTS      3
#define  SELL_PRICE     4
#define  NET_LOTS       5
#define  PROFIT         6

input color InpColor=LightSeaGreen;  // Color del texto

string ExtName="Exposure";
string ExtSymbols[SYMBOLS_MAX];
int    ExtSymbolsTotal=0;
double ExtSymbolsSummaries[SYMBOLS_MAX][7];
int    ExtLines=-1;
string ExtCols[8]= {"Symbol",
                     "Deals",
                     "Buy lots",
                     "Buy price",
                     "Sell lots",
                     "Sell price",
                     "Net lots",
                     "Profit",
                    };
int    ExtShifts[8]= { 10, 80, 130, 180, 260, 310, 390, 460 };
int    ExtVertShift=14;
double ExtMapBuffer[];
long chartid = 0;
//+------------------------------------------------------------------+
//| Función de inicialización del indicador personalizada |
//+------------------------------------------------------------------+
void OnInit()
  {
   IndicatorSetString(INDICATOR_SHORTNAME,ExtName);
   SetIndexBuffer(0,ExtMapBuffer,INDICATOR_CALCULATIONS);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_NONE);
   IndicatorSetInteger(INDICATOR_DIGITS,0);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   int windex=ChartWindowFind(chartid,ExtName);
   if(windex>0)
      ObjectsDeleteAll(windex);

  }
//+------------------------------------------------------------------+
//| Función de iteración del indicador personalizada|
//+------------------------------------------------------------------+
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[])
  {
   string name;
   int    i,col,line,windex=ChartWindowFind(chartid,ExtName);
//----
   if(windex<0)
      return(rates_total);
//---- línea de cabecera
   if(ExtLines<0)
     {
      for(col=0; col<8; col++)
        {
         name="Head_"+string(col);
         if(ObjectCreate(chartid,name,OBJ_LABEL,windex,0,0))
           {
            ObjectSetInteger(chartid,name,OBJPROP_XDISTANCE,ExtShifts[col]);
            ObjectSetInteger(chartid,name,OBJPROP_YDISTANCE,ExtVertShift);
            ObjectSetString(chartid,name,OBJPROP_TEXT,ExtCols[col]);
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
        }
      ExtLines=0;
     }
//----
   ArrayInitialize(ExtSymbolsSummaries,0.0);
   int total=Analyze();
   if(total>0)
     {
      line=0;
      for(i=0; i<ExtSymbolsTotal; i++)
        {
         if(ExtSymbolsSummaries[i][DEALS]<=0)
            continue;
         line++;
         //---- añadir línea
         if(line>ExtLines)
           {
            int y_dist=ExtVertShift*(line+1)+1;
            for(col=0; col<8; col++)
              {
               name="Line_"+string(line)+"_"+string(col);
               if(ObjectCreate(chartid,name,OBJ_LABEL,windex,0,0))
                 {
                  ObjectSetInteger(chartid,name,OBJPROP_XDISTANCE,ExtShifts[col]);
                  ObjectSetInteger(chartid,name,OBJPROP_YDISTANCE,y_dist);
                 }
              }
            ExtLines++;
           }
         //---- set line
         int    digits=(int)SymbolInfoInteger(ExtSymbols[i],SYMBOL_DIGITS);
         double buy_lots=ExtSymbolsSummaries[i][BUY_LOTS];
         double sell_lots=ExtSymbolsSummaries[i][SELL_LOTS];
         double buy_price=0.0;
         double sell_price=0.0;
         if(buy_lots!=0)
            buy_price=ExtSymbolsSummaries[i][BUY_PRICE]/buy_lots;
         if(sell_lots!=0)
            sell_price=ExtSymbolsSummaries[i][SELL_PRICE]/sell_lots;
         name="Line_"+string(line)+"_0";
           {
            ObjectSetString(chartid,name,OBJPROP_TEXT,ExtSymbols[i]);
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
         name="Line_"+string(line)+"_1";
           {
            ObjectSetString(chartid,name,OBJPROP_TEXT,DoubleToString(ExtSymbolsSummaries[i][DEALS],0));
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
         name="Line_"+string(line)+"_2";
           {
            ObjectSetString(chartid,name,OBJPROP_TEXT,DoubleToString(buy_lots,2));
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
         name="Line_"+string(line)+"_3";
           {
            ObjectSetString(chartid,name,OBJPROP_TEXT,DoubleToString(buy_price,digits));
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
         name="Line_"+string(line)+"_4";
           {
            ObjectSetString(chartid,name,OBJPROP_TEXT,DoubleToString(sell_lots,2));
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
         name="Line_"+string(line)+"_5";
           {
            ObjectSetString(chartid,name,OBJPROP_TEXT,DoubleToString(sell_price,digits));
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
         name="Line_"+string(line)+"_6";
           {
            ObjectSetString(chartid,name,OBJPROP_TEXT,DoubleToString(buy_lots-sell_lots,2));
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
         name="Line_"+string(line)+"_7";
           {
            ObjectSetString(chartid,name,OBJPROP_TEXT,DoubleToString(ExtSymbolsSummaries[i][PROFIT],2));
            ObjectSetString(chartid,name,OBJPROP_FONT,"Arial");
            ObjectSetInteger(chartid,name,OBJPROP_FONTSIZE,9);
            ObjectSetInteger(chartid,name,OBJPROP_COLOR,InpColor);
           }
        }
     }
//---- eliminar líneas
   if(total<ExtLines)
     {
      for(line=ExtLines; line>total; line--)
        {
         name="Line_"+string(line)+"_0";
         ObjectSetString(chartid,name,OBJPROP_TEXT," ");
         name="Line_"+string(line)+"_1";
         ObjectSetString(chartid,name,OBJPROP_TEXT," ");
         name="Line_"+string(line)+"_2";
         ObjectSetString(chartid,name,OBJPROP_TEXT," ");
         name="Line_"+string(line)+"_3";
         ObjectSetString(chartid,name,OBJPROP_TEXT," ");
         name="Line_"+string(line)+"_4";
         ObjectSetString(chartid,name,OBJPROP_TEXT," ");
         name="Line_"+string(line)+"_5";
         ObjectSetString(chartid,name,OBJPROP_TEXT," ");
         name="Line_"+string(line)+"_6";
         ObjectSetString(chartid,name,OBJPROP_TEXT," ");
         name="Line_"+string(line)+"_7";
         ObjectSetString(chartid,name,OBJPROP_TEXT," ");
        }
     }
//---- para evitar mínimo==máximo
   int bars=iBars(_Symbol,_Period);
   ExtMapBuffer[bars-1]=-1;
//----
   return(rates_total);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
int Analyze()
  {
   double profit;
   int    i,index,total=PositionsTotal();
//----
   for(i=0; i<total; i++)
     {
      if(!PositionGetTicket(i))
         continue;
      if(PositionGetInteger(POSITION_TYPE)!=POSITION_TYPE_BUY && PositionGetInteger(POSITION_TYPE)!=POSITION_TYPE_SELL)
         continue;
      index=SymbolsIndex(PositionGetString(POSITION_SYMBOL));
      if(index<0 || index>=SYMBOLS_MAX)
         continue;
      //----
      ExtSymbolsSummaries[index][DEALS]++;
      profit=PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP)+AccountInfoDouble(ACCOUNT_COMMISSION_BLOCKED);
      ExtSymbolsSummaries[index][PROFIT]+=profit;
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
        {
         ExtSymbolsSummaries[index][BUY_LOTS]+=PositionGetDouble(POSITION_VOLUME);
         ExtSymbolsSummaries[index][BUY_PRICE]+=PositionGetDouble(POSITION_PRICE_OPEN)*PositionGetDouble(POSITION_VOLUME);
        }
      else
        {
         ExtSymbolsSummaries[index][SELL_LOTS]+=PositionGetDouble(POSITION_VOLUME);
         ExtSymbolsSummaries[index][SELL_PRICE]+=PositionGetDouble(POSITION_PRICE_OPEN)*PositionGetDouble(POSITION_VOLUME);
        }

     }
//----
   total=0;
   for(i=0; i<ExtSymbolsTotal; i++)
     {
      if(ExtSymbolsSummaries[i][DEALS]>0)
         total++;
     }
//----
   return(total);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
int SymbolsIndex(string SymbolName)
  {
   bool found=false;
   int  i;
//----
   for(i=0; i<ExtSymbolsTotal; i++)
     {
      if(SymbolName==ExtSymbols[i])
        {
         found=true;
         break;
        }
     }
//----
   if(found)
      return(i);
   if(ExtSymbolsTotal>=SYMBOLS_MAX)
      return(-1);
//----
   i=ExtSymbolsTotal;
   ExtSymbolsTotal++;
   ExtSymbols[i]=SymbolName;
   ExtSymbolsSummaries[i][DEALS]=0;
   ExtSymbolsSummaries[i][BUY_LOTS]=0;
   ExtSymbolsSummaries[i][BUY_PRICE]=0;
   ExtSymbolsSummaries[i][SELL_LOTS]=0;
   ExtSymbolsSummaries[i][SELL_PRICE]=0;
   ExtSymbolsSummaries[i][NET_LOTS]=0;
   ExtSymbolsSummaries[i][PROFIT]=0;
//----
   return(i);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+