Forex Factory (https://www.forexfactory.com/)
-   Platform Tech (https://www.forexfactory.com/forum/69-platform-tech)
-   -   How to program Higher-High Higher-Low (https://www.forexfactory.com/thread/43483-how-to-program-higher-high-higher-low)

TickJob Aug 20, 2007 8:52pm | Post# 1

How to program Higher-High Higher-Low
 
1 Attachment(s)
How to program to identify HH (Higher High) or LL (Lower Low) or LH (Lower High) or Higher Low( HL) above and below each Peak as shown in below chart?
Click to Enlarge

Name: zigzag1.jpg
Size: 72 KB

jjk2 Aug 20, 2007 9:51pm | Post# 2

there is. keep looking.

hanover Aug 21, 2007 2:29am | Post# 3

2 Attachment(s)
How to program to identify HH (Higher High) or LL (Lower Low) or LH (Lower High) or Higher Low( HL) above and below each Peak as shown in below chart?
Hi TickJob

I’ll try to offer a little more detail than the last poster.

It’s possible that there’s a custom indicator that already does this, but I’ve searched my library (of over 500 MT4 indicators), and can’t find one.

Re defining “local” highs and lows, what appears obvious to the naked eye is not necessarily as simple to model mathematically. I wrote a charting package about 5 years back (not quite as comprehensive as MT4 though! ), and was forced to address these same kind of issues.

One approach is “slicing” the chart into sections, or cycles. It’s then a matter of looping through the bars/candles to find the highest high and/or lowest low in each section. At least that’s the way I approached it.

Here are some possible starting points:

1. Very primitive: X bars in each section, where X is an arbitrary value. An alternative view is to take each bar on the chart and find the highest high and lowest low X bars forward or backward from that point.

2. Use trend following indicators, or oscillators to define the sections as “phases”. As a simple example, when a faster moving average crosses above a slower moving average you’re in an “upward” phase; when it moves below the slower MA, you’re in a “downward” phase. Then it’s a case of finding the highest high in each upward phase, and lowest low in each downward phase. Experiment with various MA calibrations (optimizations) to capture the “cycles” that you wish, or combinations of trend followers (MAs, SAR, countback lines, or oscillators [e.g. RSI, Stochastic or MACD crossing a trigger line, or the midpoint]) to get something close to the desired result. Virtually all of these are all built into MQL4 as functions (iMA, iMACD, iRSI, etc), so it’s not necessary to manually code each algorithm.

3. Instead of slicing the chart into sections, use something like Tom Demark supply and demand points, i.e. a high that’s higher than all of the highs X bars either side of it is a local high; vice versa for a low. One problem with using TD supply/demand points is that it’s possible to get two or more local highs without an intervening low, or vice versa; so you would need to compare them and exclude all but the most extreme one. I’ve included the Demark.MQ4 indicator below. For further explanation, see my posts here: http://www.forexfactory.com/showthread.php?t=37073

4. I’ve included the Zigzag .MQ4 indicator below. Not 100% sure how its algorithm operates; you’ll need to reverse engineer the code for yourself, or perform a search of the forum here for more info.

Of course once you’ve established local highs and lows, it’s simply a case of comparing successive highs and lows to establish whether each is higher or lower than its predecessor.

For whatever it's worth, method #2 was the way I ended up doing it.

Hope this gives you a starting point. It’s not necessarily a trivial task.

Good luck
David
ZigZag.mq4
DeMark.mq4

TickJob Aug 24, 2007 12:42am | Post# 4

1 Attachment(s)
Thank you very hanover.

I have programed it in smartquant C#, it turn out quite close, can further improve on it

Inserted Code
using System; 
using System.Drawing; 
 
using OpenQuant.API; 
using OpenQuant.API.Indicators; 
 
public class MyStrategy : Strategy 
{ 
 
   private int barcount = 0; 
   private double barclose = 0; 
   private double barlow = 0; 
   private double barhigh = 0; 
   private double barlowest = 999999.0; 
   private double barhighest = 0.0; 
   private double HH1 = 0; 
   private double HH2 = 0; 
   private double LL1 = 0; 
   private double LL2 = 0; 
   private bool is_high = true; 
   private bool is_low = false; 
   private int HLbarcount = 0; 
 
   DateTime barlowestDateTime; 
   DateTime barhighestDateTime; 
 
   TimeSeries HL; 
 
 
 
   public override void OnStrategyStart() 
   { 
      HL = new TimeSeries("High-Low", Color.White); 
      Draw(HL, 0); 
   } 
 
   public override void OnBar(Bar bar) 
   { 
      if ((bar.Close > 0) && (bar.High > 0) && (bar.Low > 0) && (bar.Open > 0)) 
      {    
         if (Mode != StrategyMode.Simulation) 
         { 
            DataManager.Add(Instrument, bar); 
         } 
         barcount++; 
         HLbarcount++; 
         barclose = bar.Close; 
         barhigh = bar.High; 
         barlow = bar.Low; 
 
 
         if (barcount > 1) 
         { 
            if ((barlow) < barlowest) 
            { 
               barlowest = barlow; 
               barlowestDateTime = bar.DateTime; 
            } 
 
            if ((barhigh) > barhighest) 
            { 
               barhighest = barhigh; 
               barhighestDateTime = bar.DateTime; 
            }          
         }       
 
         if (barcount > 4) 
         { 
            if ((HLbarcount > 3) && (is_low) && (Bars.Ago(0).High > Bars.Ago(3).High) && (Bars.Ago(0).Low > Bars.Ago(1).Low) && (Bars.Ago(0).Low > barlowest)) 
            { 
               LL2 = LL1; 
               LL1 = barlowest; 
               if (LL1 != LL2) 
               { 
                  is_high = true; 
                  is_low = false; 
                  HL.Add(barlowestDateTime, barlowest);    
                  barhighest = Bars.HighestHigh(4);    
                  barhighestDateTime = bar.DateTime; 
                  HLbarcount = 0; 
                  HH1 = 0; 
                  HH2 = 0; 
                  Console.WriteLine("{0}     LL1 = {1}     barhighest = {2}", barlowestDateTime, LL1, barhighest);                                  
               } 
            } 
 
            if ((HLbarcount > 3) && (is_high) && (Bars.Ago(0).Low < Bars.Ago(3).Low)&& (Bars.Ago(0).High < Bars.Ago(1).High) && (Bars.Ago(0).High < barhighest)) 
            { 
               HH2 = HH1; 
               HH1 = barhighest; 
               if (HH1 != HH2) 
               { 
                  is_low = true; 
                  is_high = false; 
                  HL.Add(barhighestDateTime, barhighest);       
                  barlowest =  Bars.LowestLow(4); 
                  barlowestDateTime = bar.DateTime; 
                  HLbarcount = 0; 
                  LL1 = 0; 
                  LL2 = 0; 
                  Console.WriteLine("{0}     HH1 = {1}     barlowest = {2}", barhighestDateTime, HH1, barlowest);                                     
               } 
            } 
 
         }       
 
      }     
      else 
      { 
         Console.WriteLine("Instrument:    {0},       Date/Time:     {1}", Instrument, bar.DateTime); 
      } 
   } 
}
Click to Enlarge

Name: zigzag2.gif
Size: 14 KB

59fender Aug 24, 2007 1:11am | Post# 5

Hi TickJob

I’ll try to offer a little more detail than the last poster.

It’s possible that there’s a custom indicator that already does this, but I’ve searched my library (of over 500 MT4 indicators), and can’t find one.

Re defining “local” highs and lows, what appears obvious to the naked eye is not necessarily as simple to model mathematically. I wrote a charting package about 5 years back (not quite as comprehensive as MT4 though! ), and was forced to address these same kind of issues.

One approach is “slicing” the chart into sections, or cycles. It’s then a matter of looping through the bars/candles to find the highest high and/or lowest low in each section. At least that’s the way I approached it.

Here are some possible starting points:

1. Very primitive: X bars in each section, where X is an arbitrary value. An alternative view is to take each bar on the chart and find the highest high and lowest low X bars forward or backward from that point.

2. Use trend following indicators, or oscillators to define the sections as “phases”. As a simple example, when a faster moving average crosses above a slower moving average you’re in an “upward” phase; when it moves below the slower MA, you’re in a “downward” phase. Then it’s a case of finding the highest high in each upward phase, and lowest low in each downward phase. Experiment with various MA calibrations (optimizations) to capture the “cycles” that you wish, or combinations of trend followers (MAs, SAR, countback lines, or oscillators [e.g. RSI, Stochastic or MACD crossing a trigger line, or the midpoint]) to get something close to the desired result. Virtually all of these are all built into MQL4 as functions (iMA, iMACD, iRSI, etc), so it’s not necessary to manually code each algorithm.

3. Instead of slicing the chart into sections, use something like Tom Demark supply and demand points, i.e. a high that’s higher than all of the highs X bars either side of it is a local high; vice versa for a low. One problem with using TD supply/demand points is that it’s possible to get two or more local highs without an intervening low, or vice versa; so you would need to compare them and exclude all but the most extreme one. I’ve included the Demark.MQ4 indicator below. For further explanation, see my posts here: http://www.forexfactory.com/showthread.php?t=37073

4. I’ve included the Zigzag .MQ4 indicator below. Not 100% sure how its algorithm operates; you’ll need to reverse engineer the code for yourself, or perform a search of the forum here for more info.

Of course once you’ve established local highs and lows, it’s simply a case of comparing successive highs and lows to establish whether each is higher or lower than its predecessor.

For whatever it's worth, method #2 was the way I ended up doing it.

Hope this gives you a starting point. It’s not necessarily a trivial task.

Good luck
David
I've been trying to upload asluncos indiccators and I'm not having any luck perhaps you could give me some tips on how too do so?

hanover Aug 24, 2007 6:07am | Post# 6

I've been trying to upload asluncos indiccators and I'm not having any luck perhaps you could give me some tips on how too do so?
59fender,

I'm not quite sure what you mean by asluncos indicators. Can you tell me what they are and where I can find them?

If an indicator is attached to a forum post, simply save the attached MQ4 or EX4 file in one of the following folders:

  1. For indicators, the correct folder is: c:\program files\<mt4 broker name>\experts\indicators
  2. For scripts, the correct folder is: c:\program files\<mt4 broker name>\experts\scripts
  3. For experts, the correct folder is: c:\program files\<mt4 broker name>\experts
  4. For templates, the correct folder is: c:\program files\<mt4 broker name>\templates
  5. For data files, the correct folder is: c:\program files\<mt4 broker name>\experts\files

If it is from another source, simply download it and copy it to the correct folder.

Then exit, and re-run MT4. This causes MT4 to re-compile and re-load all new or changed indicators.

Press Ctrl-N to load the Navigator panel at left. The new indicators, scripts, experts should appear in the "Custom Indicators", "Scripts" or "Expert Advisors" trees.

In the case of indicators and scripts, drag them onto your chart(s) to execute them.

Hope I've helped get you one step closer to an answer.

Best wishes
David


Kamikaze456 Aug 20, 2009 11:55am | Post# 7

Bump...

Does anyone currently have a Higher-High Higher-Low etc. indicator....for MT4

Thanks

Kamikaze456 Aug 21, 2009 3:07am | Post# 8

Anyone?!

akukaya Aug 21, 2009 5:27am | Post# 9

read amazing strategy
 
I think amazing strategy by merlin is looking for high and low successfully.

read again, again and again

Rastaman Aug 22, 2009 6:36am | Post# 10

HH indi
 
1 Attachment(s)
here you go.
HL.zip

Kamikaze456 Aug 22, 2009 6:41am | Post# 11

Thanks Rastaman

unaizams Aug 31, 2009 2:00am | Post# 12

How to program to identify HH (Higher High) or LL (Lower Low) or LH (Lower High)?
Use iHighest and iLowest.

abma129 Nov 14, 2012 1:34am | Post# 13

Hi traders,
Ist possible a indicator will show every high and low in chart ( like plot or arrow) not by lines zigzag like that
if its please post here, that will be very much help me calculate a method

rcsltd Nov 15, 2013 11:23am | Post# 14

1 Attachment(s)
Is this kind of this what you're after? The red leg(s) at the end are unconfirmed.
Name:  Image3.png
Views: 16537
Size:  5 KB

acboerse Aug 20, 2014 12:50pm | Post# 15

Hi,
i also want to try with counting bars since last high/low.

Is there anybody how can write an mt4 indicator, which shows an the chart the number bars since last high/low.

or better additial an indicator which count it since a userdefined period.

Thank ´s for helping.

acboerse Mar 19, 2015 1:26pm | Post# 16

Hello,
I try since some days to learn to program with the metaeditor in MT4.

But I dont have success with my first indicator.

Please can someone have a look on following code what is wrong.

Result should be : on every new candle should print a number 1,2,3..... íf it close under the HighestHigh of 5 periods.
Im desparte
Thank you for answers
*********************************************************
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color1 Gold


double ExtMapBuffer1[];
double ExtMapBuffer2[];


// Initialisierung zum Indikatorstart
int init()
{
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);


return(0);
}
//+----------------------------------------------------+

// Deinitialisierung zum Indikatorende
int deinit()
{
return(0);
}
//+----------------------------------------------------+

// Hauptroutine
int start()
{
int limit;
int start = 0;
int counted_bars = IndicatorCounted();
// nothing else to do?
if(counted_bars < 0)
return(-1);
// do not check repeated bars
limit = Bars - 1 - counted_bars;



for(int i = 0; i<limit; i++)

{


ExtMapBuffer1[i]=High[iHighest(NULL,0,MODE_HIGH,5,0)];


if (Close[i]<ExtMapBuffer1[i])
ExtMapBuffer2[i] = ExtMapBuffer2[i]+1;
else ExtMapBuffer2[i]=0;


string name = "NR1" + TimeToStr(Time[i], TIME_DATE|TIME_MINUTES);
ObjectCreate(name, OBJ_TEXT, 0, Time[i], High[i]+2);
ObjectSetText(name, ExtMapBuffer1[i], 7, "Times New Roman", Gold);

string name1 = "NR2" + TimeToStr(Time[i], TIME_DATE|TIME_MINUTES);
ObjectCreate(name1, OBJ_TEXT, 0, Time[i], High[i]+3);
ObjectSetText(name1, ExtMapBuffer2[i], 7, "Times New Roman", Red);
}

return(0);
}
//+----------------------------------------------------+

Cnvrsn Oct 15, 2020 7:35pm | Post# 17

For whatever it's worth, method #2 was the way I ended up doing it.
Hey, please can you share the indicator? I am currently developing one using this exact method of HH and LL within each MA crossover, but I'm having a hard time figuring out whether i should calculate the crossovers from the current candle backwards, or from, say the past X candles foward to the current candle (I'm still a rookie at programming, so sorry if this question is noobish.
Thanks.

hanover Oct 16, 2020 3:44pm | Post# 18

{quote} Hey, please can you share the indicator?
I'm sorry sir, but I don't recall which indicator it was (the post is more than 13 years old).


© Forex Factory