Download MetaTrader 5
To add comments, please log in or register
Do you want to order an application? Find out how to obtain the desired result
fly7680
322
fly7680 2016.10.06 18:55 

Hello everyone, I should add in the Alert pop-up, the value of a variable double , but as I wrote the code is not good.

#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 White
#property indicator_label1 ""

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 White
#property indicator_label2 ""



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

extern int    Periodo       = 2;
extern double RSI_max       = 95;
extern double RSI_min       = 5;
extern double DistanzaIcona = 1;
extern int    Percent       = 30;
extern bool   Audible_Alerts = true;
datetime time_alert; //used when sending alert
double   myPoint;    //initialized in OnInit

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

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 159);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 159);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   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++;
   
   //--- 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 
   
   int BarShift   = i + 1; 
//-------------------Calcolo % Ombra/Copro Parametri in comune--------------
   double
   CandleOpen     = Open [BarShift],
   CandleClose    = Close[BarShift],
   CandleHigh     = High [BarShift],
   CandleLow      = Low  [BarShift],
   CandleRange    = CandleHigh - CandleLow, // Escursione Totale
   BodyHigh       = fmax( CandleOpen, CandleClose ),
   BodyLow        = fmin( CandleOpen, CandleClose ),
//------------------Calcolo % Ombra/Copro Candela Verde---------------------
   WickUpperRange = CandleHigh - BodyHigh, // High-Close
   WickLowerRange = BodyLow -  CandleLow, //  Open-Low
   WickRange      = WickUpperRange + WickLowerRange, // Somma Ombre
   WickRatio      = ( CandleRange != 0.0  ) ? WickRange / CandleRange : 0.0, 
   WickPercentage = WickRatio * 100.0;
//-------------------------------------------------------------------------- 
       
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, Periodo, PRICE_CLOSE, 1+i) > RSI_max //Relative Strength Index > fixed value
      && WickPercentage < Percent
      
      )
        {
         Buffer1[1+i] = High[1+i] + DistanzaIcona * myPoint; //Set indicator value at Candlestick High + fixed value
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell", WickPercentage); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      
      //Indicator Buffer 2
      if(iRSI(NULL, PERIOD_CURRENT, Periodo, PRICE_CLOSE, 1+i) < RSI_min //Relative Strength Index < fixed value
      && WickPercentage < Percent
      )
        {
         Buffer2[1+i] = Low[1+i] - DistanzaIcona * myPoint; //Set indicator value at Candlestick Low - fixed value
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Sell"); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
whroeder1
13602
whroeder1 2016.10.12 21:03  
fly7680: I should add in the Alert pop-up, the value of a variable double , but as I wrote the code is not good.
void myAlert(string type, string message){
  1. No it's not. So fix it.
  2. 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.
Keith Watford
Moderator
7892
Keith Watford 2016.10.13 01:02  

Make sure that you pass the correct number of parameters to a function.

Use DoubleToStr() to convert a double to a string.

/
To add comments, please log in or register