Hallo,
ist es möglich dieses Trendsystem so zu ändern, das der Einstieg erst dann erfolgt, wenn es 4 aufeinander folgende höhere Hochs und höhere Tiefst gegeben hat.
Der Entry soll erst an der Blauen Linie erfolgen wenn die HH und LL so angeordnet sind wie im Bild. Vielen Dank
//defparam calculateonlastbars=30000
ONCE HH = 0
ONCE HHprec = 0
ONCE LL = 0
ONCE LLprec = 0
if Not OnMarket Then
UseST = 0
ENDIF
if NOT LongOnMarket then
cp=3
LLbar=BOTx
EndIf
IF TradePrice = 0 THEN
PositionSize1 = 1
ELSE
PositionSize1 = 1000 / sp //Compute PositionSize
ENDIF
once lastpoint = 0
if high[cp] >= highest[2*cp+1](high) then
PEAK = 1
else
PEAK = 0
endif
if low[cp] <= lowest[2*cp+1](low) then
TROUGH = -1
else
TROUGH = 0
endif
if PEAK = 1 then
TOPy = high[cp]
TOPx = barindex[cp]
endif
if TROUGH = -1 then
BOTy = low[cp]
BOTx = barindex[cp]
endif
if PEAK>0 and (lastpoint=-1 or lastpoint=0) then
//DRAWSEGMENT(lastX,lastY,TOPx,TOPy) COLOURED(127,255,0,1000)
//DRAWTEXT("■",TOPx,TOPy,Dialog,Bold,10) coloured(200,0,0,255)
lastpoint = 1
lastX = TOPx
lastY = TOPy
HHprec= HH
HH = TOPy
HHbar = TOPx
endif
if TROUGH<0 and (lastpoint=1 or lastpoint=0) then
//DRAWSEGMENT(lastX,lastY,BOTx,BOTy) COLOURED(255,0,0,255)
//DRAWTEXT("■",BOTx,BOTy,Dialog,Bold,10) coloured(0,200,0,255)
lastpoint = -1
lastX = BOTx
lastY = BOTy
LLprec= LL
LL = BOTy
LLbar = BOTx
endif
//TREND ATTEMPT
atr=AverageTrueRange[14](close)
if TOPy > TOPy[1] and topy<>lasttop then
//drawarrowup(barindex,low-atr/2) coloured(0,200,0)
lasttop=topy
trendup = 1
else
trendup = 0
endif
//RETURN TOPy as "TOPy", BOTY as "BOTy", trendup as "trendup"
sp = close - 0
// Long
IF not longonmarket and (close crosses over HH) AND (HH > 0) AND (LL > LLprec) AND (LLprec > 0)and (HH > HHprec) and (HH > LL) and (HHprec > LLprec) THEN //
BUY Positionsize1 Contract at Market
//SL = abs(close - LL)
SET TARGET %PROFIT 100
set stop %loss 50
Hallo. Sie können beliebig viele zusätzliche Pivotpunkte speichern. Ich habe die vier höchsten und niedrigsten Pivotpunkte in Ihren Code eingefügt. Sie werden sehen, dass dies redundant ist.
//defparam calculateonlastbars=30000
ONCE HH = 0
ONCE HHprec = 0
ONCE LL = 0
ONCE LLprec = 0
if Not OnMarket Then
UseST = 0
ENDIF
if NOT LongOnMarket then
cp=3
LLbar=BOTx
EndIf
once lastpoint = 0
if high[cp] >= highest[2*cp+1](high) then
PEAK = 1
else
PEAK = 0
endif
if low[cp] <= lowest[2*cp+1](low) then
TROUGH = -1
else
TROUGH = 0
endif
if PEAK = 1 then
TOPy = high[cp]
TOPx = barindex[cp]
endif
if TROUGH = -1 then
BOTy = low[cp]
BOTx = barindex[cp]
endif
if PEAK>0 and (lastpoint=-1 or lastpoint=0) then
lastpoint = 1
lastX = TOPx
lastY = TOPy
HHprec= HH
HH = TOPy
HHbar = TOPx
hh1=hh2
hh1x=hh2x
hh2=hh3
hh2x=hh3x
hh3=hh4
hh3x=hh4x
hh4=TOPy
hh4x=TOPx
endif
if TROUGH<0 and (lastpoint=1 or lastpoint=0) then
lastpoint = -1
lastX = BOTx
lastY = BOTy
LLprec= LL
LL = BOTy
LLbar = BOTx
ll1=ll2
ll1x=ll2x
ll2=ll3
ll2x=ll3x
ll3=ll4
ll3x=ll4x
ll4=BOTy
ll4x=BOTx
endif
//TREND ATTEMPT
atr=AverageTrueRange[14](close)
if TOPy > TOPy[1] and topy<>lasttop then
lasttop=topy
trendup = 1
else
trendup = 0
endif
// Long
setupLong=hh4>hh3 and hh3>hh2 and hh2>hh1 and ll4>ll3 and ll3>ll2 and ll2>ll1
IF not longonmarket and (close crosses over HH) AND setuplong THEN //
BUY 1 Contract at Market
SL = abs(close - LL4)
SET TARGET price close+SL
set stop price ll4
endif
Hallo, vielen Dank!!!!
das wäre schön, dann könnte ich mit verschiedenen Trends experimentieren.
Können sie mir vielleicht in Ihrem Code markieren, was ich in welcher Zeile ändern muss, um zum Beispiel den Einstieg nach 5 aufeinander folgenden Hochs oder nur 3 aufeinander folgenden Hochs zu ändern??!!
Das wäre toll.
Vielen Dank
Hallo. Ich habe den Code so angepasst, dass Sie dies durch einfaches Ändern einer einzigen Variable erreichen können.
// --- SETTINGS ---
// Change this number to 3, 4, 5, etc. to experiment with different trend lengths
ONCE trendsRequired = 4
// --- INITIALIZATION ---
ONCE HH = 0
ONCE HHprec = 0
ONCE LL = 0
ONCE LLprec = 0
ONCE countHH = 0
ONCE countLL = 0
ONCE lastpoint = 0
// Pivot period
cp = 3
// --- PEAK AND TROUGH DETECTION ---
IF high[cp] >= highest[2 * cp + 1](high) THEN
PEAK = 1
ELSE
PEAK = 0
ENDIF
IF low[cp] <= lowest[2 * cp + 1](low) THEN
TROUGH = -1
ELSE
TROUGH = 0
ENDIF
IF PEAK = 1 THEN
TOPy = high[cp]
TOPx = barindex[cp]
ENDIF
IF TROUGH = -1 THEN
BOTy = low[cp]
BOTx = barindex[cp]
ENDIF
// --- LOGIC FOR HH (Picos) ---
IF PEAK > 0 AND (lastpoint = -1 OR lastpoint = 0) THEN
lastpoint = 1
HHprec = HH
HH = TOPy
// Check if current peak is higher than previous
IF HH > HHprec AND HHprec > 0 THEN
countHH = countHH + 1
ELSE
countHH = 1 // Reset to 1 as current is a peak
ENDIF
ENDIF
// --- LOGIC FOR LL (Valles) ---
IF TROUGH < 0 AND (lastpoint = 1 OR lastpoint = 0) THEN
lastpoint = -1
LLprec = LL
LL = BOTy
// Check if current trough is higher than previous
IF LL > LLprec AND LLprec > 0 THEN
countLL = countLL + 1
ELSE
countLL = 1 // Reset to 1 as current is a trough
ENDIF
ENDIF
// --- ENTRY LOGIC ---
// Trend is confirmed if both counters reach the required number
setupLong = countHH >= trendsRequired AND countLL >= trendsRequired
IF NOT LONGONMARKET AND (close CROSSES OVER HH) AND setupLong THEN
BUY 1 CONTRACT AT MARKET
// Risk Management
stopLossPrice = LL
SET STOP PRICE stopLossPrice
takeProfitPrice = close + (close - stopLossPrice)
SET TARGET PRICE takeProfitPrice
ENDIF
Ändern Sie diese Variable (trendsRequired)
Wow das ist toll…
Nur eine Kleine Sache ist nicht richtig, das LL soll immer größer als dass HHprec sein, siehe Bild