Drawing Up/down Arrows! - page 2

 

OK... this is trouble with language-lol, whereas code is very black and white! either works or not, maybe diff ways to approach BUT can only really be one outcome: ok||!ok

below, from my interpretation of what you after, does the job. If you feel it does not, at least you can see one way to use a state flag. I think the rest is really up to you now, play and learn - as they say!

btw, you might consider using more descriptive syntax. For example, what below makes for easier readability...?

MA_Type = MODE_SMA;

App_Price = PRICE_CLOSE;

.

MA_Type = 0;

App_Price = 0;

.

why do I say? readability=betterUnderstanding=VIPeasierMaintenance

the instant you have a clean compile you are into the maintenance phase of a project and like all s/w, this phase can go on and on... :)

fwiw...

//+------------------------------------------------------------------+
//|                                                        19151.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red

extern int MA_Period =20;
extern int MA_Type = MODE_SMA;
extern int App_Price = PRICE_CLOSE;
double MA_;
double CrossUp[];
double CrossDown[];
//plot state can be 1 of: UP,DOWN
#define PLOTUP 1
#define PLOTDOWN -1
int iWaitFor = PLOTUP;  //initial value

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
  //---- indicators
  SetIndexStyle(0, DRAW_ARROW, EMPTY);
  SetIndexArrow(0, 225);
  SetIndexBuffer(0, CrossUp);
  SetIndexStyle(1, DRAW_ARROW, EMPTY);
  SetIndexArrow(1, 226);
  SetIndexBuffer(1, CrossDown);

  return(0);
}
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
  MA_ =0 ;
  int counted_bars = IndicatorCounted();
  int i;
  int limit;
  if(counted_bars < 0) 
  return(-1);
  if(counted_bars > 0) 
  counted_bars--;
  limit = Bars - counted_bars;
  for(i=0; i<=limit; i++)
  {
    MA_ = iMA(Symbol(),0,MA_Period,0,MA_Type,App_Price,i);
    if (Open[i] > MA_ && iWaitFor==PLOTUP)
    {
      iWaitFor = PLOTDOWN;
      CrossUp[i]=Low[i] - 0.0010;
    } 
    if (Open[i] < MA_ && iWaitFor==PLOTDOWN)
    {
      iWaitFor = PLOTUP;
      CrossDown[i]=High[i] + 0.0010; 
    }
  }
  return(0);
}


https://forum.mql4.com/19151

 
R_Jang:

Is there a way to draw just one UP and one DOWN arrow whenever conditions meet? I am trying to accomplish this

1- Draw just one UP arrow when bar's open is greater then 20ma

2- Draw just one DOWN arrow when bar's open is less then 20ma

The code i have is drawing arrows on every bar... I want arrow on first bar when condition meets and ignore rest until condition gets reverse. Following is the code i am using but it's giving me arrow on every bar...

//----------------------------------------------------------------------------------------------

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red

extern int MA_Period =20;
extern int MA_Type = 0;
extern int App_Price = 0;
double MA_;
double CrossUp[];
double CrossDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 225);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 226);
SetIndexBuffer(1, CrossDown);

return(0);
}
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
MA_ =0 ;
int counted_bars = IndicatorCounted();
int i;
int limit;
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
for(i=0; i<=limit; i++)
{
MA_ = iMA(Symbol(),0,MA_Period,0,MA_Type,App_Price,i);
if (Open[i] > MA_ )
{
CrossUp[i]=Low[i] - 0.0010;
}
if (Open[i] < MA_ )
{
CrossDown[i]=High[i] + 0.0010;
}
}
return(0);
}
//+------------------------------------------------------------------+