How to remove arrows of the same type following the first arrow?

 
I am creating a signal indicator that follows the trend and represents the entry points with arrows.
I use IndicatorBuffers to generate arrows. The structure of the indicator is:
If (Order Condition){Draw an arrow}
Because the indicator follows the trend there are a lot of entry points that match the condition, but I only want to use the first arrow that appears after a trend reversal.

So is there a way to remove the arrows of the same type after the first one? Please help me!https://charts.mql5.com/34/723/xauusdf-m15-litefinance-global-llc.png

 
ThunderFxtrading: So is there a way to remove the arrows of the same type after the first one?

Remember the current direction and don't draw the next one. The easiest way is to create an extra buffer with your type.

 
William Roeder #:

Remember the current direction and don't draw the next one. The easiest way is to create an extra buffer with your type.

English is not my mother tongue.
I am looking for a way to show only the first Arrow after a reversal. The example behind a down arrow is an up arrow.
 
William Roeder #:

Remember the current direction and don't draw the next one. The easiest way is to create an extra buffer with your type.

Please see attached photo
 
ThunderFxtrading #: Please see attached photo

We understood your question, but it seems you did not understand the answer.

As William has already pointed out in his post #1, remember the current trend. Do just as he has stated and have an extra buffer that keeps track of the current trend — Up, Down, or None.

When you detect a new direction, then draw the arrow and update the trend buffer. When a new signal is in the same direction of current trend, then do nothing.

EDIT: If you need further guidance then please show your code attempting it.

 
Fernando Carreiro #:

We understood your question, but it seems you did not understand the answer.

As William has already pointed out in his post #1, remember the current trend. Do just as he has stated and have an extra buffer that keeps track of the current trend — Up, Down, or None.

When you detect a new direction, then draw the arrow and update the trend buffer. When a new signal is in the same direction of current trend, then do nothing.

EDIT: If you need further guidance then please show your code attempting it.

Thanks for your answer, I think I should show my code. There are many arrows that can satisfy the condition and I can't add a condition to remove unnecessary arrows. Thanks for your help!!
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexArrow(0, 233);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexArrow(1, 234);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
     
   return(INIT_SUCCEEDED);
  }

int OnCalculate(){
if(   iMA(NULL, PERIOD_M15, 36, 0, MODE_EMA, PRICE_CLOSE, 1+barshift_M15) < iMA(NULL, PERIOD_M15, 12, 0, MODE_EMA, PRICE_CLOSE, 1+barshift_M15)
      && iOsMA(NULL, PERIOD_M15, 12, 26, 9, PRICE_CLOSE, 1+barshift_M15) < iOsMA(NULL, PERIOD_CURRENT, 12, 26, 9, PRICE_CLOSE, i) //Moving Average of Oscillator < Moving Average of Oscillator
      && iMA(NULL, PERIOD_M15, 13, 0, MODE_EMA, PRICE_CLOSE, 1+barshift_M15) < iMA(NULL, PERIOD_M15, 13, 0, MODE_EMA, PRICE_CLOSE, barshift_M15) //Moving Average < Moving Average
       )
        {
         Buffer1[i] = iLow(NULL, PERIOD_M15, 1+barshift_M15)- 10*myPoint; //Set indicator value at Candlestick Close
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Buy"); //Alert on next bar open
         time_alert = Time[1];
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }

if(   iMA(NULL, PERIOD_M15, 36, 0, MODE_EMA, PRICE_CLOSE, 1+barshift_M15) > iMA(NULL, PERIOD_M15, 12, 0, MODE_EMA, PRICE_CLOSE, 1+barshift_M15)
      && iOsMA(NULL, PERIOD_M15, 12, 26, 9, PRICE_CLOSE, 1+barshift_M15) > iOsMA(NULL, PERIOD_CURRENT, 12, 26, 9, PRICE_CLOSE, i)
      && iMA(NULL, PERIOD_M15, 13, 0, MODE_EMA, PRICE_CLOSE, 1+barshift_M15) > iMA(NULL, PERIOD_M15, 13, 0, MODE_EMA, PRICE_CLOSE, barshift_M15) 
       )
        {
         Buffer2[i] = iHigh(NULL, PERIOD_M15, 1+barshift_M15)- 10*myPoint; //Set indicator value at Candlestick Close
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Sell"); //Alert on next bar open
         time_alert = Time[1];
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }


}
 
ThunderFxtrading #Thanks for your answer, I think I should show my code. There are many arrows that can satisfy the condition and I can't add a condition to remove unnecessary arrows. Thanks for your help!!

Please, first attempt to code what has been explained already — namely, add the extra buffer for tracking the current trend.

Then provide complete code that compiles, that includes the indicator properties and declarations of global variables, including the buffers.

 

Firstly, this appears to be MQL4 code, so I will move this topic to the correct section.


William and Fernando, is there any advantage to using an additional buffer to track the current trend?

I just use a static variable

enum signal_state {BUY_SIGNAL,SELL_SIGNAL,NO_SIGNAL};

and in OnCalculate()

static signal_state current_signal=NO_SIGNAL;

and of course reset it if prev_calculated ==0.

Then, when a signal is detected, ie a buy signal

   if(current_signal!=BUY_SIGNAL)
   {
   current_signal=BUY_SIGNAL;
   //place value in buy buffer
   }
 
Keith Watford #:

Firstly, this appears to be MQL4 code, so I will move this topic to the correct section.


William and Fernando, is there any advantage to using an additional buffer to track the current trend?

I just use a static variable

and in OnCalculate()

and of course reset it if prev_calculated ==0.

Then, when a signal is detected, ie a buy signal

In my opinion, the static variable has one major disadvantage in this case. If a new initialization occurs (e.g. TF change), the static variable in OnCalculate will keep its value, which is not desirable.

EDIT: OK, I'm sorry I didn't notice your part:

"and of course reset it if prev_calculated ==0"

That way, of course, it's okay

 
@Keith Watford #: Firstly, this appears to be MQL4 code, so I will move this topic to the correct section. William and Fernando, is there any advantage to using an additional buffer to track the current trend? I just use a static variable and in OnCalculate() and of course reset it if prev_calculated ==0. Then, when a signal is detected, ie a buy signal

The main advantage of the buffer is that the indicator or an EA can look back in time to see what the trend was at a particular bar. You can't do that with an internal static.

As for the static variable, it definitely is more efficient than a buffer, but it can cause trouble if not properly set again should there be a resynchronisation of the rates_total or the prev_calculated. I have seen cases where prev_calculated was only partially rolled back and not completely to zero. In these cases, in order to synchronise the static you would need to reprocess data again to find the last valid state.

It is certainly possible to implement it with a static, but in my opinion it can be much more problematic if not coded properly, especially for a newbie coder.

The buffer method is easier to implement for a newbie and also lends itself better to incremental calculations.

 
Fernando Carreiro #:

The main advantage of the buffer is that the indicator or an EA can look back in time to see what the trend was at a particular bar. You can't do that with an internal static.

As for the static variable, it definitely is more efficient than a buffer, but it can cause trouble if not properly set again should there be a resynchronisation of the rates_total or the prev_calculated. I have seen cases where prev_calculated was only partially rolled back and not completely to zero. In these cases, in order to synchronise the static you would need to reprocess data again to find the last valid state.

It is certainly possible to implement it with a static, but in my opinion it can be much more problematic if not coded properly, especially for a newbie coder.

The buffer method is easier to implement for a newbie and also lends itself better to incremental calculations.

I may be wrong, but prev_calculated cannot be "scrolled back" (only to zero). It can be "paused" when a connection is lost (e.g.), and then resumed from the last calculated bar. In that case, resetting a static variable as Keith suggested would be sufficient.

Or did I miss something?

Reason: