Retardar o alerta por vários segundos - página 2

 
OnTimer()
 
Obrigado eevviill, mas minhas habilidades são muito complicadas. Estou começando com a programação, eles são autodidatas e é difícil para mim entender algumas coisas.
Obrigado por tudo, Massimo.
 
omissamf:
Obrigado eevviill, mas minhas habilidades são muito complicadas. Estou começando com a programação, eles são autodidatas e é difícil para mim entender algumas coisas.
Obrigado por tudo, Massimo.
int seconds=3;

int OnInit()
  {  
   EventSetTimer(seconds);
 
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 241);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 242);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }
//_____________________________________________
//_____________________________________________
int start()
{
return(0);
}

void OnTimer(){
     
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, 0) < 30
      
      )
        {
         Buffer1[0] = Low[0] - iATR(NULL, PERIOD_CURRENT, 14, 0); //Set indicator value at Candlestick Low - Average True Range
         if(0 == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer1[0] = 0;
        }
      //Indicator Buffer 2
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, 0) > 70
     
      )
        {
         Buffer2[0] = High[0] + iATR(NULL, PERIOD_CURRENT, 14, 0); //Set indicator value at Candlestick High + Average True Range
         if(0 == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer2[0] = 0;
        }
     }
  
  }
 
Obrigado eevviill, seu código funciona, mas não sou do sinal após três segundos que abriu a vela, mas se, por exemplo, o RSI estiver acima do nível 70 após 30 segundos que a vela está aberta, o código deixa 3/2 ainda e depois traz a seta para cima.
Por enquanto o código que mais se aproxima é aquele que sugeriu I GumRai, mas me dá o sinal e define a abertura da vela e não depois de 3 segundos.

Obrigado por tudo, Massimo.

int start(){
if (BarStart !=Time[0]) 
{
  BarStart = Time[0]; 
//This is the code suggested by GumRai. This works well, but the arrow appears and fixed the opening of the candle, instead of 3 seconds after its opening.
 

mas eu nãosou dosinal apóstrês segundosque abriua vela

É melhor escrever primeiro e não "preciso de alerta a cada 3 segundos".

 
extern int seconds=3;
int time_dif;
bool current_candle_alert_been;
int prev_bars;

int OnInit()
  { 
prev_bars=Bars;
 
   EventSetTimer(1);
   time_dif=int(TimeLocal()-TimeCurrent());
   ...


void OnTimer()
{
if(Bars!=prev_bars) current_candle_alert_been=false;
prev_bars=Bars;

if(current_candle_alert_been) return;
if(TimeLocal()-time_dif<Time[0]+seconds) return;
current_candle_alert_been=true;



...
 
   static datetime BarStart=0;
   static bool check=false;
   if(BarStart!=Time[0])
     {
      BarStart=Time[0];
      check=true;
     }
   if(check && TimeCurrent()>=Time[0]+3)
     {
      check=false;
      //Check Condition
     }

Isto deve ser verificado no primeiro tick recebido que é pelo menos 3 segundos após o tempo de abertura do bar

Observe que se a barra tiver sido aberta n segundos quando o indicador for inicializado e n for >3, ela será verificada nesse momento. Também, obviamente, não funcionará com barras históricas.

 
GumRai:

Isto deve ser verificado no primeiro tick recebido que é pelo menos 3 segundos após o tempo de abertura do bar

Observe que se a barra tiver sido aberta n segundos quando o indicador for inicializado e n for >3, ela será verificada nesse momento. Também, obviamente, não funcionará com barras históricas.

:))))

1)Gostaria de modificar este código para que o alerta, em vez de aparecer na abertura da vela, detecte as condições após alguns segundos.

2)Mas nãosou dosinal depois detrês segundosque abriua vela

P.S. Não usar Tempo[0], usar Barras

 
eevviill:

:))))

1)Gostaria de modificar este código para que o alerta, em vez de aparecer na abertura da vela, detecte as condições após alguns segundos.

2)Mas nãosou dosinal apóstrês segundosque abriua vela


Qual é o seu objetivo?

eevviill:

:))))


P.S. Não usar Tempo[0], usar Barras

Por que não? Não há nada de errado em usar o Time[0] para detectar uma nova barra.

 
Oi pessoal, vocês são ótimos !!!
Não sei como agradecer a vocês por sua colaboração.
O código postado eevviill funciona muito bem, foi o que eu quis dizer.
O código GumRai , ao invés disso, faz repintar e dar o sinal sempre que o RSI cruza os níveis 30/70.
Eu inseri o código de trabalho de acordo com as sugestões do eevviill, esperando que ele sirva mais.

Obrigado por tudo, Massimo.


//+------------------------------------------------------------------+
//|                                                   Test Delay.mq4 |
//|                                                          Massimo |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Massimo"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description ""

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property  indicator_type1 DRAW_ARROW
#property  indicator_width1 1
#property  indicator_color1 0xFFAA00
#property  indicator_label1 "Buy"

#property  indicator_type2 DRAW_ARROW
#property  indicator_width2 1
#property  indicator_color2 0x0000FF
#property  indicator_label2 "Sell"


extern int seconds =3;
int time_dif;
bool current_candle_alert_been;
int prev_bars;



datetime time_alert; //used when sending alert
//--- indicator buffers
double Buffer1[];
double Buffer2[];

extern int Period1 = 2;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Test @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   prev_bars=Bars;
    EventSetTimer(1);
   time_dif=int(TimeLocal()-TimeCurrent());
   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 241);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 242);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }
//________________________________
 
int start()
{
return(0);
}

//_________________________________

void OnTimer(){
{
if(Bars!=prev_bars) current_candle_alert_been=false;
prev_bars=Bars;

if(current_candle_alert_been) return;
if(TimeLocal()-time_dif<Time[0]+seconds) return;
current_candle_alert_been=true;
     
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, Period1, PRICE_CLOSE, 0) < 30
      
      )
        {
         Buffer1[0] = Low[0] - iATR(NULL, PERIOD_CURRENT, 14, 0); //Set indicator value at Candlestick Low - Average True Range
         if(0 == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer1[0] = 0;
        }
      //Indicator Buffer 2
      if(iRSI(NULL, PERIOD_CURRENT, Period1, PRICE_CLOSE, 0) > 70
     
      )
        {
         Buffer2[0] = High[0] + iATR(NULL, PERIOD_CURRENT, 14, 0); //Set indicator value at Candlestick High + Average True Range
         if(0 == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer2[0] = 0;
        }
     }
     }
 //-----------------------------------------------------------------------------------------------------------------------------