"wrong" arrows in indicator

 
Hi to everybody,

I have written an indicator in MT5 which shows the last two highs/lows in comparing 3 bars to the left & one bar to the right. It works fine.

I want to do the same in MT4 fpr a friend, but I fail...and don'rt know why!?

It  takes the wrong arrows, not the ones I choose - see screenshot.

Additionl question: can I do an offset like in MT5, so that the arrow is 20 pixel above/under the high/low? How?

Thanks in advanve!

Lupo
//+------------------------------------------------------------------+
//|                                                   Highs-Lows.mq5 |
//|                                                  Copyright © 2013|
//|                                                                  |
//+------------------------------------------------------------------+
//"detects the two last Highs & Lows: 3 bars zo the past & one bar to the future"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1  Green
#property indicator_color2  Red
//---- indicator buffers
double ExtUpperBuffer[];
double ExtLowerBuffer[];
//--- x pixels upper from high/low
//int    ExtArrowShift=-20;
//--- Start
int limit=2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//--- indicators style mapping
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
//--- sets arrow style
   SetIndexArrow(0,233);
   SetIndexArrow(0,234);
   //IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- drawing begins at limit:
   SetIndexDrawBegin(0,limit);
   SetIndexDrawBegin(1,limit);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtUpperBuffer);
   SetIndexBuffer(1,ExtLowerBuffer);
  }

//+------------------------------------------------------------------+
//| HaL                                                              |
//+------------------------------------------------------------------+
int start()
  {
   bool hi, lo;
   int i,high,low,counted_bars=IndicatorCounted();
//----
   if(Bars<=limit) return(-1);
//---- initial zero
   if(counted_bars==0)
         {
         ExtUpperBuffer[Bars-i]=0.0;
         ExtLowerBuffer[Bars-i]=0.0;
         hi = false;
         lo = false;
         high=0;
         low=0;
         }
   else
      {
      i=Bars-counted_bars-1;
      for(i=limit;i<=Bars;i++) 
         {
         //---- High
         if(High[i]>High[i-1] && High[i]>High[i+1] && High[i]>High[i+2] && High[i]>High[i+3] && hi==false && high<2)
            {
            ExtUpperBuffer[i]=High[i];
            lo=false;
            hi=true;
            high=high+1;
            }
         else ExtUpperBuffer[i]=EMPTY_VALUE;

         //---- Low
         if(Low[i]<Low[i-1] && Low[i]<Low[i+1] && Low[i]<Low[i+2] && Low[i]<Low[i+3] && lo==false && low<2)
            {
            ExtLowerBuffer[i]=Low[i];
            hi=false;
            lo=true;
            low=low+1;
            }        
         else ExtLowerBuffer[i]=EMPTY_VALUE;
        }
      } 

//----
      return(0);
   }
//+------------------------------------------------------------------+
 
Lupo:
Hi to everybody,

I have written an indicator in MT5 which shows the last two highs/lows in comparing 3 bars to the left & one bar to the right. It works fine.

I want to do the same in MT4 fpr a friend, but I fail...and don'rt know why!?

It  takes the wrong arrows, not the ones I choose - see screenshot.

There is no screenshot attached.
 
Lupo:


Additionl question: can I do an offset like in MT5, so that the arrow is 20 pixel above/under the high/low? How?

No,  but you can shift it by adding/subtracting from it's price coordinate.
 

Hi RaptorUK,


and thx for the quick reply...I've attached the missing screenshot...


I will have a look fpr the price coordinate think...thx.


Greez


Lupo


Highs & Lows

 
Lupo:

Hi RaptorUK,

and thx for the quick reply...I've attached the missing screenshot...


You aren't setting the arrow style for buffer 1

   SetIndexArrow(  0, 233 );
   SetIndexArrow(  0, 234 );  // should this be for buffer 1 ?
 
I guess
SetIndexArrow(0,234);

should be

SetIndexArrow(1,234);
Regarding the shift, just do
ExtUpperBuffer[i]=High[i] + 20 * Point;
or something like that.
 

Hi RaptorUK, hi enivid,


*hum*, what should I say?!?! Too many hours in front of the laptop!? Well, whatever - IT WORKS NOW!!! Thanks 2 U both! I guess I could have been searching for hours more before I would have seen that... :-(


Also with the shift it works!


THANKS a lot!


Lupo

 
   if(counted_bars==0)
         {
         ExtUpperBuffer[Bars-i]=0.0; // What is the value of i here?
         ExtLowerBuffer[Bars-i]=0.0;
         hi = false;
         lo = false;
         high=0;
         low=0;
         }
   else                        // The else must initialize hi/lo/high/low for the i+1 bar. 
      {                        // Then you want to do all the other bars AFTER the if/else.
      i=Bars-counted_bars-1;
      for(i=limit;i<=Bars;i++) // other bars for(i=Bars -2 - counted_bars; i>=0; i--)
 
WHRoeder:

Thanks!
Reason: