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
- This topic has 1 reply, 2 voices, and was last updated 6 hours ago by
LucasBest.
-
-
11/30/2025 at 12:11 PM #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);
}
}
}11/30/2025 at 4:36 PM #254105Annäherung123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195// ==============================================// ATH stacked buys sous ATH -X% (version PRT)// - Timeframe : 1 heure (appliquer le système sur H1)// - ATH sur LookbackDays (~ jours * 24 barres)// - On empile des achats à chaque palier de % sous l'ATH// - TP global = ATH + 1 point// ==============================================DEFPARAM CumulateOrders = TrueDEFPARAM PreLoadBars = 10000// ---------- Paramètres utilisateur ----------// Taille de base par niveauUnitsPerLevel = 1// Fenêtre de calcul de l'ATH (en jours approx.)LookbackDays = 365// Niveaux en % sous l'ATHLevel1 = 5.0Level2 = 10.0Level3 = 15.0Level4 = 20.0Level5 = 25.0Level6 = 30.0Level7 = 35.0Level8 = 40.0Level9 = 45.0// ---------- Variables internes ----------ONCE LastAth = 0ONCE Initialised = 0// ---------- Calcul de l'ATH sur la fenêtre LookbackDays ----------// Approximation : 1 jour ≈ 24 bougies H1BarsPerDay = 24BarsLookback = LookbackDays * BarsPerDayIF BarIndex > 0 THENAth = HighBarsToScan = BarsLookbackIF BarsToScan > BarIndex THENBarsToScan = BarIndexENDIFFOR i = 1 TO BarsToScan DOThisHigh = High[i]IF ThisHigh > Ath THENAth = ThisHighENDIFNEXTELSEAth = HighENDIF// Initialisation & mise à jour de l'ATHIF Ath > 0 THENIF Initialised = 0 THENLastAth = AthInitialised = 1ELSEIF Ath > LastAth THEN// Nouvel ATH : on remonte la référenceLastAth = AthENDIFENDIFENDIF// Si l'ATH n'est pas encore initialisé, on ne fait rienIF Initialised = 0 THENquitENDIF// ---------- Calcul du TP global ----------BaseTp = LastAth + PointSize// ---------- Calcul des prix de niveaux ----------// On ne place des niveaux que si le % > 0PriceLevel1 = 0PriceLevel2 = 0PriceLevel3 = 0PriceLevel4 = 0PriceLevel5 = 0PriceLevel6 = 0PriceLevel7 = 0PriceLevel8 = 0PriceLevel9 = 0IF Level1 > 0 THENPriceLevel1 = LastAth * (1 - Level1 / 100)ENDIFIF Level2 > 0 THENPriceLevel2 = LastAth * (1 - Level2 / 100)ENDIFIF Level3 > 0 THENPriceLevel3 = LastAth * (1 - Level3 / 100)ENDIFIF Level4 > 0 THENPriceLevel4 = LastAth * (1 - Level4 / 100)ENDIFIF Level5 > 0 THENPriceLevel5 = LastAth * (1 - Level5 / 100)ENDIFIF Level6 > 0 THENPriceLevel6 = LastAth * (1 - Level6 / 100)ENDIFIF Level7 > 0 THENPriceLevel7 = LastAth * (1 - Level7 / 100)ENDIFIF Level8 > 0 THENPriceLevel8 = LastAth * (1 - Level8 / 100)ENDIFIF Level9 > 0 THENPriceLevel9 = LastAth * (1 - Level9 / 100)ENDIF// ---------- Taille "théorique" à détenir selon la baisse vs ATH ----------// Idée :// - On compte combien de niveaux ont été atteints par le prix actuel (Close)// - Pour chaque niveau atteint, on veut UnitsPerLevel en plus// - On n'allège jamais sur rebond : la taille cible ne fait qu'augmenterTargetSize = 0IF PriceLevel1 > 0 AND Close <= PriceLevel1 THENTargetSize = TargetSize + UnitsPerLevelENDIFIF PriceLevel2 > 0 AND Close <= PriceLevel2 THENTargetSize = TargetSize + UnitsPerLevelENDIFIF PriceLevel3 > 0 AND Close <= PriceLevel3 THENTargetSize = TargetSize + UnitsPerLevelENDIFIF PriceLevel4 > 0 AND Close <= PriceLevel4 THENTargetSize = TargetSize + UnitsPerLevelENDIFIF PriceLevel5 > 0 AND Close <= PriceLevel5 THENTargetSize = TargetSize + UnitsPerLevelENDIFIF PriceLevel6 > 0 AND Close <= PriceLevel6 THENTargetSize = TargetSize + UnitsPerLevelENDIFIF PriceLevel7 > 0 AND Close <= PriceLevel7 THENTargetSize = TargetSize + UnitsPerLevelENDIFIF PriceLevel8 > 0 AND Close <= PriceLevel8 THENTargetSize = TargetSize + UnitsPerLevelENDIFIF PriceLevel9 > 0 AND Close <= PriceLevel9 THENTargetSize = TargetSize + UnitsPerLevelENDIF// On ne réduit jamais la taille : si le prix remonte,// on garde au moins la taille déjà détenue.CurrentSize = COUNTOFPOSITIONIF TargetSize < CurrentSize THENTargetSize = CurrentSizeENDIF// ---------- Entrées supplémentaires (empilement) ----------AdditionalSize = TargetSize - CurrentSizeIF AdditionalSize > 0 THEN// On place / met à jour le TP global pour toutes les positions longuesIF BaseTp > 0 THENSET TARGET PRICE BaseTpENDIFBUY AdditionalSize SHARES AT MARKETENDIF1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on 