Hello help me please about this point to filter arrow

 

Dear Coders:

I have a problem and I can not think how to fix thay kindly support,

//$------------------------------------------------------------------$
//|                                            MA Crossing Magic.mq4 |
//|                     Copyright 2018, MohamedEgy                   |
//|                           https:/mohamedegy                      |
//$------------------------------------------------------------------$
#property copyright "Copyright 2018, MohamedEgy"
#property link      "https:/mohamedegy"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots   9
//--- plot EMA1_
#property indicator_label1  "EMA1_"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- plot EMA2_
#property indicator_label2  "EMA2_"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrLimeGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2
//--- plot EMA3_
#property indicator_label3  "EMA3_"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2
//--- plot BUY_
#property indicator_label4  "BUY_"
#property indicator_type4   DRAW_ARROW
#property indicator_color4  clrDodgerBlue
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- plot SELL_
#property indicator_label5  "SELL_"
#property indicator_type5   DRAW_ARROW
#property indicator_color5  clrViolet
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1
//--- plot Buffer_1
#property indicator_label6  "Buffer_1"
#property indicator_type6   DRAW_LINE
#property indicator_color6  clrRed
#property indicator_style6  STYLE_SOLID
#property indicator_width6  1
//--- plot Buffer_2
#property indicator_label7  "Buffer_2"
#property indicator_type7   DRAW_LINE
#property indicator_color7  clrRed
#property indicator_style7  STYLE_SOLID
#property indicator_width7  1
//--- plot Buffer_3
#property indicator_label8  "Buffer_3"
#property indicator_type8   DRAW_LINE
#property indicator_color8  clrRed
#property indicator_style8  STYLE_SOLID
#property indicator_width8  1
//--- plot Buffer_4
#property indicator_label9  "Buffer_4"
#property indicator_type9   DRAW_LINE
#property indicator_color9  clrRed
#property indicator_style9  STYLE_SOLID
#property indicator_width9  1
// Indicator parameters.
input int EMA_1 = 5;
input int EMA_2 = 15;
input int EMA_3 = 100;
//--- indicator buffers
double         EMA1_Buffer[];
double         EMA2_Buffer[];
double         EMA3_Buffer[];
double         BUY_Buffer[];
double         SELL_Buffer[];
double         Buffer_1Buffer[];
double         Buffer_2Buffer[];
double         Buffer_3Buffer[];
double         Buffer_4Buffer[];
//$------------------------------------------------------------------$
//| Custom indicator initialization function                         |
//$------------------------------------------------------------------$
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,EMA1_Buffer);
   SetIndexBuffer(1,EMA2_Buffer);
   SetIndexBuffer(2,EMA3_Buffer);
   SetIndexBuffer(3,BUY_Buffer);
   SetIndexBuffer(4,SELL_Buffer);
   SetIndexBuffer(5,Buffer_1Buffer);
   SetIndexBuffer(6,Buffer_2Buffer);
   SetIndexBuffer(7,Buffer_3Buffer);
   SetIndexBuffer(8,Buffer_4Buffer);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   SetIndexArrow(3,233);
   SetIndexArrow(4,234);

//---
   return(INIT_SUCCEEDED);
  }
//$------------------------------------------------------------------$
//| Custom indicator deinitialization function                       |
//$------------------------------------------------------------------$
int deinit()
  {
//----
   int k=0;
   for(k=Bars-1;k>=0;k--)
     {
      //ObjectDelete("Object_Name"+IntegerToString(k));
      //ObjectsDeleteAll();
     }
   return(0);
  }
//$------------------------------------------------------------------$

//$------------------------------------------------------------------$
//| 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;
//--- Main Loop
//if(rates_total>prev_calculated) 
//int limit=0;
   if(prev_calculated==0) limit=rates_total-1;
   else limit=rates_total-prev_calculated;

//for(int i=1; i<limit; i++)
   for(int i=limit; i>=1; i--)
     {
      //----
      //System EMA
      EMA1_Buffer[i]=EMA(i,EMA_1);
      EMA2_Buffer[i]=EMA(i,EMA_2);
      EMA3_Buffer[i]=EMA(i,EMA_3);
      //Buy Arrow
      if
      (
       EMA(i,EMA_1)>EMA(i,EMA_2)
       && EMA(i+1,EMA_1)<EMA(i+1,EMA_2)
       && EMA(i,EMA_2)>EMA(i,EMA_3)
       )BUY_Buffer[i]=Low[i]-ArrowSpacer();

      //---Sell Arrow
      if
      (
       EMA(i,EMA_1)<EMA(i,EMA_2)
       && EMA(i+1,EMA_1)>EMA(i+1,EMA_2)
       && EMA(i,EMA_2)<EMA(i,EMA_3)
       )SELL_Buffer[i]=High[i]+ArrowSpacer();
      Buffer_1Buffer[i]=0;
      Buffer_2Buffer[i]=0;
      Buffer_3Buffer[i]=0;
      Buffer_4Buffer[i]=0;
      //----
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//$------------------------------------------------------------------$

//$------------------------------------------------------------------$
//| External function                                                |
//$------------------------------------------------------------------$
double EMA(int i,int EMA_Period){return(iMA(NULL,0,EMA_Period,0,MODE_EMA,PRICE_TYPICAL,i));}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double ArrowSpacer()
  {
   double Arrow_Space=0;
   if( PERIOD_M1  == Period() ) Arrow_Space=(5*Point);
   if( PERIOD_M5  == Period() ) Arrow_Space=(10*Point);
   if( PERIOD_M15 == Period() ) Arrow_Space=(15*Point);
   if( PERIOD_M30 == Period() ) Arrow_Space=(20*Point);
   if( PERIOD_H1  == Period() ) Arrow_Space=(15*Point);
   if( PERIOD_H4  == Period() ) Arrow_Space=(40*Point);
   if( PERIOD_D1  == Period() ) Arrow_Space=(80*Point);
   if( PERIOD_W1  == Period() ) Arrow_Space=(150*Point);
   if( PERIOD_MN1 == Period() ) Arrow_Space=(200*Point);
   return(Arrow_Space);
  }

//$------------------------------------------------------------------$
 
Mohamed Abdelrahman:

Dear Coders:

I have a problem and I can not think how to fix thay kindly support,

What is the problem?

Please explain where you are having a problem and also indicate the section of code where the problem occurs. Then somebody may be able to help you.

 
You can use PlotIndexSetInteger PLOT_ARROW_SHIFT instead of ArrowSpace().
 
kypa:
You can use PlotIndexSetInteger PLOT_ARROW_SHIFT instead of ArrowSpace().

Does that work in mql4 now?

 

I didn't realize it's mql4.

Surprisingly it compiles, doesn't look like working though.

 

Hello Coders:

Sorry a problem happened while posting this chart,

I want the indicator to only display buy arrow if the current arrow is higher than previous arrow,

and display sell arrow if the arrow lower than previous arrow

how to code that ?! please help



 
Mohamed Abdelrahman:

Hello Coders:

Sorry a problem happened while posting this chart,

I want the indicator to only display buy arrow if the current arrow is higher than previous arrow,

and display sell arrow if the arrow lower than previous arrow

how to code that ?! please help



Impossible to know without seeing the code.

I don't see the point of this as that would mean that the indicator could only display progressively higher buy arrows and progressively lower sell arrows. It will eventually get to the point where no arrows are displayed.

 
Keith Watford:

Impossible to know without seeing the code.

I don't see the point of this as that would mean that the indicator could only display progressively higher buy arrows and progressively lower sell arrows. It will eventually get to the point where no arrows are displayed.

the code is here above at the beginning of the topic

 
Mohamed Abdelrahman:

the code is here above at the beginning of the topic

Sorry, I tend to only look at unread posts and didn't realise that you had previously posted code.

As I already said, I don't see the point but if you want to do this, create 2 static double variables.

Save the value in the relevant variable when there is an arrow.

Check any new arrow value against the static variable

if the new arrow's value is not higher/lower, do not create the new arrow.

if it is, create the arrow and update the static variable.

Reason: