help on new developed indicator

 

the arrow doesnt show on live until i switch time frame , please help me .

below is the codes.

//+------------------------------------------------------------------+
//|                                              signalindicator.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Yellow
#property indicator_color3 Aqua
#property indicator_color4 Red

#property indicator_color4 Red

extern int FastEMA = 5;
extern int SlowEMA = 6;
extern int RSIPeriod = 7;
extern bool Alerts = TRUE;
double buffer_1[];
double buffer_2[];
double arrow_1[];
double arrow_2[];
int a = 0;
int b = 0;
double x = 0.0;
double y = 0.0;
 double alertshow;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, buffer_1);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, buffer_2);
   SetIndexStyle(2, DRAW_ARROW, 0,4);
   SetIndexArrow(2, 241);
   SetIndexBuffer(2, arrow_1);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW, 0,4);
   SetIndexArrow(3, 242);
   SetIndexBuffer(3, arrow_2);
   SetIndexEmptyValue(3, 0.0);

   return (0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return (0);
  }
//+------------------------------------------------------------------+
//| expert start 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 counted_bars = IndicatorCounted();
   double irsi_1 = 0;
   int li_0;
   bool c = FALSE;
   double price_10 = 0;
   if (counted_bars < 0) return (-1);
   if (counted_bars > 0) counted_bars--;
   if(counted_bars==0)
      li_0=MathMin(Bars-10-1,Bars-MathMax(FastEMA,SlowEMA)-1);
   else
      li_0=Bars-counted_bars;
   for (int i = 0; i < li_0; i++) {
      buffer_1[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      buffer_2[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      irsi_1 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i);
      x = buffer_1[i] - buffer_2[i];
      if (x > 0.0 && irsi_1 > 50.0) a = 1;
      else
         if (x < 0.0 && irsi_1 < 50.0) a = 2;
      if (a == 1 && b == 2) {
         arrow_2[i - 1] = High[i - 1] - 5.0 * Point;
         c= TRUE;
         price_10 = Ask;
      } else {
         if (a == 2 && b == 1) {
            arrow_1[i - 1] = Low[i - 1] - 5.0 * Point;
            c = TRUE;
            price_10 = Bid;
         }
      }
      b = a;
      y = x;
   }
   if (Alerts && c) {
      PlaySound("alert.wav");
      if (b == 2)  
      
         if(alertshow<Time[1] && counted_bars!=0)
           {
            PlaySound("news.wav");// buy wav
            Alert(Symbol()," buy signal");
            alertshow=Time[1];
           }
      else
         if (b == 1) if(alertshow<Time[1] && counted_bars!=0)
           {
            PlaySound("news.wav");// buy wav
            Alert(Symbol(),"  sell signal");
            alertshow=Time[1];
           }
   }
//----
   return(prev_calculated);
  }
//+------------------------------------------------------------------+

 
 

Welcome,

  • Usually people who can't code don't receive free help on this forum, though it could happen if you are lucky, be patient.
  • If you show your attempts and describe well your problem, you will most probably receive an answer from the community.
  • If you don't want to learn to code, nothing bad, you can either look at the Codebase if something free already exists, or in the Market for paid products (sometimes free also).
  • Finally, you also have the option to hire a programmer in the Freelance section.
Good luck.
 
kewu:

the arrow doesnt show on live until i switch time frame , please help me .

below is the codes.

Problem is with this two lines of code:

arrow_2[i - 1] = High[i - 1] - 5.0 * Point;

 

arrow_1[i - 1] = Low[i - 1] - 5.0 * Point;

if i=0 than this lines generate "array out of range" error.

So if you want to draw signal arrows on current bar, than this should be:

arrow_2[i] = High[i] - 5.0 * Point;
arrow_1[i] = Low[i] - 5.0 * Point;

 or on prev. bar:

arrow_2[i+1] = High[i+1] - 5.0 * Point;
arrow_1[i+1] = Low[i+1] - 5.0 * Point;
 
Janusz Trojca:

Problem is with this two lines of code:

 

if i=0 than this lines generate "array out of range" error.

So if you want to draw signal arrows on current bar, than this should be:

 or on prev. bar:

Is still the sameting sir , in fact the arrow doesn't display base on my condition again .

Below is my code sir.

//+------------------------------------------------------------------+
//|                                              signalindicator.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Yellow
#property indicator_color3 Aqua
#property indicator_color4 Red

#property indicator_color4 Red

extern int FastEMA = 5;
extern int SlowEMA = 6;
extern int RSIPeriod = 7;
extern bool Alerts = TRUE;
double buffer_1[];
double buffer_2[];
double arrow_1[];
double arrow_2[];
int a = 0;
int b = 0;
double x = 0.0;
double y = 0.0;
 double alertshow;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, buffer_1);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, buffer_2);
   SetIndexStyle(2, DRAW_ARROW, 0,4);
   SetIndexArrow(2, 241);
   SetIndexBuffer(2, arrow_1);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW, 0,4);
   SetIndexArrow(3, 242);
   SetIndexBuffer(3, arrow_2);
   SetIndexEmptyValue(3, 0.0);

   return (0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return (0);
  }
//+------------------------------------------------------------------+
//| expert start 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 counted_bars = IndicatorCounted();
   double irsi_1 = 0;
   int li_0;
   bool c = FALSE;
   double price_10 = 0;
   if (counted_bars < 0) return (-1);
   if (counted_bars > 0) counted_bars--;
   if(counted_bars==0)
      li_0=MathMin(Bars-10-1,Bars-MathMax(FastEMA,SlowEMA)-1);
   else
      li_0=Bars-counted_bars;
   for (int i = 0; i < li_0; i++) {
      buffer_1[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      buffer_2[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      irsi_1 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i);
      x = buffer_1[i] - buffer_2[i];
      if (x > 0.0 && irsi_1 > 50.0) a = 1;
      else
         if (x < 0.0 && irsi_1 < 50.0) a = 2;
      if (a == 1 && b == 2) {
         arrow_2[i +1] = High[i +1] - 5.0 * Point;
         c= TRUE;
         price_10 = Ask;
      } else {
         if (a == 2 && b == 1) {
            arrow_1[i +1] = Low[i +1] - 5.0 * Point;
            c = TRUE;
            price_10 = Bid;
         }
      }
      b = a;
      y = x;
   }
   if (Alerts && c) {
      PlaySound("alert.wav");
      if (b == 2)  
      
         if(alertshow<Time[1] && counted_bars!=0)
           {
            PlaySound("news.wav");// buy wav
            Alert(Symbol()," buy signal");
            alertshow=Time[1];
           }
      else
         if (b == 1) if(alertshow<Time[1] && counted_bars!=0)
           {
            PlaySound("news.wav");// buy wav
            Alert(Symbol(),"  sell signal");
            alertshow=Time[1];
           }
   }
//----


 
Please help me on the above problem 
 
kewu:
Please help me on the above problem 

check this:

//+------------------------------------------------------------------+
//|                                              signalindicator.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Yellow
#property indicator_color3 Aqua
#property indicator_color4 Red

#property indicator_color4 Red

extern int FastEMA = 5;
extern int SlowEMA = 6;
extern int RSIPeriod = 7;
extern bool Alerts = TRUE;
double buffer_1[];
double buffer_2[];
double arrow_1[];
double arrow_2[];
int a = 0;
int b = 0;
double x = 0.0;
double y = 0.0;
 double alertshow;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, buffer_1);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, buffer_2);
   SetIndexStyle(2, DRAW_ARROW, 0,4);
   SetIndexArrow(2, 241);
   SetIndexBuffer(2, arrow_1);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW, 0,4);
   SetIndexArrow(3, 242);
   SetIndexBuffer(3, arrow_2);
   SetIndexEmptyValue(3, 0.0);
   a=0;
   b=0;
   return (0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return (0);
  }
//+------------------------------------------------------------------+
//| expert start 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 counted_bars = IndicatorCounted();
   double irsi_1 = 0;
   int li_0;
   bool c = FALSE;
   double price_10 = 0;
   if (counted_bars < 0) return (-1);
   if (counted_bars > 0) counted_bars--;
   if(counted_bars==0)
      li_0=MathMin(Bars-10-1,Bars-MathMax(FastEMA,SlowEMA)-1);
   else
      li_0=Bars-counted_bars;
   for (int i = li_0; i >= 0; i--) {
      buffer_1[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      buffer_2[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      irsi_1 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i);
      x = buffer_1[i] - buffer_2[i];
      if (x > 0.0 && irsi_1 > 50.0) a = 1;
      else
         if (x < 0.0 && irsi_1 < 50.0) a = 2;
      if (a == 1 && b != 1) {
         arrow_2[i +1] = High[i +1] + 5.0 * Point;
         c= TRUE;
         price_10 = Ask;
         b = a;
      } else {
         if (a == 2 && b != 2) {
            arrow_1[i +1] = Low[i +1] - 5.0 * Point;
            c = TRUE;
            price_10 = Bid;
            b = a;
         }
      }
      y = x;
   }
   if (Alerts && c) {
      PlaySound("alert.wav");
      if (b == 2)  
      
         if(alertshow<Time[1] && counted_bars!=0)
           {
            PlaySound("news.wav");// buy wav
            Alert(Symbol()," buy signal");
            alertshow=Time[1];
           }
      else
         if (b == 1) if(alertshow<Time[1] && counted_bars!=0)
           {
            PlaySound("news.wav");// buy wav
            Alert(Symbol(),"  sell signal");
            alertshow=Time[1];
           }
   }
//----
   return(rates_total);
  }   
//----
 
Janusz Trojca:

check this:

Janusz Trojca
:

check this:

Sir, it doesnt follow the settings /condition that i give it.

please look at the below code sir , and the settings that i gave FAST & SLOWEMA and RSI.

the problem that am having now ,i dont want the arrow to be display on the current candle and if i use  [i+1] it wont follow my settings / condition again.


//+------------------------------------------------------------------+
//|                                              signalindicator.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Yellow
#property indicator_color3 Aqua
#property indicator_color4 Red

#property indicator_color4 Red

extern int FastEMA = 5;
extern int SlowEMA = 6;
extern int RSIPeriod = 7;
extern bool Alerts = TRUE;
double buffer_1[];
double buffer_2[];
double arrow_1[];
double arrow_2[];
int a = 0;
int b = 0;
double x = 0.0;
double y = 0.0;
 double alertshow;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, buffer_1);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, buffer_2);
   SetIndexStyle(2, DRAW_ARROW, 0,4);
   SetIndexArrow(2, 241);
   SetIndexBuffer(2, arrow_1);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW, 0,4);
   SetIndexArrow(3, 242);
   SetIndexBuffer(3, arrow_2);
   SetIndexEmptyValue(3, 0.0);

   return (0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return (0);
  }
//+------------------------------------------------------------------+
//| expert start 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 counted_bars = IndicatorCounted();
   double irsi_1 = 0;
   int li_0;
   bool c = FALSE;
   double price_10 = 0;
   if (counted_bars < 0) return (-1);
   if (counted_bars > 0) counted_bars--;
   if(counted_bars==0)
      li_0=MathMin(Bars-10-1,Bars-MathMax(FastEMA,SlowEMA)-1);
   else
      li_0=Bars-counted_bars;
   for (int i = 0; i < li_0; i++) {
      buffer_1[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      buffer_2[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      irsi_1 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i+1);
      x = buffer_1[i] - buffer_2[i];
      if (x > 0.0 && irsi_1 > 50.0) a = 1;
      else
         if (x < 0.0 && irsi_1 < 50.0) a = 2;
      if (a == 1 && b == 2) {
         arrow_2[i ] = High[i + 1] - 5.0 * Point;
         c= TRUE;
         price_10 = Ask;
      } else {
         if (a == 2 && b == 1) {
            arrow_1[i ] = Low[i + 1] - 5.0 * Point;
            c = TRUE;
            price_10 = Bid;
         }
      }
      b = a;
      y = x;
   }
   if (Alerts && c) {
      PlaySound("alert.wav");
      if (b == 2)  
      
         if(alertshow<Time[1] && counted_bars!=0)
           {
            PlaySound("news.wav");// buy wav
            Alert(Symbol()," buy signal");
            alertshow=Time[1];
           }
      else
         if (b == 1) if(alertshow<Time[1] && counted_bars!=0)
           {
            PlaySound("news.wav");// buy wav
            Alert(Symbol(),"  sell signal");
            alertshow=Time[1];
           }
   }
//----
   return(prev_calculated);
  }
//+------------------------------------------------------------------+

i attached it signal image below.

Files:
signal1.PNG  31 kb
 
Janusz Trojca:

check this:

below is the live signal of the last codes u posted sir,
Files:
signal2.PNG  35 kb
 
please i need ur help gurus in the house.
 

After a long discussion we have the final version:

//+------------------------------------------------------------------+ 
//|                                              signalindicator.mq4 | 
//|                        Copyright 2015, MetaQuotes Software Corp. | 
//|                                             https://www.mql5.com | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright 2015, MetaQuotes Software Corp." 
#property link "https://www.mql5.com" 
#property version "1.00" 
#property strict 
#property indicator_chart_window 
#property indicator_buffers 4 
#property indicator_color1 Blue 
#property indicator_color2 Yellow 
#property indicator_color3 Aqua 
#property indicator_color4 Red 

int FastEMA = 18; 
int SlowEMA = 28; 
int RSIPeriod = 9; 
double buffer_1[]; 
double buffer_2[]; 
double arrow_1[]; 
double arrow_2[]; 
int a = 0; 
int b = 0; 
double x = 0.0; 
double y = 0.0; 
int lookBack; 

//+------------------------------------------------------------------+ 
//| Custom indicator initialization function | 
//+------------------------------------------------------------------+ 
int init() 
{ 
   SetIndexStyle(0, DRAW_LINE); 
   SetIndexBuffer(0, buffer_1); 
   SetIndexLabel(0, "FasterEMA");
   SetIndexStyle(1, DRAW_LINE); 
   SetIndexBuffer(1, buffer_2); 
   SetIndexLabel(1, "SlowerEMA");
   SetIndexStyle(2, DRAW_ARROW, 0,4); 
   SetIndexArrow(2, 241); 
   SetIndexBuffer(2, arrow_1); 
   SetIndexEmptyValue(2, 0.0); 
   SetIndexStyle(3, DRAW_ARROW, 0,4); 
   SetIndexArrow(3, 242); 
   SetIndexBuffer(3, arrow_2); 
   SetIndexEmptyValue(3, 0.0); 

   a=-1;
   b=-1;
   return (0); 
} 

//+------------------------------------------------------------------+ 
//| | 
//+------------------------------------------------------------------+ 
int deinit() 
{ 
   return (0); 
} 

//+------------------------------------------------------------------+ 
//| expert start 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 counted_bars = prev_calculated; 
   double irsi_1 = 0; 
   double irsi_2 = 0;
   int li_0; 
   bool c = FALSE; 
   double price_10 = 0; 
   if (counted_bars < 0) return (-1); 
   if (counted_bars > 0) counted_bars--; 
   li_0 = Bars - counted_bars-1; 

   for(int i = li_0; i >=0; i--) 
   { 

      buffer_1[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i); 
      buffer_2[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i); 
      irsi_1 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i); 
      irsi_2 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i+1); 
      x = buffer_1[i] - buffer_2[i];
      a=0;
      if (x < 0.0 && irsi_1 > 50.0 && irsi_2 <= 50) a = 2; 
      else if (x > 0.0 && irsi_1 < 50.0 && irsi_2 >= 50) a = 1; 
      if (a == 1 && b != 1) 
      { 
         arrow_2[i] = High[i] + 5.0 * Point; 
         c= TRUE; 
         price_10 = Ask; 
         if (i > 0) b = a; 
      } 
      else if (a == 2 && b != 2) 
      { 
         arrow_1[i] = Low[i] - 5.0 * Point; 
         c = TRUE; 
         price_10 = Bid; 
         if (i > 0) b = a; 
      } 
      y = x; 
   } 

//---- 
   return(rates_total); 
} 
//+------------------------------------------------------------------+
Reason: