Hier ist eine einfache Strategie für de40 und vgl

Forums ProRealTime Deutsch forum ProOrder Support Hier ist eine einfache Strategie für de40 und vgl

Viewing 2 posts - 1 through 2 (of 2 total)
  • #254094

    Ich frage ob es jmd in PRT-Sprache übersetzen kann
    im mt4 gab es keine Kompilierfehler
    die Idee dahinter ist wirklich einfach
    warten wir auf ein Corona 2.0
    LG

    //+——————————————————————+
    //| Expert Advisor: 5%.mq4 |
    //| Purpose: Place stacked Buy Limits below ATH – X%, TP = ATH + 1 |
    //| Logic: ATH from H1, check hourly at H1 close |
    //| Extension: ATH calculation by time window (days) |
    //+——————————————————————+

    #property strict
    #property show_inputs
    #property copyright “DKATLE 2025”
    #property link “https://www.dkatle.com”

    input string TradeComment = “%5”; // Unique text for orders

    // — Inputs
    input double Lots = 0.1; // Lot size per order
    input int Slippage = 10; // Slippage
    input int LookbackDays = 365; // Time window in days for ATH
    input int MagicNumber = 12345; // Unique ID for this EA

    // Stacking levels (percent below ATH)
    input double Level1 = 5.0;
    input double Level2 = 10.0;
    input double Level3 = 15.0;
    input double Level4 = 20.0;
    input double Level5 = 25.0;
    input double Level6 = 30.0;
    input double Level7 = 35.0;
    input double Level8 = 40.0;
    input double Level9 = 45.0;

    double lastATH = -1;
    datetime lastHourBar = 0;

    //— Calculate ATH from H1 candles within LookbackDays
    double GetLastATH(string sym, int daysBack)
    {
    int totalBars = iBars(sym, PERIOD_H1);
    if(totalBars <= 0) return -1;

    double ath = -DBL_MAX;
    datetime cutoff = TimeCurrent() – daysBack * 24 * 60 * 60;

    for(int i = 0; i < totalBars; i++)
    {
    datetime barTime = iTime(sym, PERIOD_H1, i);
    if(barTime < cutoff) break;
    double high = iHigh(sym, PERIOD_H1, i);
    if(high > ath) ath = high;
    }
    return ath;
    }

    //— Delete pending Buy Limits for current symbol & MagicNumber
    void DeletePendingBuyLimits(string sym)
    {
    for(int i = OrdersTotal() – 1; i >= 0; i–)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == sym && OrderType() == OP_BUYLIMIT && OrderMagicNumber() == MagicNumber)
    {
    if(!OrderDelete(OrderTicket()))
    Print(“OrderDelete error “, GetLastError(), ” for ticket “, OrderTicket());
    }
    }
    }
    }

    //— Check if a BuyLimit with same price already exists
    bool BuyLimitExists(string sym, double price)
    {
    for(int i = OrdersTotal() – 1; i >= 0; i–)
    {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
    if(OrderSymbol() == sym && OrderType() == OP_BUYLIMIT && OrderMagicNumber() == MagicNumber)
    {
    if(MathAbs(OrderOpenPrice() – price) < Point*0.5)
    return true;
    }
    }
    }
    return false;
    }

    //— Price validation and normalization
    bool ValidateAndNormalizePrices(string sym, double &price, double &tp)
    {
    int digits = (int)MarketInfo(sym, MODE_DIGITS);
    double point = MarketInfo(sym, MODE_POINT);
    int stopLevel = (int)MarketInfo(sym, MODE_STOPLEVEL);
    double ask = MarketInfo(sym, MODE_ASK);
    double minDist = stopLevel * point;

    price = NormalizeDouble(price, digits);
    tp = NormalizeDouble(tp, digits);

    if(price >= ask – minDist)
    {
    Print(“Invalid BuyLimit price “, price, ” (Ask “, ask, “, minDist “, minDist, “)”);
    return false;
    }

    if(tp <= price + minDist)
    {
    tp = price + MathMax(minDist, point);
    tp = NormalizeDouble(tp, digits);
    Print(“TP adjusted to “, tp, ” (minDist “, minDist, “)”);
    }

    return true;
    }

    //— Place new stacked Buy Limits
    void PlaceStackedBuyLimits(string sym, double ath)
    {
    double baseTp = ath + MarketInfo(sym, MODE_POINT);

    double levels[9];
    levels[0] = Level1;
    levels[1] = Level2;
    levels[2] = Level3;
    levels[3] = Level4;
    levels[4] = Level5;
    levels[5] = Level6;
    levels[6] = Level7;
    levels[7] = Level8;
    levels[8] = Level9;

    for(int i = 0; i < 9; i++)
    {
    double pct = levels[i];
    if(pct <= 0.0) continue;

    double buyPrice = ath * (1.0 – pct / 100.0);
    double tp = baseTp;

    if(!ValidateAndNormalizePrices(sym, buyPrice, tp))
    {
    Print(“Skipped: Level “, pct, “% (invalid price)”);
    continue;
    }

    if(BuyLimitExists(sym, buyPrice))
    {
    Print(“Skipped: Level “, pct, “% (duplicate order at “, buyPrice, “)”);
    continue;
    }

    int ticket = OrderSend(
    sym, OP_BUYLIMIT, Lots, buyPrice, Slippage,
    0, tp,
    TradeComment + ” ATH-” + DoubleToString(pct, 1) + “% TP=ATH+1”,
    MagicNumber, 0, clrBlue
    );
    if(ticket < 0)
    {
    int err = GetLastError();
    Print(“OrderSend error “, err, ” at level “, pct, “% (price “, buyPrice, “, TP “, tp, “)”);
    }
    }
    }

    //— Initialization
    int OnInit()
    {
    string sym = _Symbol;
    lastATH = GetLastATH(sym, LookbackDays);

    if(lastATH > 0)
    {
    DeletePendingBuyLimits(sym);
    PlaceStackedBuyLimits(sym, lastATH);
    }
    else
    {
    Print(“OnInit: No valid ATH found (Symbol “, sym, “).”);
    }

    lastHourBar = iTime(sym, PERIOD_H1, 0);
    return(INIT_SUCCEEDED);
    }

    //— OnTick: check only after H1 candle closes
    void OnTick()
    {
    string sym = _Symbol;
    datetime bt = iTime(sym, PERIOD_H1, 0);

    if(bt != lastHourBar && TimeCurrent() > bt)
    {
    lastHourBar = bt;

    double ath = GetLastATH(sym, LookbackDays);
    if(ath > 0 && ath > lastATH)
    {
    lastATH = ath;
    DeletePendingBuyLimits(sym);
    PlaceStackedBuyLimits(sym, ath);
    }
    }
    }

     

    #254105
    1 user thanked author for this post.
Viewing 2 posts - 1 through 2 (of 2 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login