延缓警报几秒钟 - 页 2

 
计时器上(OnTimer)。
 
谢谢 eevviill 我的技能 太复杂 开始 接触编程, 他们是 自学的 理解 一些东西
谢谢你做的一切 Massimo
 
omissamf:
谢谢 eevviill 我的技能 太复杂 开始 接触编程, 他们是 自学的 理解 一些东西
谢谢你做的一切 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;
        }
     }
  
  }
 
谢谢 eevviill,你的 代码工作 但我不是 信号后 三秒 ,打开 蜡烛 但如果 例如 RSI 70 级以上30秒后蜡烛 是开放的 代码 3/2 尚未 ,然后 提出箭头
目前最接近的 代码 谁建议我 GumRai 给我的 信号和 设置的 蜡烛开放 ,而不是 在3

谢谢你做的一切 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.
 

但我不是三秒信号打开了蜡烛

最好先写出来,而不是 "我需要每3秒的警报"。

 
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
     }

这应该在第一个收到的tick点上进行检查,该tick点至少在条形图打开时间 后3秒。

请注意,如果指标初始化时,条形图已经打开了n秒,并且n>3,它将在那个时候被检查。另外,很明显,它对历史条形图不起作用。

 
GumRai:

这应该是在收到的第一个刻度线时进行检查,该刻度线至少在条形图打开时间后3秒。

注意,如果在指标初始化时,条形图已经打开了n秒,并且n>3,那么它将在那个时候被检查。另外,很明显,它对历史条形图不起作用。

:))))

1)我想修改这段代码,使警报不是在蜡烛开盘时出现,而是在几秒钟后检测条件。

2)但是我没有开盘三秒收到信号

P.S. 不要使用Time[0],使用Bars

 
eevviill:

:))))

1)我想修改这段代码,使警报不是在蜡烛开盘时出现,而是在几秒钟后检测条件。

2)但我没有三秒打开蜡烛信号


你的观点是什么?

eevviill

:))))


P.S. 不要使用Time[0],使用Bars

为什么不呢?使用Time[0]来检测一个新的条形图并没有错。

 
嗨,伙计们 你们真 了不起 !!! 我不知道该如何感谢你们的合作。
我不知道 该如何感谢你们 的合作
eevviill 发布的 代码 工作得很好,这就是 我的意思。
GumRai 代码 RSI 越过 30/70 水平 重绘 给出 信号
根据 eevviill 的建议 插入了 工作代码 希望它能 发挥 更大的 作用

谢谢你做的一切 马西莫


//+------------------------------------------------------------------+
//|                                                   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;
        }
     }
     }
 //-----------------------------------------------------------------------------------------------------------------------------