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...
Please have a look on SetIndexEmptyValue(), this will be help.
Thanks for the quick reply didn't work though...
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
doesn't the object move if you set it's values to a new value? use ObjectSet() and call the same name over and over?
CrossUp[i] = EMPTY_VALUE; CrossDown[i] = EMPTY_VALUE; // if (Open[i] > MA_ ) { CrossUp[i]=Low[i] - 0.0010; } if (Open[i] < MA_ ) { CrossDown[i]=High[i] + 0.0010; }
assume that NO plot for current bar until proven otherwise
No luck still not working
it is doing exactly what you asked. why? because the candle Open price can be in 1 of 3 positions relative to the SMA(20) : above or same or below.
this is why the code does what you asked it to do... on every bar.
1 .expand the candles on your chart
2.draw a simpleMovingAverage on main chart. SimpleMA, period=20, shift=0
3. now apply the English condition to all candles where Open is above the plotted ma in 2. above
4. do same for all candles where Open is below the plotted ma in 2. above
example: in 3 above, by just looking eg, at all candles above plotted ma, you will quickly see that when Open is above your code plots an UP arrow
// if open greater than close ma
if (Open[i] > MA_ )
.
//if open less than close ma
if (Open[i] < MA_ )
Thanks for the quick reply. May be i didn't explain it right. Nothing wrong with the code that i pasted above. It is doing what it supposes to do "draw arrow when ever condition meets". But my question was is there way to make it to have just one arrow (when condition meets at first candle) and ignore rest.... Example... Let’s say candle "1" open price is above 20ma so code should draw an up arrow on candle "1" and suppose next 30 candles stay above 20ma no arrows on these candles until condition reverse (what this code does is to draw 30 arrows. One arrow on each candle). Now lets say "31st" candle’s open price is less the 20ma so it should draw down arrow on "31st" candle and suppose 50 candles stay below 20ma no arrows on these... and keep going ....
Thanks for the quick reply. May be i didn't explain it right. Nothing wrong with the code that i pasted above. It is doing what it supposes to do "draw arrow when ever condition meets". But my question was is there way to make it to have just one arrow (when condition meets at first candle) and ignore rest.... Example... Let’s say candle "1" open price is above 20ma so code should draw an up arrow on candle "1" and suppose next 30 candles stay above 20ma no arrows on these candles until condition reverse (what this code does is to draw 30 arrows. One arrow on each candle). Now lets say "31st" candle’s open price is less the 20ma so it should draw down arrow on "31st" candle and suppose 50 candles stay below 20ma no arrows on these... and keep going ....
Generally, I think this is programming works. By setting a flag to hold the arrow state to show that is the arrow is the first up or down arrow. If it is not just set the arrow to empty value. The simple condition of the arrow state is the change of state of up or down arrown. After it is change, it is the first up or down arrow. And if the first arrow is set and show, the state will be not show any arrow. Hope this will be help.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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);
}
//+------------------------------------------------------------------+