Cualquier pregunta de los recién llegados sobre MQL4 y MQL5, ayuda y discusión sobre algoritmos y códigos - página 579

 
PolarSeaman:
Todavía no he descubierto cómo contar los segundos hasta que la barra se cierra en el período actual. Necesito tu ayuda.

Te he dado la función.

 
Artyom Trishkin:

Te he dado la función.

Sí, pero el código de arriba, en el comentario, hace una cuenta atrás suave cada segundo y la función es brusca. En M1, de 60 barras, 3 o 4 veces no hay alerta.

#property strict
#define  MILLISEC_TIMER_INTERVAL         500 
//--- input parameters
input int s_clo=2;
input int Period_=13,
Shift_=0;
input     ENUM_MA_METHOD Method_MA_=MODE_SMA;
input ENUM_APPLIED_PRICE Apply_to_=PRICE_CLOSE;
double ma_fast;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
{

   if(!EventSetMillisecondTimer(MILLISEC_TIMER_INTERVAL))
   {
      Print("Не могу запустить таймер");
      return INIT_FAILED;
   }
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTimer()
  {
   RefreshRates();
//---
ma_fast=0;
   if(SecondsToCandleClose(Symbol(),0)>=s_clo)return;
   
   { ma_fast=ma(Period_,Shift_,Method_MA_,Apply_to_,0); Alert("ma_fast",ma_fast,"время откр. бара ",Time[0]);}
   
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
long SecondsToCandleClose(const string symbol_name,const ENUM_TIMEFRAMES timeframe)
  {
   datetime array[];
   return(CopyTime(symbol_name,timeframe,0,1,array)==1 ? PeriodSeconds(timeframe)+array[0]-TimeCurrent() : 0);
  }

//+------------------------------------------------------------------+
double ma(int period,int ma_shift,ENUM_MA_METHOD ma_method,ENUM_APPLIED_PRICE ap_price,int shift)
  {
   return(ND(iMA(NULL,(int)0,period,ma_shift,ma_method,ap_price,shift)));
  }
  //
  double ND(double A)
  {
   return(NormalizeDouble(A,Digits));
  }
  //
 
PolarSeaman:

Sí, pero el código de arriba, en el comentario, hace una cuenta atrás suave cada segundo, mientras que la función es brusca. En M1, de 60 barras 3 o 4 veces no hay alerta.

Esto se debe a que la función utiliza TimeCurrent() - hora de llegada de la última cita. Debe sustituir esta hora por una local TimeLocal() con un desplazamiento calculado (ya se le ha explicado).

 
Artyom Trishkin:

Tienes que sustituir esta hora por la local TimeLocal() con un desplazamiento calculado (ya te lo han dicho)

No sé cómo hacerlo bien, así que encontré un código que cuenta el tiempo para cerrar H1 sin ticks y tratando de usarlo, reemplacéTimeCurrent() en su función, pero no quiere mostrarme los segundos para cerrar.

#property strict
#property indicator_chart_window
//--- input parameters
#define  MILLISEC_TIMER_INTERVAL         500 
int            timeOffset;
datetime       ServerLocalOffset;
datetime       prevTime,myTime,localtime;
bool           newBar = false;
datetime sec;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   EventSetMillisecondTimer(MILLISEC_TIMER_INTERVAL);
   
  datetime srvtime,tmpOffset;
   RefreshRates();
   srvtime = TimeCurrent();
   // Modified
   localtime = TimeLocal()+TimeGMTOffset();
   if(TimeHour(srvtime)>TimeHour(localtime)){
      // Server Time is still ahead of us
      int newOffset = TimeHour(srvtime)-TimeHour(localtime);
      ServerLocalOffset = (newOffset*60*60);
   }else if(TimeHour(srvtime)<TimeHour(localtime)){
      // Server Time is Behind us
      int newOffset = TimeHour(localtime)-TimeHour(srvtime);
      ServerLocalOffset = (newOffset*60*60);
   }else{
      // No modification required
      ServerLocalOffset = srvtime;
   }
   localtime = TimeLocal()-ServerLocalOffset;
   
   tmpOffset = TimeSeconds(srvtime) - TimeSeconds(localtime);
   if(tmpOffset < 30 && tmpOffset >= 0){
      timeOffset = TimeSeconds(srvtime) - TimeSeconds(localtime);
   }
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   datetime localtime;
   localtime = TimeLocal()+(TimeGMTOffset()+(60*60));
 sec=Time[0]+Period()*60-localtime-timeOffset;//
 
 if(SecondsToCandleClose(Symbol(),0)<=2){Alert("время откр. бара ",Time[0]);}
      Comment(" Time 1: ",TimeToStr(sec,TIME_SECONDS )," Time 2: ",TimeToStr(SecondsToCandleClose(Symbol(),0),TIME_SECONDS ));
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
long SecondsToCandleClose(const string symbol_name,const ENUM_TIMEFRAMES timeframe)
  {
   datetime array[];
   return(CopyTime(symbol_name,timeframe,0,1,array)==1 ? PeriodSeconds(timeframe)+array[0]-sec : 0);
  }
////
 
Por favor, aconseja cómo implementar la idea en el código:
Si las garantías estaban abiertas y ahora no hay ninguna = Alerta.

Algo así probablemente...
doble x=0;
Si(TotalPedidos >0) {x=1;}
If (OrdersTotal <x) {Alert ;}
x=0;

 
Tigerfreerun:
Por favor, dime cómo implementar la idea en el código:
Si se han abierto las garantías y ahora no hay garantías = Alerta.

Algo de este estilo probablemente...
doble x=0;
Si (TotalPedidos >0) {x=1;}
If (OrdersTotal <x) {Alert ;}
x=0;

If(OrdersTotal ==0) {Alert ;}
 
Alekseu Fedotov:
If (OrdersTotal ==0) {Alert ;}
Entonces la señal es cíclica. Y aunque no se abriera ningún pedido. La idea es que 1) Las órdenes están abiertas 2) ahora no hay órdenes 3)1 Alerta
 

¡Chicos!

Hay muchos objetos en el gráfico.

Pero cuando se accede a ella.

Comment(ObjectsTotal());

Dice que sólo hay tres.

¿Por qué no cuenta flechas?


 
Tigerfreerun:
Por favor, dime cómo implementar la idea en el código:
Si las garantías estaban abiertas y ahora no hay ninguna = Alerta.

Algo así probablemente...
doble x=0;
Si (TotalPedidos >0) {x=1;}
If (OrdersTotal <x) {Alert ;}
x=0;

Hazlo así. El código es casi correcto. Sólo falta una palabra ahí:

static double x=0;
If (OrdersTotal >0) {x=1;} 
If (OrdersTotal <x) {Алерт ; x= 0;} 
 
Vladimir Tkach:

¡Chicos!

Hay muchos objetos en el gráfico.

Pero cuando se accede a ella.

Dice que sólo hay tres.

¿Por qué no cuenta flechas?


Tal vez porque sonsímbolos de la fuente Wingdings
Razón de la queja: