Preguntas de los principiantes MQL5 MT5 MetaTrader 5 - página 812

 

¿Cómo es posible? ¿No había un problema con las matemáticas?

input double    T_P  =0.81;
input double    S_L  =0.35;

b_ep=price-atrH1200;
b_sl=b_ep-(b_ep*S_L)/100;
b_tp=b_ep+(b_ep*T_P)/100;

Parece que 1,05 *0,81/100 =0,008505

Te da un 35% de stop y un 81% de tek profit en lugar de un 0,81% y un 0,35%.

SellLimit(LOT_FOR_TRADE,s_ep,symb,s_sl,s_tp,ORDER_TIME_DAY,0,"SellLimit");

BuyLimit(LOT_FOR_TRADE,b_ep,symb,b_sl,b_tp,ORDER_TIME_DAY,0,"BuyLimit");

El método de la biblioteca estándarSellLimit&BuyLimit


Print(s_ep,"s_ep");
Print(s_sl,"s_sl");
Print(s_tp,"s_tp");

Muestra de impresión:

2017.12.24 07:55:27.559 2017.01.03 16:54:17 1.04236745s_ep

2017.12.24 07:55:27.559 2017.01.03 16:54:17 1.25084094s_sl

2017.12.24 07:55:27.559 2017.01.03 16:54:17 0.521183725s_tp


 
SILVERPRINT:

¿Cómo es posible? ¿No había un problema con las matemáticas?

Parece que 1,05 *0,81/100 =0,008505

Te da un 35% de stop y un 81% de tek profit en lugar de un 0,81% y un 0,35%.

El método de la biblioteca estándarSellLimit&BuyLimit


Muestra de impresión:

2017.12.24 07:55:27.559 2017.01.03 16:54:17 1.04236745s_ep

2017.12.24 07:55:27.559 2017.01.03 16:54:17 1.25084094s_sl

2017.12.24 07:55:27.559 2017.01.03 16:54:17 0.521183725s_tp



Reescribe el mismo código, pero de forma que se declaren TODAS las variables. Voy a ver qué tipos de variables declaras. Y entonces la solución adecuada está cerca.

 
Vladimir Karputov:

Reescribe el mismo código, pero de forma que se declaren TODAS las variables. Voy a ver qué tipos de variables declaras. Y entonces estarás en el camino de la solución correcta.


//+------------------------------------------------------------------+
//|                                                       |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
#include <Indicators\Trend.mqh>
#include <Indicators\Oscilators.mqh>
#include <Indicators\TimeSeries.mqh>
#include <Trade\Trade.mqh>
input double    T_P  =0.81;
input double    S_L  =0.35;
static int hour;
int h;
input int TIME_FOR_ACTION=16;
input int slowma=200;
input int fastwma=20;
input int mahours=20;
input double LOT_FOR_TRADE=0.1;
string symb;
MqlTick infotick;
MqlDateTime currentTime;
CiMA ValueofMA200;
CiMA ValueofMA20;
CiMA ValueofMAHour;
CiATR atr;
CTrade T_M;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   symb=_Symbol;
   ValueofMA200.Create(symb,PERIOD_D1,slowma,0,MODE_SMA,PRICE_CLOSE);
   ValueofMA20.Create(symb,PERIOD_D1,fastwma,0,MODE_SMA,PRICE_CLOSE);
   ValueofMAHour.Create(symb,PERIOD_H1,mahours,0,MODE_SMA,PRICE_CLOSE);
   atr.Create(symb,PERIOD_H1,200);


   atr.BufferResize(40);
   ValueofMA200.BufferResize(250);
   ValueofMA20.BufferResize(250);
   ValueofMAHour.BufferResize(250);

   T_M.LogLevel(LOG_LEVEL_ALL);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   RefCustom();
   SymbolInfoTick(symb,infotick);
   TimeToStruct(infotick.time,currentTime);

   if(1==1)
     {
      if(1==1)
        {
         double maD1200,maD120,maH120,atrH1200,price;

         maD1200=ValueofMA200.Main(0);
         maD120=ValueofMA20.Main(0);
         maH120=ValueofMAHour.Main(0);
         atrH1200=atr.Main(0);
         price=infotick.bid;
         double s_ep,s_sl,s_tp;
         double b_ep,b_sl,b_tp;


         if(1==1)
           {
            b_ep=price-atrH1200;
            b_sl=b_ep-(b_ep*S_L)/100;
            b_tp=b_ep+(b_ep*T_P)/100;
            T_M.BuyLimit(LOT_FOR_TRADE,b_ep,symb,b_sl,b_tp,ORDER_TIME_DAY,0,"BuyLimit");
           }
         if(1==1)
           {
            s_ep=price+atrH1200;
            s_sl=s_ep+(s_ep*S_L)/100;
            s_tp=s_ep-(s_ep*T_P)/100;

            T_M.SellLimit(LOT_FOR_TRADE,s_ep,symb,s_sl,s_tp,ORDER_TIME_DAY,0,"SellLimit");
           }
}

     }
  }
//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
//---

  }
//+------------------------------------------------------------------+
void RefCustom()
  {
   ValueofMA200.Refresh();
   ValueofMA20.Refresh();
   ValueofMAHour.Refresh();
   atr.Refresh();
  }
//+------------------------------------------------------------------+

 
SILVERPRINT:


Errores. No compilar.

 
Vladimir Karputov:

Errores. No se compila.


Lo siento, inténtalo ahora.

 
SILVERPRINT:

Lo siento, inténtalo ahora.


Probablemente de la noche a la mañana - por lo que no entiendo en absoluto QUÉ es lo que está tratando de hacer.

Un consejo:

  • INICIALIZAR las variables al declarar
  • al dividir, dividir por el doble, no por el int (por ejemplo, número 100,0 -> doble, número 100 -> int)
  • ¿qué es este estilo if(1==1) - ? Esto es monstruoso, nunca lo escribas así.
  • Por último, y lo más importante, deja sólo tres líneas en tu código,

            b_ep=price-atrH1200;
            b_sl=b_ep-(b_ep*S_L)/100;
            b_tp=b_ep+(b_ep*T_P)/100;

  • y declarar e inicializar las variables explícitamente. Por ejemplo, así:

   double price=1.05848;
   double atrH1200=1.05168;
   double T_P=0.81;
   double S_L=0.35;

   double b_ep=price-atrH1200;
   double b_sl=b_ep-(b_ep*S_L)/100.0;
   double b_tp=b_ep+(b_ep*T_P)/100.0;
   DebugBreak();
 
Vladimir Karputov:

Probablemente de la noche a la mañana - por lo que no entiendo NADA de lo que estás tratando de hacer.

Un consejo:

  • al declarar las variables INITIALIZE
  • al dividir, dividir por el doble, no por el int (por ejemplo, número 100,0 -> doble, número 100 -> int)
  • ¿qué es este estilo if(1==1) - ? Esto es monstruoso, nunca lo escribas así.
  • Por último, y lo más importante, deja sólo tres líneas en tu código,

  • y declarar e inicializar las variables explícitamente. Por ejemplo, así:


Gracias increíblemente útil.

 
Curiosamente, la función funciona incluso si hay más órdenes que cero.
if(OrdersTotal()==0)

No hay muchadiferencia, pero cuando la función no funciona, puede abrir todo el depósito.

 
SILVERPRINT:
Extraño pero la función, funciona incluso si hay más órdenes que cero.

No hace muchadiferencia, pero cuando la función no funciona puede abrir todo el depósito.

Abra la ayuda de MT5 para la función y asegúrese de que entiende correctamente lo que es una orden en MT5

 
Presioné y presioné F1, no pude encontrar...

¿Pueden decirme cómo determinar los _Dígitos para otro carácter?
Razón de la queja: