Download MetaTrader 5
To add comments, please log in or register
Interested in traders' opinion? Arrange a poll on the Forum!
Massimo
479
Massimo 2016.02.26 21:33 
Hello everyone.
I would like to modify this code so that the alert, instead of appearing at the opening of the candle, detects the conditions after a few seconds.

Thanks for everything, Massimo.


int start(){
if (BarStart !=Time[0]) 
{
  BarStart = Time[0]; 

  //Indicator Buffer 1
     
       if ( iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, 0+1) > 70
      
      
      )
        {
         Buffer1[0] = Low[0] - iATR(NULL, PERIOD_CURRENT, 14, 0); //Set indicator value at Candlestick Low - Average True Range
        }
      else
        {
         Buffer1[0] = 0;
        }
      //Indicator Buffer 2
    
      && iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, 0) < 30
     
      )
        {
         Buffer2[0] = High[0] + iATR(NULL, PERIOD_CURRENT, 14, 0); //Set indicator value at Candlestick High + Average True Range
        }
      else
        {
         Buffer2[0] = 0;
        }
     }
   return(0);
  }
whroeder1
14240
whroeder1 2016.02.27 00:50  
omissamf: I would like to modify this code
  1. So what's stopping you. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. Have you tried
      BarStart = Time[0]; 
      Sleep(3000); RefreshRates();

Massimo
479
Massimo 2016.02.27 01:16  
Hello WHRoeder , thanks for the reply . I apologize for my behavior , but it was not my intent to offend and disrespect to anyone. I tried all day to change the code to accomplish this , but I did not succeed . They are the beginning of the study MQL4 . I ask again apologize administrators . Greetings , Massimo
Massimo
479
Massimo 2016.03.01 00:14  

Hello WHRoeder, I tried, but don't work!!! I tried in all ways, but do not understand where I'm wrong!!

Anyway, thanks for everything, Massimo. 

Keith Watford
Moderator
9546
Keith Watford 2016.03.01 00:20  
I don't see an alert in your code
Massimo
479
Massimo 2016.03.01 15:00  
Hello GunRai, I send you the complete code, so I'll explain. I could not delay the confirmation of the conditions of the candel opening (as it is doing now), but after 3 seconds, even the suggestion of WHRoeder. I can not understand where I'm wrong !!!

Thanks, Max.


//+------------------------------------------------------------------+
//|                                                    RSI 70-30.mq4 |
//|                                                          Massimo |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Massimo"
#property link      "https://www.mql5.com"
#property version   "1.00"
#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"
static datetime BarStart=0;

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

datetime time_alert; //used when sending alert
extern bool Audible_Alerts = true;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | RSI 30-70 @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      if(Audible_Alerts) Alert(type+" | RSI 30-70 @ "+Symbol()+","+Period()+" | "+message);
     }
  }
  
  //+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   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(){
if (BarStart !=Time[0]) 
{
  BarStart = Time[0]; 
   Sleep(3000); RefreshRates(); //this code don't work

//
     
      //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;
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
whroeder1
14240
whroeder1 2016.03.01 19:11  
You are correct; you are running an indicator.
int start(){
if (BarStart !=Time[0]) 
{
  BarStart = Time[0]; 
   Sleep(3000); RefreshRates(); //this code don't work
Try this
#define  MAX_DATETIME   D'3000.12.31 23:59:59'  // 32,535,215,999
#define  MIN_DATETIME   D'1970.01.01 00:00:00'  // Zero.

int start(){
static datetime alertTime = MAX_DATETIME;
if(TimeCurrent() > alertTime){ alertTime = MAX_DATETIME; Alert(...); }
if (BarStart !=Time[0]) 
{
  BarStart = Time[0]; 
  :
  if(condition) alertTime = TimeCurrent() + 3; // Delay
Massimo
479
Massimo 2016.03.01 22:27  
WHRoeder:
You are correct; you are running an indicator.
Try this

Thanks, now I study the code you posted me and then let you know.
For now, infinite thanks, Massimo.
Massimo
479
Massimo 2016.03.02 17:00  
WHRoeder:
You are correct; you are running an indicator.
y thi

WHRoeder Hello, I tried to change the code with your instructions. I tried various ways and that's what you send is what you have not errors, but the delay of about five seconds there is only sull'alert sound, while the arrows keep appearing exact opening of the candle.

Hello and thank you, Massimo.

#define  MAX_DATETIME   D'3000.12.31 23:59:59'  // 32,535,215,999
#define  MIN_DATETIME   D'1970.01.01 00:00:00'  // Zero.


int start(){
static datetime alertTime = MAX_DATETIME;
if (TimeCurrent() > alertTime)
{ alertTime = MAX_DATETIME;
 Alert(“ ATTENTION!!!!); }

if (BarStart !=Time[0]) 
{
  BarStart = Time[0]; 
  
//
     
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, 0) < 30
      
      )
        {
         alertTime = TimeCurrent() + 3;
         Buffer1[0] = Low[0] - iATR(NULL, PERIOD_CURRENT, 14, 0);        }
      else
        {
         Buffer1[0] = 0;
        }
      //Indicator Buffer 2
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, 0) > 70
     
      )
        {
                     alertTime = TimeCurrent() + 3;
         Buffer2[0] = High[0] + iATR(NULL, PERIOD_CURRENT, 14, 0);                }
      else
        {
         Buffer2[0] = 0;
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+





whroeder1
14240
whroeder1 2016.03.02 18:11  
omissamf: there is only sull'alert sound, 
  1. No idea what you meant.
  2. Alert( ATTENTION!!!!); }
    Try/post code that compiles.
Massimo
479
Massimo 2016.03.02 18:26  
WHRoeder:
  1. No idea what you meant.
  2. Try/post code that compiles.
I put ATTENTION !!! because it is the one that appears in sound / visual alert, but I'm trying, with your help, to delay the onset of the Arrow few seconds. In this case. Attention !!! It will appear after 5 seconds, while Arrows appear just open the candle.
Thanks for everything, Massimo.
/ /12345
To add comments, please log in or register