1. Welcome back! Thank you for being a part of this Traders Community. Let's discuss and share :)
    Selamat datang kembali! Trimakasih telah menjadi bagian dari Komunitas Trader ini. Mari berdiskusi dan berbagi :)
    Dismiss Notice

Looping Code High & Low Mql4

Discussion in 'Belajar MQL dari Nol' started by rickyandreas290292, 24 Jun 2023.

  1. rickyandreas290292

    rickyandreas290292 New Member

    Equity
    Credit
    Ref Point
    void OnTick() {
    // Looping high prices
    // Loop from 1 to 6
    for (int i = 1; i <= 6; i++) {
    double highestPrice = High;

    // Loop to find the highest price for the current range
    for (int j = i - 1; j >= 0; j--) {
    if (High[j] > highestPrice) {
    highestPrice = High[j];
    }
    }

    // Print the highest price for the current range
    Print("Highest price for Range 1-6, Bar ", i, ": ", highestPrice);
    }

    // Loop from 6 to 34
    for (int i = 6; i <= 34; i++) {
    double highestPrice = High;

    // Loop to find the highest price for the current range
    for (int j = i - 1; j >= i - 5; j--) {
    if (High[j] > highestPrice) {
    highestPrice = High[j];
    }
    }

    // Print the highest price for the current range
    Print("Highest price for Range 6-34, Bar ", i, ": ", highestPrice);
    }

    // Looping low prices
    // Loop from 1 to 6
    for (int i = 1; i <= 6; i++) {
    double lowestPrice = Low;

    // Loop to find the lowest price for the current range
    for (int j = i - 1; j >= 0; j--) {
    if (Low[j] < lowestPrice) {
    lowestPrice = Low[j];
    }
    }

    // Print the lowest price for the current range
    Print("Lowest price for Range 1-6, Bar ", i, ": ", lowestPrice);
    }

    // Loop from 6 to 34
    for (int i = 6; i <= 34; i++) {
    double lowestPrice = Low;

    // Loop to find the lowest price for the current range
    for (int j = i - 1; j >= i - 5; j--) {
    if (Low[j] < lowestPrice) {
    lowestPrice = Low[j];
    }
    }

    // Print the lowest price for the current range
    Print("Lowest price for Range 6-34, Bar ", i, ": ", lowestPrice);
    }
    }
     
  2. SulthonNurfalah

    SulthonNurfalah New Member

    Equity
    Credit
    Ref Point
    5/5,
    This is my review for this thread:
    Thanks for sharing
     

Share This Page