Quaisquer perguntas de recém-chegados sobre MQL4 e MQL5, ajuda e discussão sobre algoritmos e códigos - página 579

 
PolarSeaman:
Ainda não descobrimos como contar os segundos até que a barra feche no período atual. Eu preciso de sua ajuda.

Eu lhe dei a função.

 
Artyom Trishkin:

Eu lhe dei a função.

Sim, mas o código acima, no comentário, faz uma contagem regressiva a cada segundo, enquanto a função é estúpida. Na M1, de 60 barras 3 ou 4 vezes não há 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:

Sim, mas o código acima, no comentário, faz uma contagem regressiva a cada segundo, enquanto a função é estúpida. Na M1, de 60 barras 3 ou 4 vezes não há alerta.

Isso porque a função utiliza TimeCurrent() - hora de chegada da última cotação. Você precisa substituir este tempo por um TimeLocal() local por uma compensação calculada (você já foi informado sobre isso).

 
Artyom Trishkin:

Você precisa substituir este tempo por TimeLocal() local por offset calculado (você já foi informado sobre isso)

Eu não sei como fazê-lo corretamente, então encontrei um código que conta o tempo para fechar o H1 sem ticks e tentando usá-lo, substituí oTimeCurrent() em sua função, mas ele não quer me mostrar segundos para fechar.

#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);
  }
////
 
Favor aconselhar como implementar a idéia no código:
Se os mandados estivessem abertos e agora não houvesse nenhum = Alerta.

Algo como isto provavelmente...
duplo x=0;
Se(OrderTotal >0) {x=1;}
Se (OrdensTotal <x) {Alerta ;}
x=0;

 
Tigerfreerun:
Por favor, me diga como implementar a idéia no código:
Se os mandados foram abertos e agora não há mandados = Alerta.

Algo neste estilo provavelmente...
duplo x=0;
Se (OrderTotal >0) {x=1;}
Se (OrdensTotal <x) {Alerta ;}
x=0;

Se(OrdersTotal ==0) {Alert ;}
 
Alekseu Fedotov:
Se (OrdersTotal ==0) {Alert ;}
Então o sinal é cíclico. E mesmo que nenhuma ordem tenha sido aberta. A idéia é que 1) as ordens estão abertas 2) agora não há ordens 3)1 Alerta
 

Gente!

Há muitos objetos no gráfico.

Mas quando você tem acesso a ele.

Comment(ObjectsTotal());

Diz que são apenas três.

Por que não está contando flechas?


 
Tigerfreerun:
Por favor, me diga como implementar a idéia no código:
Se os mandados estivessem abertos e agora não houvesse nenhum = Alerta.

Algo como isto provavelmente...
duplo x=0;
Se (OrderTotal >0) {x=1;}
Se (OrdensTotal <x) {Alerta ;}
x=0;

Faça-o assim. O código está quase correto. Apenas uma palavra está faltando ali:

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

Gente!

Há muitos objetos no gráfico.

Mas quando você tem acesso a ele.

Diz que são apenas três.

Por que não está contando flechas?


Talvez por seremsímbolos da fonte Wingdings
Razão: