Pausar indicador por alguns minutos, depois do ultimo sinal

 

Olá, pessoal estou precisando de muita ajuda, não entendo muito de código mas criei esse código com videos no youtube,

preciso criar uma pausa entre os sinais do indicador, exemplo: pausar 10 min depois do ultimo sinal, já fiz de tudo mas não consigo obter exito.

em anexo tem um exemplo de como os sinais saem muito proximos.

na configuração abaixo quero pausar 240 segundos.

quem puder me ajudar fico muito grato.


#property version   "1.00"

#property description "Stoch"

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

#property indicator_type1 DRAW_ARROW
#property indicator_width1 2
#property indicator_color1 0x37DB12
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 2
#property indicator_color2 0x1212DB
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

datetime time_alert; //used when sending alert
input bool Audible_Alerts = true;
input bool Push_Notifications = true;
double myPoint; //initialized in OnInit
int Stochastic_handle;
double Stochastic_Main[];
double Stochastic_Signal[];
double Open[];
int ATR_handle;
double ATR[];
int _time_waiting=0;

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | estrategia25_75 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      if(Audible_Alerts) Alert(type+" | estrategia25_75 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
      if(Push_Notifications) SendNotification(type+" | estrategia25_75 @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   SetIndexBuffer(0, Buffer1);
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(0, PLOT_ARROW, 241);
   SetIndexBuffer(1, Buffer2);
   PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(1, PLOT_ARROW, 242);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   Stochastic_handle = iStochastic(NULL, PERIOD_CURRENT, 5, 2, 3, MODE_LWMA, STO_LOWHIGH);
   if(Stochastic_handle < 0)
     {
      Print("The creation of iStochastic has failed: Stochastic_handle=", INVALID_HANDLE);
      Print("Runtime error = ", GetLastError());
      return(INIT_FAILED);
     }
   
   ATR_handle = iATR(NULL, PERIOD_CURRENT, 14);
   if(ATR_handle < 0)
     {
      Print("The creation of iATR has failed: ATR_handle=", INVALID_HANDLE);
      Print("Runtime error = ", GetLastError());
      return(INIT_FAILED);
     }
   
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| 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[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   datetime Time[];
   
   if(CopyBuffer(Stochastic_handle, MAIN_LINE, 0, rates_total, Stochastic_Main) <= 0) return(rates_total);
   ArraySetAsSeries(Stochastic_Main, true);
   if(CopyBuffer(Stochastic_handle, SIGNAL_LINE, 0, rates_total, Stochastic_Signal) <= 0) return(rates_total);
   ArraySetAsSeries(Stochastic_Signal, true);
   if(CopyOpen(Symbol(), PERIOD_CURRENT, 0, rates_total, Open) <= 0) return(rates_total);
   ArraySetAsSeries(Open, true);
   if(CopyBuffer(ATR_handle, 0, 0, rates_total, ATR) <= 0) return(rates_total);
   ArraySetAsSeries(ATR, true);
   if(CopyTime(Symbol(), Period(), 0, rates_total, Time) <= 0) return(rates_total);
   ArraySetAsSeries(Time, true);
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(Stochastic_Main[i] > Stochastic_Signal[i]
      && Stochastic_Main[i+1] < Stochastic_Signal[i+1] //Stochastic Oscillator crosses above Stochastic Oscillator
      && Stochastic_Main[i] < 50 //Stochastic Oscillator < fixed value
      && Stochastic_Main[i] > 25 //Stochastic Oscillator > fixed value
      )
        {
         
         if( TimeLocal() - time_alert < 240 )
                    
                  time_alert = TimeLocal(); // the pause ends in 10 seconds after the current local time
         while ( TimeLocal() < _time_waiting )
         {}
         
         Buffer1[i] = Open[i] - ATR[i]; //Set indicator value at Candlestick Open - Average True Range
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      if(Stochastic_Main[i] < Stochastic_Signal[i]
      && Stochastic_Main[i+1] > Stochastic_Signal[i+1] //Stochastic Oscillator crosses below Stochastic Oscillator
      && Stochastic_Main[i] > 50 //Stochastic Oscillator > fixed value
      && Stochastic_Main[i] < 75 //Stochastic Oscillator < fixed value
      )
        {
         
         
         if( TimeLocal() - time_alert < 240 )
         
                    
                  time_alert = TimeLocal(); // the pause ends in 10 seconds after the current local time
         while ( TimeLocal() < _time_waiting )
         {}
         
         Buffer2[i] = Open[i] + ATR[i]; //Set indicator value at Candlestick Open + Average True Range
         
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Arquivos anexados:
graf.png  6 kb
 

Fala meu xará, beleza? Rsrs

Primeira coisa mano, quando for postar um código aqui na comunidade utilize o campo de código (Alt+S), dessa forma ele fica organizado e colorido. Um dos moderadores pode te dar uma advertência ou até mesmo apagar seu post.

Com respeito a sua dúvida você pode utilizar o evento Timer. Para saber como funciona veja esta aula: https://www.youtube.com/watch?v=BzNrVzr9JHc

Abraço =D

 

Pode usar uma variável para considerar o tempo.

datetime NotBefore=TimeCurrent()-1;
if (TimeCurrent()>NotBefore
{
 NotBefore=TimeCurrent()+240;
}

Razão: