semplice alert...

 

Buongiorno a tutti

vorrei sapere se qualcuno può scrivermi un semplice alert basato su una linea retta ...mi spiego vorrei che una volta messa la linea orizzontale mi suonasse un alert quando il prezzo attraversa e chiude sotto o sopra di questa a secondo della modalita che si sceglie

Good morning everyone


I would like to know if someone can write me a simple alert based on a straight line ... let me explain I would like that once the horizontal line has been placed, an alert will sound when the price crosses and closes below or above it depending on the method chosen

 
5073095:

Buongiorno a tutti

vorrei sapere se qualcuno può scrivermi un semplice alert basato su una linea retta ...mi spiego vorrei che una volta messa la linea orizzontale mi suonasse un alert quando il prezzo attraversa e chiude sotto o sopra di questa a secondo della modalita che si sceglie

Good morning everyone


I would like to know if someone can write me a simple alert based on a straight line ... let me explain I would like that once the horizontal line has been placed, an alert will sound when the price crosses and closes below or above it depending on the method chosen

try this indicator 

#property copyright "discussion"
#property link      "https://www.mql5.com/en/forum/450744"
#property version   "1.00"
#property indicator_chart_window
#define SYSTEM_TAG "LineAlerter_"
input double thePrice=1.14;//the price 
enum type_of_alert{
alert_touch=0,//touch
alert_close=1//close beyond
};
input type_of_alert theType=alert_touch;//type of alert
input color lineColor=clrRed;//color
input int lineWidth=1;//line width
input ENUM_LINE_STYLE lineStyle=STYLE_DASH;//line style
bool alertSetup=false,alertFired=false;
bool isAbove=false,isBelow=false;
datetime barStamp=0;

int OnInit()
  {
  ObjectsDeleteAll(ChartID(),SYSTEM_TAG);
  alertFired=false;
  alertSetup=false;
  isAbove=false;
  isBelow=false;
  barStamp=0;
  return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  ObjectsDeleteAll(ChartID(),SYSTEM_TAG);
  alertFired=false;
  alertSetup=false;
  isAbove=false;
  isBelow=false;
  barStamp=0;
  }
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[])
  {
  if(!alertSetup&&SymbolIsSynchronized(_Symbol)&&rates_total>0)
    {
    //setup the alert 
      //touch
        if(theType==alert_touch){
        if(close[rates_total-1]>thePrice){isAbove=true;}
        else if(close[rates_total-1]<thePrice){isBelow=true;}
        else{Alert("the price is on the alert price , lol xD");}
        alertSetup=true;
        }
      //close  
        else{
        if(close[rates_total-2]>thePrice){isAbove=true;}
        else if(close[rates_total-2]<thePrice){isBelow=true;}
        else{Alert("the price is on the alert price , lol xD");}
        alertSetup=true;
        barStamp=time[rates_total-1];
        }
        ObjectCreate(ChartID(),SYSTEM_TAG+"_Line",OBJ_HLINE,0,time[rates_total-1],thePrice);
        ObjectSetInteger(ChartID(),SYSTEM_TAG+"_Line",OBJPROP_COLOR,lineColor);
        ObjectSetInteger(ChartID(),SYSTEM_TAG+"_Line",OBJPROP_WIDTH,lineWidth);
        ObjectSetInteger(ChartID(),SYSTEM_TAG+"_Line",OBJPROP_STYLE,lineStyle);
    }
  if(alertSetup&&!alertFired){
    //touch 
      if(theType==alert_touch){
      //above
        if(isAbove){
        if(close[rates_total-1]<thePrice){
          Alert(_Symbol+" the price touch below "+DoubleToString(thePrice,_Digits));
          alertFired=true;
          }
        }
      //below
        else{
        if(close[rates_total-1]>thePrice){
          Alert(_Symbol+" the price touch above "+DoubleToString(thePrice,_Digits));
          alertFired=true;
          }
        }
      }
    //close 
      else{
      if(time[rates_total-1]>barStamp){
        //above
          if(isAbove){
          if(close[rates_total-2]<thePrice){
            Alert(_Symbol+" the price closed below "+DoubleToString(thePrice,_Digits));
            alertFired=true;            
            }
          } 
        //below
          else{
          if(close[rates_total-2]>thePrice){
            Alert(_Symbol+" the price closed above "+DoubleToString(thePrice,_Digits));
            alertFired=true;
            }
          }        
        }
      }
    }
  return(rates_total);
  }
//+------------------------------------------------------------------+
 
Lorentzos Roussos #:

try this indicator 

grazie mille.... gentilissimo