Find High and Low Peaks with MQL Code

Поділитися
Вставка
  • Опубліковано 3 лис 2024

КОМЕНТАРІ • 134

  • @eversonmay
    @eversonmay 3 роки тому +67

    void OnStart() {
    int shoulder = 5;
    int bar1;
    int bar2;

    bar1 = FindPeak(MODE_HIGH, shoulder, 0);
    bar2 = FindPeak(MODE_HIGH, shoulder, bar1+1);

    ObjectDelete(0, "upper");
    ObjectCreate(0, "upper", OBJ_TREND, 0, iTime(Symbol(), Period(), bar2), iHigh(Symbol(), Period(), bar2), iTime(Symbol(), Period(), bar1), iHigh(Symbol(), Period(), bar1));
    ObjectSetInteger(0, "upper", OBJPROP_COLOR, clrBlue);
    ObjectSetInteger(0, "upper", OBJPROP_WIDTH, 2);
    ObjectSetInteger(0, "upper", OBJPROP_RAY_RIGHT, true);

    bar1 = FindPeak(MODE_LOW, shoulder, 0);
    bar2 = FindPeak(MODE_LOW, shoulder, bar1+1);

    ObjectDelete(0, "lower");
    ObjectCreate(0, "lower", OBJ_TREND, 0, iTime(Symbol(), Period(), bar2), iLow(Symbol(), Period(), bar2), iTime(Symbol(), Period(), bar1), iLow(Symbol(), Period(), bar1));
    ObjectSetInteger(0, "lower", OBJPROP_COLOR, clrBlue);
    ObjectSetInteger(0, "lower", OBJPROP_WIDTH, 2);
    ObjectSetInteger(0, "lower", OBJPROP_RAY_RIGHT, true);

    }
    int FindPeak(int mode, int count, int startBar) {
    if (mode!=MODE_HIGH && mode!=MODE_LOW) return(-1);

    int currentBar = startBar;
    int foundBar = FindNextPeak(mode, count*2+1, currentBar-count);
    while (foundBar!=currentBar) {
    currentBar = FindNextPeak(mode, count, currentBar+1);
    foundBar = FindNextPeak(mode, count*2+1, currentBar-count);
    }
    return(currentBar);
    }
    int FindNextPeak(int mode, int count, int startBar) {

    if (startBar

  • @petarpetrovic5453
    @petarpetrovic5453 3 роки тому +2

    You are really the best! I have been trying this for 6 months with no success... Thank You!

  • @MQLwithBrian
    @MQLwithBrian Рік тому +1

    This is the closest information I found for my recent problem. Something that will find multiple values in the past with the same conditions but different index. Thank you! 🙏

  • @hamzavictor2385
    @hamzavictor2385 3 роки тому +2

    It is amazing how you solve such difficult problems to a novice in a simplistic and stylish manner. Thank you, I am learning so much from you.

  • @TheJoshuamcgowan
    @TheJoshuamcgowan 2 роки тому

    once i finish up my primary work projects im joining your private group. combo of teaching, programming, and trading skills is unique for sure

    • @TheJoshuamcgowan
      @TheJoshuamcgowan 2 роки тому

      nvm. closed to new members haha. makes sense. the world should be beating down a path to your door. thank you for all you do to help educate others. +1

  • @tamodolo
    @tamodolo 11 місяців тому

    Thank you very much for this!

  • @olaniyikehindemary4502
    @olaniyikehindemary4502 Рік тому

    Thanks so much for all your videos
    Everyone on of them is the best

  • @germanslobo
    @germanslobo 2 роки тому

    Thanks Richard for your education.

  • @johnskinner3145
    @johnskinner3145 3 роки тому

    Another piece of code added to my toolbox, thanks.

  • @productvisibilitytvshoppin1107

    Thank you, this is great!!

  • @mcnyrocher1624
    @mcnyrocher1624 10 місяців тому

    waoh ! Thank you @OrchardForex for that. Please how to add into the code a function to draw a trendline on specific pattern like if its detects a consecutive tripple bullish or bearish bars, robot has to draw a horizontal short trend line on their highest prices or on their lowest prices ?

  • @catherinefabian2171
    @catherinefabian2171 2 роки тому

    Amazing 🥰 Thank you.

  • @Ohyeahtimesanillusion
    @Ohyeahtimesanillusion Рік тому

    Thank you so much Richard for sharing this technique. I was stuck on how to handle negative bars and you pulled me out of it.
    I am now trying to modify the code, so that it waits 5 bars, before repainting. Tried to wrap some part of code around (if (prev_calculated == 0 ) .... else if checknewbar() ...... No luck so far...Not sure how other platforms manage to wait 5 bars in reality when a negative offset/look ahead shoulder is specified. I'm back to solving the problem :)

    • @OrchardForex
      @OrchardForex  Рік тому

      Just start the calculations 5 bars back and check at every new bar

  • @IntegralDeLinha
    @IntegralDeLinha 2 роки тому

    Thanks!! That was useful!

  • @anupmistry123
    @anupmistry123 4 місяці тому

    Thanks mate very good video and coding.

  • @IanKayCey
    @IanKayCey 2 роки тому +1

    Amazing!

  • @thanhnguyen8257
    @thanhnguyen8257 2 роки тому

    thank you, sir 😁

  • @anubhavmeena3064
    @anubhavmeena3064 7 місяців тому

    Instead of fixing the bars to look for to 5 can you keep it variable/dynamic (how humans do) to get accurate highs and lows? This will help in correctly identifying break of structure and change of trend. Fixing the bars often leads to fake break of structures. I want to avoid that.

  • @SathishKumar-cg8er
    @SathishKumar-cg8er Рік тому

    Nice code as usual.. but if u can extend the code to find if price crosses the line from above & from below, we will b able to use it to automate price cross strategies…

    • @OrchardForex
      @OrchardForex  Рік тому

      This shows how to draw the line, after that all you have to do is check for price crossing.

  • @forester1
    @forester1 10 місяців тому

    I m new big fan of you sir ❤❤❤❤

  • @mugishajean7923
    @mugishajean7923 3 роки тому

    Thank you so much!

  • @forester1
    @forester1 10 місяців тому

    greate... works almost correct

  • @saeidsaati4021
    @saeidsaati4021 2 роки тому

    Thank you so much, great video, can you please make a video about creating a semi-log scale for Y axis via MQL, is it possible to do that in metatrader?

  • @MasterCzen
    @MasterCzen 7 місяців тому

    Hello. Can you show me how to make a counter of open and closed positions so that the ADVISER opens only one position to buy or sell during this day?

  • @mathewz7434
    @mathewz7434 Рік тому +2

    hello , how about finding equal peaks like double top

  • @martinriri4132
    @martinriri4132 2 роки тому

    hello Richard. i've been a long time follower of your classes and pointers and this was an eye opener. i however have a question on how to use the static double to save the high function (or any other coding reference that you may have), of the peak bars to be used as references for trade entries. like say a peak candle in the 30 minute timeframe to be a reference point of entry in a reference entry point for a lower timeframe.

    • @OrchardForex
      @OrchardForex  2 роки тому

      The functions allow you to specify the TF so just specify the M30. If you have a peak in M30 then it must also be a peak in any lower TF.

  • @molefanekennymphahlele1367
    @molefanekennymphahlele1367 2 роки тому

    Excellent video, thank you very much. Is it possible to do example of programming an alert indicator for specific time frame when the chart e.g create a low followed by high low then continues to form higher high, pulls back to retest the high low. The program must sound when market retest the high low or send an email. Meaning on a downtrend the chart will form a high then form a higher low followed by lower low, when chart retest higher low the program should sound or send an email

  • @KamiaKavi
    @KamiaKavi Рік тому

    Thanks for this amazing tutorial!
    Why is it currentBar-count and not currentBar-count+1? currentBar+1 takes currentBar one bar leftwards (so, if the index of currentBar is 10, it will be 11) and currentBar-count takes currentBar five bars rightwards (so, if currentBar is 10, it will be 10-5 = 5), so I think in this way the currentBar-count is one bar a head of currnetBar+1. Where am I missing the point?

    • @OrchardForex
      @OrchardForex  Рік тому

      The function with your example is looking for a bar with 5 (say lower) to left and right. That means bars 5-9 must be lower and also bars 11-15. So start bar is 10-5 for a search distance of 11

  • @rajisodiq2333
    @rajisodiq2333 Рік тому

    Thanks for this Mr Orchard.
    Please, how are we going to create High1, High2, Low1, and Low2 in order to be able to use this function for buy or sell entry? For instance, say,
    if H2 > H1 (BuyEntry).
    In this case, H1 is the Peak1 and High2 os the Peak 2.
    Does everything in the findpeak functions = H1/H2/L1/L2 ?
    I would be more than happy of I get a solution to ghis questions.
    Thanks for the training once again.

    • @OrchardForex
      @OrchardForex  Рік тому +1

      I'm not sure what is being asked. The functions find H1 and H2, so if you want to trade based on relative values then just compare them.

    • @rajisodiq2333
      @rajisodiq2333 Рік тому

      Sir, I meant; how will I say
      if(Peak2 > Peak1) ?
      What would be my Peak1

    • @rajisodiq2333
      @rajisodiq2333 Рік тому

      @@OrchardForex I've rematch the video and gotten what you mean sir. I've watched the video more than going to 10 times though

    • @rajisodiq2333
      @rajisodiq2333 Рік тому

      @@OrchardForex Do you have any free group or community for your students sir, I would like to join pls?

    • @rajisodiq2333
      @rajisodiq2333 Рік тому

      @@OrchardForex I tried to compare Bar1 and Bar2 but it doesn't work when I tested it. Pls what am I doing wrong sir?

  • @jglazebrook8930
    @jglazebrook8930 2 роки тому

    Thank you very much. Yet again works fantastically. One question would be. I was drawing the D1 Trendlines with the script, and when changing to the 5M TF, the trendline remains on the start of the day instead of being on the actual low that occurred during that day.... Is there an easy fix to this?
    And a big thank you again for the videos, very easy to understand.

    • @OrchardForex
      @OrchardForex  2 роки тому

      This is a script. It won't run again automatically when you change timeframe.

    • @jglazebrook8930
      @jglazebrook8930 2 роки тому

      @@OrchardForex Yes true, I missed the point that I converted it into an indicator, and hence my question above.

  • @ChargeUPFinancial
    @ChargeUPFinancial 3 роки тому

    Dear great Mr.Ochard
    Please make multiple videos on how to make all the pattern in codes
    Like head & shoulders
    Widgets ( Raising & falling )
    All the technical patterns please
    Thanks in advance MQL King

  • @yoenkurniadi4701
    @yoenkurniadi4701 7 місяців тому

    Hello Sir, how to get highest and lowest price after trade begin / open order? Thanks..

  • @Mkkhaneditx
    @Mkkhaneditx Рік тому

    How we identify the break of structure on impulse plzz make a code in mt5

  • @elijahchauke2522
    @elijahchauke2522 2 роки тому

    Excellent work, would you please show us how to write a code or an expert advisor that draw fib level

    • @elijahchauke2522
      @elijahchauke2522 2 роки тому

      Showing us when price is in uptrend and when is in down trend

  • @pulsemuziq
    @pulsemuziq Рік тому

    Interesting video.
    So how does one create an ea or indicator using zig zag to find out if the previous candle broke and closed below or above the previous zig zag high or low point?

    • @OrchardForex
      @OrchardForex  Рік тому

      zig zag is a repainting indicator. You have to remember the previous value in code.

  • @nhtr87
    @nhtr87 3 роки тому

    Thank' you

  • @chrischannel3250
    @chrischannel3250 2 роки тому

    What if peaks and lows are not based on iHighest, iLowest functions, but on a price shift? Meaning, if for a candle number 15 the price moves lower for 40 pips on both sides of the chart, then we consider High[15] as a swing Peak.

    • @OrchardForex
      @OrchardForex  2 роки тому +1

      Then that is not what this video is about.

  • @JsontheBarber
    @JsontheBarber 2 роки тому

    For some reason I'm getting these errors for lines 20 and 29
    'ObjectDelete' - no one of the overloads can be applied to the function call
    could be one of 2 function(s)
    built-in; bool ObjectDelete(long,const string)
    built-in; bool ObjectDelete(const string)

    • @OrchardForex
      @OrchardForex  2 роки тому

      That's exactly the format I have in the original code. You have mistyped something.

    • @JsontheBarber
      @JsontheBarber 2 роки тому

      @@OrchardForex I don't see any typos. This is exactly what is there...
      Line 20:
      ObjectDelete(0, "upper", OBJ_TREND, 0, iTime(Symbol(), Period(), bar2), iHigh(Symbol(), Period(), bar2), iTime(Symbol(), Period(), bar1), iHigh(Symbol(), Period(), bar1));
      Line 29:
      ObjectDelete(0, "lower", OBJ_TREND, 0, iTime(Symbol(), Period(), bar2), iLow(Symbol(), Period(), bar2), iTime(Symbol(), Period(), bar1), iLow(Symbol(), Period(), bar1));

    • @OrchardForex
      @OrchardForex  2 роки тому +1

      @@JsontheBarber That code is from the ObjectCreate function

    • @JsontheBarber
      @JsontheBarber 2 роки тому

      @@OrchardForex thank you! I don't know how I over looked that for 2 hours straight. .. (probably just looking too hard)

  • @shahinsinv
    @shahinsinv 3 роки тому

    Thanks A Lot, I am awaiting this type of code. Now can we use this code for Auto Trading .

    • @OrchardForex
      @OrchardForex  3 роки тому

      Yes you can. That's why I coded it as a function.

    • @shahinsinv
      @shahinsinv 3 роки тому

      @@OrchardForex Sir Thanks A Lot , I have made a indicator , which projection of new bar from M15 to Weekly high low , and make it free for MQL5 Community , you can convert it to expeert . if you permit me i will send you coode. Thanks .

  • @forester1
    @forester1 10 місяців тому

    ❤❤❤

  • @ronaldnkhoma8267
    @ronaldnkhoma8267 3 роки тому +1

    Could you kindly share the link to the code of the MQL Code?

  • @sairam-pn1lu
    @sairam-pn1lu 3 роки тому +1

    Thanks a lot sir, please can you post RSI divergence video

  • @pipwhisperer5952
    @pipwhisperer5952 3 роки тому

    Please help sir with finding previous high or low only

  • @HimasRafeek
    @HimasRafeek 3 роки тому

    Can you please teach how to make a web socket connection from mql4 to a php server so it can send and recieve data?

  • @SathishKumar-cg8er
    @SathishKumar-cg8er Рік тому

    Will u b able to extend this code to see if the price crosses these lines..

  • @shaileshsaxena
    @shaileshsaxena 3 роки тому +1

    Excellent lesson. Thank you once again. I am having problem with OrderSelect() function returning error 0 and leading my EA to believe that there is no open order opened by it. This happens mainly when I have another instance of this EA running on a different pair. I use different magic numbers for each instance. Please make a lesson on how to solve this. Thank you.

    • @OrchardForex
      @OrchardForex  3 роки тому

      OrderSelect returns a boolean indicating select was successful or not. It has no filters to select by symbol or magic. It appears you may be using OrderSelect incorrectly.

  • @HartmutGoetze
    @HartmutGoetze Рік тому

    🙏❤

  • @franciscojunior6841
    @franciscojunior6841 3 роки тому

    Nice...

  • @klangfarbeblau9087
    @klangfarbeblau9087 Рік тому

    Gosh tell me someone where this music is from before I get totally crazy :) I do not get it

  • @radihadzhiev6630
    @radihadzhiev6630 3 роки тому

    Hello, I am writing my own version of this but in the form of an indicator. When filling the line buffer I keep getting array out of bounds. I am resizing the array to be the size of rates_total + 1 on each on calculate call but I am still getting the error. Is it possible to do a tutorial on how to create an indicator when using the coppybuffer function is not applicable?

    • @OrchardForex
      @OrchardForex  3 роки тому

      Have you tried just printing the index value you are using when you get array out of bounds?

  • @ggeyy123
    @ggeyy123 3 роки тому

    Hi Sir,
    I have complied the script, it has error stating the FindNextPeak is not defined.
    Pls advise.
    Thank you.

    • @OrchardForex
      @OrchardForex  3 роки тому

      I can only assume that you have a typing error somewhere in the FindNextPeak function name.

  • @lungpung123
    @lungpung123 Рік тому

    owsem😇

  • @fcsc6381
    @fcsc6381 3 роки тому

    Can we identify the divergent using the awesome oscillator with code?

    • @OrchardForex
      @OrchardForex  3 роки тому +2

      Sure, why not?

    • @fcsc6381
      @fcsc6381 3 роки тому

      @@OrchardForex can you share some tutorial example ? 🙏🙏

  • @wamashudunetsianda974
    @wamashudunetsianda974 3 роки тому

    Can you make a video of an EA which place order only once per candle

    • @OrchardForex
      @OrchardForex  3 роки тому

      Does this help ua-cam.com/video/Ip7BBPe8mwA/v-deo.html

    • @wamashudunetsianda974
      @wamashudunetsianda974 3 роки тому

      @@OrchardForex it doesn't help, if you can please make a simple EA which can trade every candles but the moment it's either buy or sell it stops trading until new candle appears.

  • @rexstephen8054
    @rexstephen8054 2 роки тому

    Sir please how can o turn it into an indicator

    • @OrchardForex
      @OrchardForex  2 роки тому

      This just gives values. You need to know what you want to do with them before they can be used in an indicator.

  • @brightonviews4826
    @brightonviews4826 2 роки тому

    how can one parse this into an mql4 EA? i'm getting errors.

    • @OrchardForex
      @OrchardForex  2 роки тому +1

      The same functions will work in EA, Indicator and Script.

    • @brightonviews4826
      @brightonviews4826 2 роки тому

      @@OrchardForex it worked perfectly, thank you.

  • @OSWALD569
    @OSWALD569 3 роки тому +1

    Not good. He finally tests something that is good. But he never mentioned and shown the time of the second point of the line.

    • @OrchardForex
      @OrchardForex  3 роки тому +2

      Sorry you don't like my content. Everything in the functions is shown in the video. What you do with it is up to you

  • @NikitaSerditov
    @NikitaSerditov 3 роки тому

    Why do you need to rewrite Zigzag indicator?

  • @autosassfx1934
    @autosassfx1934 3 роки тому

    I found this interesting and I'm backtracking it in my EA. can you please write an array function to include the last 10 upper and lower points. Thank you

  • @mixai7
    @mixai7 3 роки тому

    Can copy to mql4?

    • @OrchardForex
      @OrchardForex  3 роки тому +2

      Yes, the same code works for both MQL4 and MQL5

  • @HansenKay-q1h
    @HansenKay-q1h Місяць тому

    Perez Thomas White Helen Davis John

  • @growmybusinessonline5711
    @growmybusinessonline5711 8 місяців тому

    Can you write an indicator for me in MQL5 if i give you the logic?

  • @makeit707
    @makeit707 2 роки тому

    I have troubles adding this to my EA! Can anyone assist me? I am new to code so this is kind of a problem for me… @orchard forex do you do small jobs i don’t have much but can pay something

    • @OrchardForex
      @OrchardForex  2 роки тому

      This script calls functions to find high and low points. You can just copy the function into your EA to do the same there but how you use the function depends on what your EA plans to do. The lines the script draws are really just for display.

    • @makeit707
      @makeit707 2 роки тому

      @@OrchardForex how do i use an And or a Or when adding it to buy conditions

    • @OrchardForex
      @OrchardForex  2 роки тому

      @@makeit707 I'm not sure what you are asking. This function just finds high and low points. You would need to have a way of using that in your expert. For example if h1 is the most recent high value from the function and h2 is the high before that, and you have similar l1 and l2 for low points, you might want to buy if h1 is higher than h2 and l1 is higher than l2. A traditional higher highs and higher lows. In that cast the and coudition would be if ( (h1>h2) && (l1>l2) ). For an or condition you still need to decide what you are testing then use || instead of &&

    • @makeit707
      @makeit707 2 роки тому

      @@OrchardForex what i am aiming for is if current candle is higher than higher point and candle(1) is a bear OR candle(2) is a bear than buy, thats what i am battling with the OR

    • @arthurmcalister1454
      @arthurmcalister1454 2 роки тому +1

      @@makeit707 So you use the function to get the recent high point, say you put that in double recentHigh. Then you have current price in a variable like double price. And for candles 1 and 2 you have open and close prices like open1, open2, close1, close2. A bear candle is where close