Modular Algo System V2.0 inkl. DAX Intraday 1m System
Forums › ProRealTime Deutsch forum › ProOrder Support › Modular Algo System V2.0 inkl. DAX Intraday 1m System
- This topic has 35 replies, 12 voices, and was last updated 1 month ago by VinzentVega.
-
-
12/13/2022 at 8:40 PM #205728
Anbei mein zwischenzeitlich stark erweiterter modularer Algorithmus-Code
inkl. eines “Starter-Paketes zum Experimentieren.
Viel Spaß!
Kommentare sind natürlich willkommen!//*************************************************************************//
//Modular Algorithm Library V2.0 //
//*************************************************************************//
//Modules:
//Market-Data-Definition+Parameter
///Monthly/Weekly/Daily-Modifiers, Xetra-HLC-Correction, Strategy-Stop-Code mit Money-Management
//Moving-Average-Clustering-Filter, Robustness-Test, Stop-Loss/Trailing-Routines Long/Short/Risk
//Long/Short-Support2/Resistance2-Break-Filter, HexenSabbat-Filter
//Trading Code//*************************************************************************//
//Parameter //
//*************************************************************************//
DEFPARAM PreLoadBars = 10000
DEFPARAM CumulateOrders = false
ONCE TradeON = 0
ONCE Tradeday = 0ONCE IndexFaktoring = 0 // 1=ON 0=OFF Faktoring des Indexkurses
ONCE ClusterSave = 2 // 0=OFF 1=small 2=large 3=all MovingAverage-Clustering-Filter
ONCE startingsize = 0.25 // starting position size
ONCE maxsize = 2 // maximal positionsize
ONCE ForbiddenLSFlag = 0 // 0=OFF 1=ON 2=Reverse 3=Strict 4=StrictReverse S1/S2/Short-R1/R2/Long-Filter
ONCE RobustnessTest = 0 // 0=OFF 1=ON Robustness-Test
ONCE SSC = 0 // 0=OFF 1=ON 2=Alternative Strategy-Stop-Code
ONCE Reinvest = 1 // 0=OFF 1=ON Gewinne reinvestieren
ONCE ReinvestValue = 0.5 //Reinvestitionsanteil
ONCE StartingCapital = 20000 // Startkapital
ONCE Modifiers = 1 // 0=OFF 1=ON Modifikatoren auf PositionSize
ONCE DaySLFlag = 1 // 0=OFF 1=ON Intraday Short/Long-Reversal-Flag (Modifier)
ONCE MarketFlag = 1 // 1=DAX 2=DJI Marktauswahl
ONCE HexSabFilter = 1 // 0=OFF 1=ON HexenSabbatFilter
ONCE Overnight = 1 // 0=NO 1=YES Overnight Holding allowed//*************************************************************************//
//Market Data //
//*************************************************************************//
ONCE Opening = 080000 // Eröffnungszeit DAX
ONCE Closing = 220000 // Schlusszeit DAX
ONCE TF = 1 // TimeFrame in Minuten DAX
ONCE SpreadGeb = 4 // Spread+Gebühren DAX
ONCE Indexfaktor = 13000
ONCE Faktor1 = Close / Indexfaktor
ONCE FaktorTS = 1 // Trailing-Stop-MultiplikatorIF MarketFlag = 1 THEN
Opening = 080000 // Eröffnungszeit DAX
Closing = 220000 // Schlusszeit DAX
TF = 1 // TimeFrame in Minuten DAX
SpreadGeb = 4 // Spread+Gebühren DAX
ONCE FaktorTS = 1 // Trailing-Stop-Multiplikator
IF IndexFaktoring = 1 THEN
Indexfaktor = 14000
ELSIF Indexfaktoring = 0 THEN
Indexfaktor = Close
ENDIF
Faktor1 = Close / Indexfaktor
ENDIFIF MarketFlag = 2 THEN
Opening = 080000 // Eröffnungszeit DJI
Closing = 220000 // Schlusszeit DJI
TF = 1 // TimeFrame in Minuten DJI
SpreadGeb = 4 // Spread+Gebühren DJI
IF IndexFaktoring = 1 THEN
Indexfaktor = 30000
ELSIF Indexfaktoring = 0 THEN
Indexfaktor = Close
ENDIF
Faktor1 = Close / Indexfaktor
ONCE FaktorTS = 2.5 // Trailing-Stop-Multiplikator
ENDIFIF OpenDayOfWeek > 0 AND OpenDayOfWeek < 6 AND NOT (Month = 10 AND Day = 3) AND NOT (Month = 5 AND Day = 1) AND NOT (Month = 12 AND Day = 24) AND NOT (MONTH = 12 AND Day = 25) AND NOT (MONTH = 12 AND Day = 26) AND NOT (MONTH = 12 AND Day = 30) AND NOT (MONTH = 12 AND Day = 26) THEN
Tradeday = 1
ELSE
Tradeday = 0
ENDIF//Flat Failsave
If ONMARKET AND Overnight = 0 AND (Time < Opening OR Time > Closing) THEN
SELL AT Market
EXITSHORT AT Market
ENDIF//*************************************************************************//
//Algorithm Robustness-Test //
//*************************************************************************//
StartDate = 20000101 // Parameter
Qty = 5 // Parameter
Rndom = 3 // Parameter
once j = 0
once flag = 1IF RobustnessTest = 1 THEN
if flag = 1 then
j = j + 1
if j > qty then
flag = -1
j = j - 1
endif
endif
if flag = -1 then
j = j - 1
if j = 0 then
j = j + rndom
flag = 1
endif
endifif opendate >= startdate AND (barindex mod qty = 0 or barindex mod qty = j) then
tradeon = 1
ELSIF opendate >= startdate AND NOT (barindex mod qty = 0 or barindex mod qty = j) then
tradeon = 0
endif
ENDIF//*************************************************************************//
//Strategy-Stop-Code, Money Management/ReInvest //
//*************************************************************************//
barsbeforenextcheck = 30 // number of bars between performance checks
drawdownquitting = 1 // drawdown quitting on or off (on=1 off=0)
winratequit = 50 // minimum win rate in % allowed before quitting (0 = off)
tradesbeforewrquit = 50 // number of trades required before a win rate stop of strategy is allowed to happen
increase = 1 // position size increasing on or off (on=1 off=0)
decrease = 1 // position size decreasing on or off (on=1 off=0)
capital = StartingCapital // starting capital
minpossize = 1 // minimum position size allowed
gaintoinc = 5 // % profit rise needed before an increase in position size is made
losstodec = 5 // % loss needed before a decrease in position size is made
maxdrawdown = 50 // maximum % draw down allowed from highest ever equity before stopping strategy
maxcapitaldrop = 50 // maximum % starting capital lost before stopping strategy
ONCE highestprofit = 0
ONCE count = 0
ONCE win = 0
ONCE winrate = 0
ONCE MMpositionsize = 1
ONCE psperc = (MMpositionsize*startingsize) / (capital/100)
ONCE equity = StartingCapital
ONCE Profit1 = 0IF SSC = 1 THEN
if strategyprofit < strategyprofit[1] then
Profit1 = highestprofit - (strategyprofit[1] - strategyprofit)
highestprofit = highestprofit - Profit1
Profit1 = 0
ELSIF strategyprofit > strategyprofit[1] then
Profit1 = (strategyprofit - strategyprofit[1])*0.7
highestprofit = highestprofit + Profit1
Profit1 = 0
if count < tradesbeforewrquit OR winrate > winratequit/100 then
count = count + 1
if strategyprofit > strategyprofit[1] then
win = win + 1
endif
ENDIF
winrate = win/count
ENDIF
if count >= tradesbeforewrquit AND winrate < winratequit/100 then
quit
endif
if barindex mod barsbeforenextcheck = 0 AND drawdownquitting AND highestprofit <> 0 then
if (capital + strategyprofit) <= (capital + highestprofit) - ((capital + highestprofit)*(maxdrawdown/100)) then
quit
endif
endif
if count >= tradesbeforewrquit AND highestprofit = 0 then
if (capital + strategyprofit) <= capital - (capital * (maxcapitaldrop/100)) then
quit
endif
ENDIF
IF SSC = 2 THEN
MMpositionsize = max(((equity)/startingcapital),minpossize)
ENDIF
ENDIF//*******************************************************************************************//
//Position Size,Monthly,Weekly,Daily,Intra,Trend,Reversal Modifiers (optional) //
//*******************************************************************************************//
//Berechnung am Schluss löschen ( auf 1 setzen) für Löschen des Modifikators
ONCE PSizeL = startingsize
ONCE PSizeS = startingsize
ONCE MonthSizeL = 0
ONCE MonthSizeS = 0
ONCE WeekSizeL = 0
ONCE WeekSizeS = 0
ONCE DaySizeL = 0
ONCE DaySizeS = 0
ONCE Monatsanfang = 0
ONCE Monatsende = 0
ONCE IntraSizeL = 0
ONCE IntraSizeS = 0
ONCE GapCloseup = 0
ONCE GapClosedown = 0
ONCE VBaisse = 0
ONCE VHausse = 0
ONCE SentimentSizeL = 0
ONCE SentimentSizeS = 0
ONCE MidMonthSizeL = 0IF Modifiers = 1 THEN
IF MarketFlag = 1 THEN
IF XetraClose > XetraCloseOld THEN
VHausse = VHausse +1
VBaisse = 0
ELSIF XetraClose < XetraCloseOld THEN
VHausse = 0
VBaisse = VBaisse +1
ENDIF
IF VHausse > 5 THEN
SentimentSizeS = 0.5
ELSIF VBaisse > 5 THEN
SentimentSizeL = 0.5
ENDIF
IF Day > 8 AND Day < 12 THEN
MidMonthSizeL = 0.5
ELSE
MidMonthSizeL = 0
ENDIF
IF CurrentMonth = 1 THEN
MonthSizeS = 0.25
MonthSizeL = 0
ELSIF CurrentMonth >= 2 AND CurrentMonth >= 3 THEN
MonthSizeS = 0
MonthSizeL = 0.25
ELSIF CurrentMonth = 4 THEN
MonthSizeS = 0
PMonthSizeL = 0.5
ELSIF CurrentMonth = 5 THEN
MonthSizeS = 0
MonthSizeL = 0
ELSIF CurrentMonth = 6 THEN
MonthSizeS = 0.25
MonthSizeL = 0
ELSIF CurrentMonth = 7 THEN
MonthSizeS = 0
MonthSizeL = 0.25
ELSIF CurrentMonth >= 8 AND CurrentMonth <= 9 THEN
MonthSizeS = 0.25
MonthSizeL = 0
ELSIF CurrentMonth >= 10 AND CurrentMonth <= 12 THEN
MonthSizeS = 0
MonthSizeL = 0.5
ENDIF
IF Time = Opening THEN
If Day >= 01 AND Day <= 08 THEN
Monatsanfang = 1
ELSIF Day >= 25 AND Day <= 31 THEN
Monatsende = 1
ENDIF
ENDIF
IF Monatsanfang = 1 THEN
IF CurrentMonth >= 1 AND CurrentMonth <= 7 THEN
WeekSizeL = 0.25
WeekSizeS = 0
ELSIF CurrentMonth >= 8 AND CurrentMonth <= 9 THEN
WeeksizeL = 0
WeekSizeS = 0.25
ELSIF CurrentMonth = 10 THEN
WeeksizeL = 0
WeekSizeS = 0
ELSIF CurrentMonth >= 11 AND CurrentMonth <= 12 THEN
WeekSizeL = 0.25
WeekSizeS = 0
ENDIF
ENDIF
IF Monatsende = 1 THEN
IF CurrentMonth = 1 THEN
WeekSizeL = 0.25
WeekSizeS = 0
ELSIF CurrentMonth = 2 THEN
WeekSizeL = 0
WeekSizeS = 0
ELSIF CurrentMonth >= 3 AND CurrentMonth <= 6 THEN
WeeksizeL = 0.25
WeekSizeS = 0
ELSIF CurrentMonth = 7 THEN
WeekSizeL = 0
WeekSizeS = 0
ELSIF CurrentMonth >= 8 AND CurrentMonth <= 9 THEN
WeekSizeL = 0
WeekSizeS = 0.5
ELSIF CurrentMonth >= 10 AND CurrentMonth <= 12 THEN
WeeksizeL = 0.5
WeekSizeS = 0
ENDIF
ENDIF
IF OpenDayofWeek = 1 THEN
DaySizeL = 0.25
DaySizeS = 0
ELSIF OpenDayofWeek = 5 Then
DaySizeL = 0
DaySizeS = 0.25
ELSIF OpenDayofWeek <1 OR (OpenDayofWeek >= 2 AND OpenDayOfWeek <= 4) OR OpenDayofWeek = 6 THEN
DaySizeL = 0
DaySizeS = 0
ENDIF
IF Close < DLow(1) AND DaySLFlag = 1 THEN
IntraSizeL = 0.25
IntraSizeS = 0
ELSIF Close > DHigh(1) AND DaySLFlag = 1 THEN
IntraSizeL = 0
IntraSizeS = 0.25
ELSIF DaySLFlag = 0 THEN
IntraSizeL = 0
IntraSizeS = 0
ENDIF
IF Time >= Opening AND Time <= Closing THEN
IF Close > ResR2 THEN
IDReversalL = 0.25
ELSIF Close > ResR3 THEN
IDReversalL = 0.5
ELSIF Close < SupS2 AND Close > SupS3 THEN
IDReversalS = 0.25
ELSIF Close < SupS3 THEN
IDReversalS = 0.5
ELSIF Close < ResR2 AND Close > SupS2 THEN
IDReversalL = 0
IDReversalS = 0
ENDIF
ENDIF
IF Time = Closing THEN
TrendUp = 0
TrendDown = 0
ENDIF
IF Time = Opening THEN
IF DHigh(1) > DHigh(2) AND DLow(1) > DLow(2) THEN
TrendUp = 0.25
TrendDown = 0
ELSIF DHigh(1) < DHigh(2) AND DLow(1) < DLow(2) THEN
TrendUp = 0
TrendDown = 0.25
ENDIF
ENDIF
IF Time = Opening AND XetraCloseOld > XetraClose AND Close < XetraClose-10 THEN
GapCloseup = 0.5
GapClosedown = 0
ELSIF Time = Opening AND XetraCloseOld < XetraClose AND Close > XetraClose+10 THEN
GapCloseup = 0
GapClosedown = 0.5
ENDIF
ELSIF MarketFlag = 2 THEN
IF CurrentMonth = 1 THEN
MonthSizeS = 0.25
MonthSizeL = 0
ELSIF CurrentMonth = 3 OR CurrentMonth = 4 OR CurrentMonth = 5 THEN
MonthSizeS = 0
PMonthSizeL = 0.25
ELSIF CurrentMonth = 6 THEN
MonthSizeS = 0.25
MonthSizeL = 0
ELSIF CurrentMonth = 7 OR CurrentMonth = 8 THEN
MonthSizeS = 0
MonthSizeL = 0
ELSIF CurrentMonth = 9 THEN
MonthSizeS = 0.25
MonthSizeL = 0
ELSIF CurrentMonth >= 10 AND CurrentMonth <= 12 THEN
MonthSizeS = 0
MonthSizeL = 0.5
ENDIF
ENDIF
ENDIF//Einzelne Komponenten können nach belieben hier gelöscht werden, um die Modifikationen an eigene Vorstellungen anzupassen
IF Reinvest = 1 THEN
PositionSizeLong = (PSizeL*(PSizeL+TrendUp+IDReversalL+IntraSizeL+DaySizeL+WeekSizeL+MonthSizeL+GapCloseup+SentimentSizeL+MidMonthSizeL)*Min(maxsize,(1+(strategyprofit/startingcapital)*Reinvestvalue))*MMpositionsize)
PositionSizeShort = (PSizeS*(PSizeS+TrendDown+IDReversalS+IntraSizeS+DaySizeS+WeekSizeL+MonthSizeS+GapClosedown+SentimentSizeS)*Min(maxsize,(1+(strategyprofit/startingcapital)*Reinvestvalue))*MMpositionsize)
ELSIF Reinvest = 0 THEN
PositionSizeLong = Min(maxsize,(PSizeL*(PSizeL+TrendUp+IDReversalL+IntraSizeL+DaySizeL+WeekSizeL+MonthSizeL+GapCloseup+SentimentSizeL+MidMonthSizeL))*MMpositionsize)
PositionSizeShort = Min(maxsize,(PSizeS*(PSizeS+TrendDown+IDReversalS+IntraSizeS+DaySizeS+WeekSizeL+MonthSizeS+GapClosedown+SentimentSizeS))*MMpositionsize)
ELSIF Modifiers = 0 THEN
PositionSizeLong = Min(maxsize,(PSizeL*MMpositionsize))
PositionSizeShort = Min(maxsize,(PSizeS*MMpositionsize))
ENDIF//*************************************************************************//
//Xetra-Korrektur High Low Close, Pivot, Resistance, Support , Flags //
//*************************************************************************//
ONCE DayClose = 14536 // last numbers before start of algorithm
ONCE DayHigh = 14586
ONCE DayLow = 14389
ONCE XetraClose = 14523
ONCE XetraCloseOld = 14423ONCE ReachedXetra = 1
ONCE ReachedDayClose = 1
ONCE Reachedboth = 1
ONCE ClosetryCount = 0IF Time = 060000 THEN
ReachedXetra = 0
ReachedDayClose = 0
Reachedboth = 0
ClosetryCount = 0
ENDIFIF Time >= 070000 AND Time <= 113000 THEN
IF Close >= XetraClose-15 AND Close <= XetraClose+12 THEN
ReachedXetra = 1
ENDIF
IF Close >= DayClose-10 AND Close <= DayClose+12 THEN
ReachedDayClose = 1
ENDIF
IF (ReachedXetra = 1) AND (ReachedDayClose = 1) THEN
Reachedboth = 1
ENDIF
ENDIFOverboth = (Close-5 > XetraClose AND XetraClose > DayClose) OR (Close-5 > DayClose AND DayClose > XetraClose)
Underboth = (Close+5 < XetraClose AND XetraClose < DayClose) OR (Close+5 < DayClose AND DayClose < XetraClose)
AmplitudeMin = 10
hi = Highest[15](close[1])
lo = Lowest[15](close[1])IF Time = 174400 AND OPENDAYOFWEEK <6 AND OPENDAYOFWEEK >0 AND Tradeday THEN
IF (Close < XetraClose AND (Highest[585] < XetraClose-5)) OR ((Close > XetraClose) AND Lowest[585] > XetraClose+5) THEN
XetraCloseOld = XetraClose
ENDIF
ENDIF
IF TIME = 174500 AND OPENDAYOFWEEK <6 AND OPENDAYOFWEEK >0 AND Tradeday THEN
XetraClose = Close[0]
ENDIFIF Time = 220000 AND OPENDAYOFWEEK <6 AND OPENDAYOFWEEK >0 AND Tradeday then
DayClose = Close[0]
DayHigh = Highest[(840/TF)](close[0])
DayLow = Lowest[(840/TF)](close[0])
ENDIFif Time = 220000 AND OPENDAYOFWEEK <6 AND OPENDAYOFWEEK >0 AND Tradeday then
Pivot = (DayHigh + DayLow + DayClose) / 3
ResR1 = Pivot + (Pivot - DayLow)
ResR2 = Pivot + (Dayhigh - Daylow)
ResR3 = Dayhigh + (2 * (Pivot - Daylow))
SupS1 = Pivot - (Dayhigh - Pivot)
SupS2 = Pivot - (Dayhigh - Daylow)
SupS3 = Daylow - (2 * (Dayhigh - Pivot))
ENDIF//*************************************************************************//
//Moving-Average-Clustering-FilterCode (optional) //
//*************************************************************************//
xx = 15*pipsize //20-pip range
xy = 15*pipsize //20-pip range
ma4500 = Average[4500,0](close)
ma2500 = Average[2500,0](close)
ma1000 = average[1000,0](close)
ma50 = average[50,0](close)
ma100 = average[100,0](close)
ma200 = average[200,0](close)
MaxMA = max(ma1000,max(ma2500,max(ma100,ma200)))
MinMA = min(ma1000,min(ma2500,min(ma100,ma200)))IF ClusterSave = 1 OR ClusterSave = 3 THEN
IF (MaxMA - MinMA) <= xx THEN
Tradeon = 0
ELSIF (MaxMA - MinMA) > xx THEN
IF RobustnessTest = 0 THEN
Tradeon = 1
ELSIF opendate >= startdate AND NOT (barindex mod qty = 0 or barindex mod qty = j) THEN
Tradeon = 0
ENDIF
ENDIF
ENDIF
IF ClusterSave >= 2 THEN
IF (max(ma4500,ma2500)-min(ma4500,ma2500) < xy) OR (max(ma4500,ma1000)-min(ma4500,ma1000) < xy) OR (max(ma2500,ma1000)-min(ma2500,ma1000) < xy) THEN
Tradeon = 0
ENDIF
ENDIF//*************************************************************************//
//R2-Long/S2-Short Filter (optional) //
//*************************************************************************//
ONCE ForbiddenLong = 0
ONCE ForbiddenShort = 0IF ForbiddenLSFlag = 1 THEN
ForbiddenLong = Close < SupS2
ForbiddenShort = Close > ResR2
ELSIF ForbiddenLSFlag = 2 THEN
ForbiddenLong = Close > ResR2
ForbiddenShort = Close < SupS2
ELSIF ForbiddenLSFlag = 3 THEN
ForbiddenLong = Close < SupS1
ForbiddenShort = Close > ResR1
ELSIF ForbiddenLSFlag = 4 THEN
ForbiddenLong = Close > ResR1
ForbiddenShort = Close < SupS1
ELSIF ForbiddenLSFlag = 0 THEN
ForbiddenLong = 0
ForbiddenShort = 0
ENDIF//*************************************************************************//
//MA20/MA50- MA30/50- MA100/200- Cross-Flag //
//*************************************************************************//
MA20 = Average[20](close)
MA30 = Average[30](close)
MA50 = Average[50](close)
MA100 = Average[100](close)
MA200 = Average[200](close)
MA20over = (MA20 crosses over MA50)
MA20under = (MA20 crosses under MA50)
MA30over = (MA30 crosses over MA50)
MA30under = (MA30 crosses under MA50)
MA100over = (MA100 > MA200)
MA100under = (MA100 < MA200)//*************************************************************************//
//HexenSabbat-Filter //
//*************************************************************************//
IF HexSabFilter = 1 THEN
IF (CurrentMonth = 3 OR CurrentMonth = 6 OR CurrentMonth = 9 OR CurrentMonth = 12) AND OpenDayofWeek = 5 AND Day >= 15 AND Day <= 21 THEN
TradeDay = 0
ELSIF RobustnessTest = 0 AND Opening AND Tradeday THEN
TradeOn = 1
ELSE
TradeON = 0
ENDIF
ELSIF RobustnessTest = 0 AND Opening AND Tradeday THEN
TradeON = 1
ELSE
TradeON = 0
ENDIF//*************************************************************************//
//Daytrend-Flag //
//*************************************************************************//
ONCE TrendFlag = 0IF Time = Opening THEN
IF DHigh(1) > DHigh(2) AND DLow(1) > DLow(2) THEN
TrendFlag = 1
ELSIF DHigh(1) < DHigh(2) AND DLow(1) < DLow(2) THEN
TrendFlag = -1
ELSIF NOT (DHigh(1) > DHigh(2) AND DLow(1) > DLow(2)) AND NOT (DHigh(1) < DHigh(2) AND DLow(1) < DLow(2)) THEN
TrendFlag = 0
ENDIF
ENDIF
TrendUp = (TrendFlag = 1)
TrendDown = (TrendFlag = -1)//*************************************************************************//
//trailing stop function Risk, Long, Short //
//*************************************************************************//
//wenn gewünscht die Parameter ändern oder die SET STOP-CODES löschen
// TrailingFlag = 0 Special (Code im Modul)
// TrailingFlag = 1 Normal
// TrailingFlag = 2 Risk
trailingstartL = 35*FaktorTS*Faktor1 //LONG trailing will start @trailinstart points profit, TrailingFlag = 0
trailingstartS = 35*FaktorTS*Faktor1 //SHORT trailing will start @trailinstart points profit, TrailingFlag = 0
trailingL = 13*FaktorTS*Faktor1 //trailing to move the "stoploss"
trailingS= 13*FaktorTS*Faktor1 //trailing to move the "stoploss"
trailingR= 11*FaktorTS*Faktor1 //trailing start+to move the "stoploss" for risky positions, TrailingFlag = 2
SaveDistanceL = 16*Faktor1 //Minimum Stop-Abstand 10 lt IG
SaveDistanceS = 16*Faktor1 //Minimum Stop-Abstand 10 lt IG
SaveDistanceR = 16*Faktor1 //Minimum Stop-Abstand 10 lt IG
MinimumPlus = SpreadGeb //Anzahl Pips zum Breakeven inkl. Spread+Gebühren
ONCE TrailingFlag = 0
ONCE newSL = 0//reset the stoploss value
IF NOT ONMARKET THEN
TrailingFlag = 0
newSL = 0
ENDIF//************************//
//manage long positions //
//***********************//
IF LOngONMarket AND TrailingFlag = 1 THEN
newSL = tradeprice-(trailingstartL*pipsize)
ENDIF
//breakeven
IF LOngONMarket AND (close-tradeprice) >= ((SaveDistanceL+MinimumPlus)*pipsize) AND TrailingFlag = 1 THEN
newSL = Close-((SaveDistanceL)*pipsize)
TrailingFlag = 3
ENDIF
IF LOngONMarket AND (close-newSL) >= ((trailingL)*pipsize) AND TrailingFlag = 3 THEN
newSL = close-(trailingL*pipsize)
ENDIF
IF LongOnMarket AND TrailingFlag = 2 THEN
newSL = Close-(trailingR*pipsize)
ENDIF
//breakeven
IF LongOnMarket AND (close-tradeprice) >= ((MinimumPlus+SaveDistanceL)) THEN
newSL = Close-(SaveDistanceL)
TrailingFlag = 4
ENDIF
IF LongOnMarket AND (close-newSL) > (trailingL) AND TrailingFlag = 4 THEN
newSL = newSL+(close-trailingL)
ENDIF//************************//
//manage Short positions //
//************************//
IF ShortONMarket AND TrailingFlag = 1 THEN
newSL = tradeprice+(trailingstartS*pipsize)
ENDIF
//breakeven
IF ShortOnMarket AND (tradeprice-close) >= ((SaveDistanceS+MinimumPlus)*pipsize) AND TrailingFlag = 1 THEN
TrailingFlag = 3
newSL = Close+((SaveDistanceS)*pipsize)
ENDIF
IF ShortOnMarket AND (newSL-close) >= (trailingS*pipsize) AND TrailingFlag = 3 THEN
newSL = close+(trailingS*pipsize)
ENDIF
IF ShortOnMarket AND TrailingFlag = 2 THEN
newSL = Close+(trailingR*pipsize)
ENDIF
//breakeven
IF ShortOnMarket AND (tradeprice-close) >= ((MinimumPlus+SaveDistanceS)) THEN
newSL = Close-(SaveDistanceS)
TrailingFlag = 4
ENDIF
IF ShortOnMarket AND (newSL-close) => (trailingS) AND TrailingFlag = 4 THEN
newSL = close+((trailingS))
ENDIF//**********************************//
//stop order to exit the positions //
//*********************************//
IF LONGONMARKET AND Close <= Lowest[1440] AND newSL > 0 THEN
SELL AT MARKET
TrailingFlag = 0
ELSIF ShortOnMarket AND Close >= Highest[1440] AND NewSL > 0 THEN
EXITSHORT AT MARKET
TrailingFlag = 0
ENDIF
IF LongonMarket AND newSL > 0 AND close < newSL THEN
SELL AT MARKET
ELSIF ShortOnMarket AND newSL > 0 AND close > newSL THEN
EXITSHORT AT MARKET
ENDIF
IF LONGOnMarket AND newSL > 0 AND ((Close < newSL) OR (Average[20] crosses under Average[30] AND Average[30] < Average[50] AND Close < Average[2000] AND Close < Average[100] AND Average[100] < Average[200]) AND Close < Close[1] AND Close < tradeprice-100) THEN
SELL AT MARKET
TrailingFlag = 0
ELSIF ShortOnMarket AND newSL > 0 AND ((Close => newSL) OR (Average[20] > Average[30] AND Average[30] > Average[50] AND Close > Average[2000] AND Close > Average[100] AND Average[100] > Average[200]) AND Close > Close[1] AND Close > tradeprice+100 ) THEN
EXITSHORT AT MARKET
TrailingFlag = 0
ENDIF
IF Time = 220000 THEN
IF LongOnMarket THEN
newSL = newSL +2
ELSIF ShortOnMarket THEN
newSL = newSL -2
ENDIF
ENDIF//stop order to exit the positions if price went high/low enough
IF LongonMarket AND (Close - TradePrice) > 250 THEN
SELL AT MARKET
newSL = 0
TrailingFlag = 0
ELSIF ShortonMarket AND (TradePrice - Close) > 250 THEN
EXITSHORT AT MARKET
newSL = 0
TrailingFlag = 0
ENDIF//stop order to exit the positions if marketClose and price went high/low enough
IF LongonMarket AND (Time >= 220000 OR Time <= 070000) AND (Close - TradePrice) > MinimumPlus THEN
SELL AT MARKET
TrailingFlag = 0
newSL = 0
ELSIF ShortonMarket AND (Time >= 220000 OR Time <= 070000) AND (TradePrice - Close) > MinimumPlus THEN
EXITSHORT AT MARKET
TrailingFlag = 0
newSL = 0
ENDIF//*************************************************************************//
//Dayly-Gap-Strategy //
//*************************************************************************//
IF ClosetryCount < 10 THEN
IF ((TIME = 065900)) AND TradeON AND TradeDay AND NOT OnMarket THEN
IF NOT Forbiddenshort AND Close > Pivot+8 AND Close < Pivot+100 AND Aroondown > 5 AND RSI < 75 AND NOT Trendup AND Close < Average[10000] AND Close < Supertrend THEN
Sellshort PositionSizeShort Contracts AT MARKET
SET TARGET pProfit (Close-Pivot)-5
SET STOP pLOSS 50*Faktor1
ClosetryCount = ClosetryCount +1
ENDIF
IF Not Forbiddenlong AND Close < Pivot-8 AND Close > Pivot-55 AND Aroonup > 0 AND RSI > 20 AND NOT Trenddown AND Close = Highest[30] THEN
Buy PositionSizeLong Contracts AT MARKET
SET TARGET pProfit (Pivot-Close)-5
SET STOP pLOSS 50*Faktor1
ClosetryCount = ClosetryCount +1
ENDIF
ENDIFIF ((TIME = 075900)) AND NOT Reachedboth AND TradeON AND TradeDay AND NOT OnMarket THEN
IF NOT Forbiddenshort AND Close > Pivot+8 AND Close < Pivot+100 AND Aroondown > 5 AND RSI < 75 AND MACD < 2 AND NOT Trendup AND Close < Average[10000] AND Close < Supertrend THEN
Sellshort PositionSizeShort Contracts AT MARKET
SET TARGET pProfit (Close-Pivot)-5
SET STOP pLOSS 50*Faktor1
ClosetryCount = ClosetryCount +1
ENDIF
IF Not Forbiddenlong AND Close < Pivot-8 AND Close > Pivot-55 AND Aroonup > 0 AND RSI > 20 AND MACD > -1 AND NOT Trenddown AND Close = Highest[30] THEN
Buy PositionSizeLong Contracts AT MARKET
SET TARGET pProfit (Pivot-Close)-5
SET STOP pLOSS 50*Faktor1
ClosetryCount = ClosetryCount +1
ENDIF
ENDIFIF ((TIME >= 085400) AND (TIME <= 085500)) AND TradeON AND TradeDay THEN
IF NOT Forbiddenshort AND NOT OnMarket AND Close > Pivot+8 AND Close < Pivot+100 AND Aroondown > 10 AND RSI < 75 AND MACD < 2 AND Close < Average[200] AND Close < Average[10] AND NOT Trendup AND Close < Supertrend THEN
Sellshort PositionSizeShort Contracts AT MARKET
SET TARGET pProfit (Close-Pivot)-5
SET STOP pLOSS 50*Faktor1
ClosetryCount = ClosetryCount +1
ENDIF
IF Not Forbiddenlong AND NOT OnMarket AND Close < Pivot+8 AND Close > Pivot-55 AND Aroonup > 10 AND RSI > 20 AND MACD > -1 AND Close > Average[200] AND CLose > Average[1000] THEN
Buy PositionSizeLong Contracts AT MARKET
SET TARGET pProfit (Pivot-Close)-5
SET STOP pLOSS 50*Faktor1
ClosetryCount = ClosetryCount +1
ENDIF
ENDIFIF ((TIME >= 092500) AND (TIME <= 093500)) AND TradeON AND TradeDay THEN
IF NOT Forbiddenshort AND NOT OnMarket AND Close > Pivot+8 AND Close < Pivot+100 AND Aroondown > 20 AND RSI < 70 AND MACD < 1 AND Close < Average[200] AND Average[50] < Average[100] AND Average[100] < Average[200] AND Close < Average[10000] AND Overboth AND Close = Lowest[90] THEN
Sellshort PositionSizeShort Contracts AT MARKET
SET TARGET pProfit (Close-Pivot)-5
SET STOP pTrailing 100*Faktor1
ClosetryCount = ClosetryCount +1
ENDIF
IF Not Forbiddenlong AND NOT Onmarket AND Close < Pivot+8 AND Close > Pivot-100 AND Aroonup > 20 AND RSI > 25 AND MACD > 0 AND Close > Average[200] AND Average[50] > Average[200] AND Average[100] > Average[200] AND Close < XetraClose AND Underboth AND Close = Highest[90] THEN
Buy PositionSizeLong Contracts AT MARKET
SET TARGET pProfit (Pivot-Close)-5
SET STOP pTrailing 100*Faktor1
ClosetryCount = ClosetryCount +1
ENDIF
ENDIFIF (TIME >= 080000 AND TIME <= 113000) AND Tradeon AND Tradeday THEN
IF NOT ForbiddenShort AND Not Onmarket AND Overboth AND Reachedboth = 0 AND (Close > Average[4500]) AND (Close > Average[100]) AND (Close > Average[1000]) AND ((Average[2500] > Average[1000]) OR (Average[4500] > Average[2500]) OR (Average[4500] > Average[1000])) AND Aroondown > 5 AND RSI < 75 AND MACD < 2 AND Close < Highest[600] AND Close < Close[1] AND Close < Supertrend THEN
Sellshort PositionSizeShort Contracts AT MARKET
ClosetryCount = ClosetryCount +1
IF Close > DayClose+10 AND DayClose > (max(Pivot,XetraClose)) THEN
SET TARGET pProfit (Close - DayClose)-5
ELSE
SET TARGET pProfit (Close-min(min(DayClose,XetraClose),Pivot))-5
ENDIF
SET STOP pTrailing 220*Faktor1
ELSIF NOT ForbiddenShort AND Not Onmarket AND Reachedboth = 0 AND (Close > Average[100]) AND (Close < Average[1000]) AND (Average[2500] < Average[1000]-15) AND (Average[4500] < Average[2500]) AND Aroondown > 5 AND RSI < 75 AND MACD < 2 AND Close < Highest[600] AND NOT Trendup AND Close < Close[1] AND Close < Supertrend THEN
Sellshort PositionSizeShort Contracts AT MARKET
ClosetryCount = ClosetryCount +1
IF Close > DayClose+10 AND DayClose > (max(Pivot,XetraClose)) THEN
SET TARGET pProfit (Close - DayClose)-5
ELSE
SET TARGET pProfit (Close-max(max(DayClose,XetraClose),Pivot))-5
ENDIF
SET STOP pTrailing 170*Faktor1
ELSIF NOT ForbiddenLong AND NOT OnMarket AND Underboth AND Reachedboth = 0 AND ((Close < Average[4500]) AND Close < Average[100]) AND ((Average[2500] < Average[1000]) OR (Average[4500] < Average[2500]) OR (Average[4500] < Average[1000])) AND Aroonup > 15 AND RSI > 20 AND RSI < 75 AND Close > Close[1] AND Close > Supertrend THEN
Buy PositionSizeLong Contracts AT MARKET
ClosetryCount = ClosetryCount +1
IF Close < DayClose-10 AND DayClose < (min(XetraClose,Pivot)) THEN
SET TARGET pProfit (DayClose-Close)-5
ELSE
SET TARGET pProfit (max(max(DayClose,XetraClose),Pivot)-Close)-5
ENDIF
SET STOP pTrailing 170*Faktor1
ELSIF NOT ForbiddenLOng AND NOT OnMarket AND Underboth AND Reachedboth = 0 AND ((Close > Average[4500]) AND Close > Average[100]) AND ((Average[2500] > Average[1000]) AND (Average[4500] < Average[2500]) AND (Average[4500] < Average[1000])) AND Aroonup > 5 AND RSI > 20 AND MACD > -5 AND NOT Trenddown AND RSI < 75 AND Close > Close[1] AND Close > Supertrend THEN
Buy PositionSizeLong Contracts AT MARKET
ClosetryCount = ClosetryCount +1
IF Close < DayClose-10 AND DayClose < (min(XetraClose,Pivot)) THEN
SET TARGET pProfit (DayClose-Close)-5
ELSE
SET TARGET pProfit (max(XetraClose,Pivot)-Close)-5
ENDIF
SET STOP pTrailing 170*Faktor1
ELSIF NOT ForbiddenLong AND NOT OnMarket AND Underboth AND Reachedboth = 0 AND ((Average[2500] > Average[1000]) OR (Average[4500] > Average[2500]) OR (Average[4500] > Average[1000])) AND Close > Average[100] AND Average[200] > Average[1000] AND Aroonup > 5 AND RSI > 20 AND MACD > -5 AND NOT Trenddown AND RSI < 75 AND Close > Close[1] AND Close > Supertrend THEN
Buy PositionSizeLong Contracts AT MARKET
ClosetryCount = ClosetryCount +1
IF Close < DayClose-10 AND DayClose < (min(XetraClose,Pivot)) THEN
SET TARGET pProfit (DayClose-Close)-5
ELSE
SET TARGET pProfit (max(XetraClose,Pivot)-Close)-5
ENDIF
SET STOP pTrailing 170*Faktor1
ELSIF NOT ForbiddenLong AND NOT OnMarket AND Underboth AND Reachedboth = 0 AND ((Average[2500] > Average[1000]) AND (Average[4500] > Average[2500]) AND (Average[1000] > Average[200]) AND Average[200] > Average[100]) AND Close > Average[100] AND Aroonup > 5 AND RSI > 20 AND MACD > -2 AND RSI < 75 AND Close > Close[1] AND Close > Supertrend THEN
Buy PositionSizeLong Contracts AT MARKET
ClosetryCount = ClosetryCount +1
IF Close < DayClose-10 AND DayClose < (min(XetraClose,Pivot)) THEN
SET TARGET pProfit (DayClose-Close)-5
ELSE
SET TARGET pProfit (max(XetraClose,Pivot)-Close)-5
ENDIF
SET STOP pTrailing 200*Faktor1
ENDIF
ENDIF
ENDIF//*************************************************************************//
//Tagesschluss Rallye und Down M/W/D: o/o/o //
//*************************************************************************//
//up
IF Time >= 164500 AND Time <= 173000 AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenLong AND Close => hi THEN
IF Close > (Pivot) THEN
IF RSI > 20 AND MACD > -2 AND Close > Average[100] AND AroonUp > 5 AND MA20over AND Close < Highest[840] THEN
BUY PositionsizeLong CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ELSIF Close < Pivot AND RSI > 20 AND MACD > -2 AND Close > Average[100] AND AroonUp > 0 AND MA20over AND Average[50] > Average[100] THEN
BUY PositionsizeLong CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ENDIFIF Time >= 175000 AND Time <= 210000 AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenLong AND Close => hi THEN
IF Close < (Pivot) THEN
IF RSI > 20 AND MACD > -2 AND Close > Average[100] AND Average[100] > Average[200] AND Average[200] < Average[1000] AND Average[1000] < Average[2500] AND Average[2500] < Average[4500] AND AroonUp > 0 AND MA20over THEN
BUY PositionsizeLong CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ENDIF
ENDIF//down
IF (Time >= 164500 AND Time <= 173000) AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THEN
IF Close < (Pivot) THEN
IF RSI < 85 AND MACD < 2 AND Close < Average[50] AND AroonDown > 5 AND MA20under THEN
SellShort PositionsizeShort CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ENDIF
ENDIFIF Opendayofweek = 5 AND (Time >= 175000 AND Time <= 184500) AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THEN
IF Close > Pivot AND RSI < 25 AND MACD < -2 AND Close < Average[20] AND Close < Average[50] AND AroonDown > 5 AND Close < Average[100] THEN
SellShort PositionsizeShort CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ENDIFIF (Time >= 180000 AND Time <= 190000) AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THEN
IF Close > Pivot AND NOT ReachedXetra AND RSI < 75 AND MACD < 2 AND Close < Average[50] AND AroonDown > 5 AND MA20under AND Average[100] < Average[200] THEN
SellShort PositionsizeShort CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ENDIFIF Time >= 180000 AND Time <= 200000 AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THEN
IF Close > (Pivot) THEN
IF RSI < 75 AND MACD < 2 AND Close < Average[100] AND Average[100] < Average[200] AND Average[100] > Average[1000]+25 AND Average[1000] > Average[2500] AND AroonDown > 0 AND MA20under THEN
Sellshort PositionsizeShort CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ENDIF
ENDIFIF Time >= 190000 AND Time <= 215900 AND TradeDay AND TRADEON THEN
IF Close > ResR1 AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THEN
IF RSI < 75 AND MACD < 2 AND Close < Average[10] AND Average[10] < Average[30] AND Average[100] < Average[200] AND Average[200] > Average[1000] AND MA30under AND AroonDown > 0 THEN
Sellshort PositionsizeShort CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ELSIF Close < SupS1 AND NOT ONMARKET AND NOT ForbiddenLong AND Close >= hi THEN
IF RSI > 25 AND MACD > -2 AND Close > Average[10] AND Average[10] < Average[30] AND MA30over AND Average[100] > Average[200] AND Average[200] < Average[1000] AND AroonUp > 0 THEN
Buy PositionsizeLong CONTRACTS AT MARKET
SET STOP pLOSS 60*Faktor1
ENDIF
ENDIF
ENDIF// JahresendRallye
IF Time >= 143000 AND Time <= 171500 AND Close > Average[10000] AND Tradeday AND TradeON AND NOT ForbiddenLong AND NOT Trenddown AND NOT ONMARKET AND Close > Close[1] AND RSI > 25 AND RSI < 85 AND Close > Average[10] AND Average[20] > Average[30] AND AroonUp > 5 AND Close = Highest[60] AND Close < ResR3 AND (Close MOD 100) > 20 AND MACDLine < 10 AND Close > Average[1000] THEN
BUY PositionSizeLong CONTRACTS AT MARKET
SET STOP pTrailing 100*Faktor1
ENDIF// Nachmittagsanstieg
IF Time >= 143000 AND Time <= 200000 AND NOT Reachedboth AND Tradeday AND TradeON AND NOT ForbiddenLong AND Trendup AND CurrentMonth < 10 AND NOT ONMARKET AND Close > Close[1] AND RSI > 25 AND RSI < 85 AND Close > Average[10] AND Average[20] > Average[30] AND AroonUp > 5 AND Close = Highest[60] AND (Close MOD 100) > 20 AND MACDLine < 10 AND Close > Average[1000] THEN
BUY PositionSizeLong CONTRACTS AT MARKET
SET STOP pTrailing 100*Faktor1
ENDIF12/13/2022 at 8:52 PM #205729123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878//*************************************************************************////Modular Algorithm Library V2.0 ////*************************************************************************////Modules://Market-Data-Definition+Parameter///Monthly/Weekly/Daily-Modifiers, Xetra-HLC-Correction, Strategy-Stop-Code mit Money-Management//Moving-Average-Clustering-Filter, Robustness-Test, Stop-Loss/Trailing-Routines Long/Short/Risk//Long/Short-Support2/Resistance2-Break-Filter, HexenSabbat-Filter//Trading Code//*************************************************************************////Parameter ////*************************************************************************//DEFPARAM PreLoadBars = 10000DEFPARAM CumulateOrders = falseONCE TradeON = 0ONCE Tradeday = 0ONCE IndexFaktoring = 0 // 1=ON 0=OFF Faktoring des IndexkursesONCE ClusterSave = 2 // 0=OFF 1=small 2=large 3=all MovingAverage-Clustering-FilterONCE startingsize = 0.25 // starting position sizeONCE maxsize = 2 // maximal positionsizeONCE ForbiddenLSFlag = 0 // 0=OFF 1=ON 2=Reverse 3=Strict 4=StrictReverse S1/S2/Short-R1/R2/Long-FilterONCE RobustnessTest = 0 // 0=OFF 1=ON Robustness-TestONCE SSC = 0 // 0=OFF 1=ON 2=Alternative Strategy-Stop-CodeONCE Reinvest = 1 // 0=OFF 1=ON Gewinne reinvestierenONCE ReinvestValue = 0.5 //ReinvestitionsanteilONCE StartingCapital = 20000 // StartkapitalONCE Modifiers = 1 // 0=OFF 1=ON Modifikatoren auf PositionSizeONCE DaySLFlag = 1 // 0=OFF 1=ON Intraday Short/Long-Reversal-Flag (Modifier)ONCE MarketFlag = 1 // 1=DAX 2=DJI MarktauswahlONCE HexSabFilter = 1 // 0=OFF 1=ON HexenSabbatFilterONCE Overnight = 1 // 0=NO 1=YES Overnight Holding allowed//*************************************************************************////Market Data ////*************************************************************************//ONCE Opening = 080000 // Eröffnungszeit DAXONCE Closing = 220000 // Schlusszeit DAXONCE TF = 1 // TimeFrame in Minuten DAXONCE SpreadGeb = 4 // Spread+Gebühren DAXONCE Indexfaktor = 13000ONCE Faktor1 = Close / IndexfaktorONCE FaktorTS = 1 // Trailing-Stop-MultiplikatorIF MarketFlag = 1 THENOpening = 080000 // Eröffnungszeit DAXClosing = 220000 // Schlusszeit DAXTF = 1 // TimeFrame in Minuten DAXSpreadGeb = 4 // Spread+Gebühren DAXONCE FaktorTS = 1 // Trailing-Stop-MultiplikatorIF IndexFaktoring = 1 THENIndexfaktor = 14000ELSIF Indexfaktoring = 0 THENIndexfaktor = CloseENDIFFaktor1 = Close / IndexfaktorENDIFIF MarketFlag = 2 THENOpening = 080000 // Eröffnungszeit DJIClosing = 220000 // Schlusszeit DJITF = 1 // TimeFrame in Minuten DJISpreadGeb = 4 // Spread+Gebühren DJIIF IndexFaktoring = 1 THENIndexfaktor = 30000ELSIF Indexfaktoring = 0 THENIndexfaktor = CloseENDIFFaktor1 = Close / IndexfaktorONCE FaktorTS = 2.5 // Trailing-Stop-MultiplikatorENDIFIF OpenDayOfWeek > 0 AND OpenDayOfWeek < 6 AND NOT (Month = 10 AND Day = 3) AND NOT (Month = 5 AND Day = 1) AND NOT (Month = 12 AND Day = 24) AND NOT (MONTH = 12 AND Day = 25) AND NOT (MONTH = 12 AND Day = 26) AND NOT (MONTH = 12 AND Day = 30) AND NOT (MONTH = 12 AND Day = 26) THENTradeday = 1ELSETradeday = 0ENDIF//Flat FailsaveIf ONMARKET AND Overnight = 0 AND (Time < Opening OR Time > Closing) THENSELL AT MarketEXITSHORT AT MarketENDIF//*************************************************************************////Algorithm Robustness-Test ////*************************************************************************//StartDate = 20000101 // ParameterQty = 5 // ParameterRndom = 3 // Parameteronce j = 0once flag = 1IF RobustnessTest = 1 THENif flag = 1 thenj = j + 1if j > qty thenflag = -1j = j - 1endifendifif flag = -1 thenj = j - 1if j = 0 thenj = j + rndomflag = 1endifendifif opendate >= startdate AND (barindex mod qty = 0 or barindex mod qty = j) thentradeon = 1ELSIF opendate >= startdate AND NOT (barindex mod qty = 0 or barindex mod qty = j) thentradeon = 0endifENDIF//*************************************************************************////Strategy-Stop-Code, Money Management/ReInvest ////*************************************************************************//barsbeforenextcheck = 30 // number of bars between performance checksdrawdownquitting = 1 // drawdown quitting on or off (on=1 off=0)winratequit = 50 // minimum win rate in % allowed before quitting (0 = off)tradesbeforewrquit = 50 // number of trades required before a win rate stop of strategy is allowed to happenincrease = 1 // position size increasing on or off (on=1 off=0)decrease = 1 // position size decreasing on or off (on=1 off=0)capital = StartingCapital // starting capitalminpossize = 1 // minimum position size allowedgaintoinc = 5 // % profit rise needed before an increase in position size is madelosstodec = 5 // % loss needed before a decrease in position size is mademaxdrawdown = 50 // maximum % draw down allowed from highest ever equity before stopping strategymaxcapitaldrop = 50 // maximum % starting capital lost before stopping strategyONCE highestprofit = 0ONCE count = 0ONCE win = 0ONCE winrate = 0ONCE MMpositionsize = 1ONCE psperc = (MMpositionsize*startingsize) / (capital/100)ONCE equity = StartingCapitalONCE Profit1 = 0IF SSC = 1 THENif strategyprofit < strategyprofit[1] thenProfit1 = highestprofit - (strategyprofit[1] - strategyprofit)highestprofit = highestprofit - Profit1Profit1 = 0ELSIF strategyprofit > strategyprofit[1] thenProfit1 = (strategyprofit - strategyprofit[1])*0.7highestprofit = highestprofit + Profit1Profit1 = 0if count < tradesbeforewrquit OR winrate > winratequit/100 thencount = count + 1if strategyprofit > strategyprofit[1] thenwin = win + 1endifENDIFwinrate = win/countENDIFif count >= tradesbeforewrquit AND winrate < winratequit/100 thenquitendifif barindex mod barsbeforenextcheck = 0 AND drawdownquitting AND highestprofit <> 0 thenif (capital + strategyprofit) <= (capital + highestprofit) - ((capital + highestprofit)*(maxdrawdown/100)) thenquitendifendifif count >= tradesbeforewrquit AND highestprofit = 0 thenif (capital + strategyprofit) <= capital - (capital * (maxcapitaldrop/100)) thenquitendifENDIFIF SSC = 2 THENMMpositionsize = max(((equity)/startingcapital),minpossize)ENDIFENDIF//*******************************************************************************************////Position Size,Monthly,Weekly,Daily,Intra,Trend,Reversal Modifiers (optional) ////*******************************************************************************************////Berechnung am Schluss löschen ( auf 1 setzen) für Löschen des ModifikatorsONCE PSizeL = startingsizeONCE PSizeS = startingsizeONCE MonthSizeL = 0ONCE MonthSizeS = 0ONCE WeekSizeL = 0ONCE WeekSizeS = 0ONCE DaySizeL = 0ONCE DaySizeS = 0ONCE Monatsanfang = 0ONCE Monatsende = 0ONCE IntraSizeL = 0ONCE IntraSizeS = 0ONCE GapCloseup = 0ONCE GapClosedown = 0ONCE VBaisse = 0ONCE VHausse = 0ONCE SentimentSizeL = 0ONCE SentimentSizeS = 0ONCE MidMonthSizeL = 0IF Modifiers = 1 THENIF MarketFlag = 1 THENIF XetraClose > XetraCloseOld THENVHausse = VHausse +1VBaisse = 0ELSIF XetraClose < XetraCloseOld THENVHausse = 0VBaisse = VBaisse +1ENDIFIF VHausse > 5 THENSentimentSizeS = 0.5ELSIF VBaisse > 5 THENSentimentSizeL = 0.5ENDIFIF Day > 8 AND Day < 12 THENMidMonthSizeL = 0.5ELSEMidMonthSizeL = 0ENDIFIF CurrentMonth = 1 THENMonthSizeS = 0.25MonthSizeL = 0ELSIF CurrentMonth >= 2 AND CurrentMonth >= 3 THENMonthSizeS = 0MonthSizeL = 0.25ELSIF CurrentMonth = 4 THENMonthSizeS = 0PMonthSizeL = 0.5ELSIF CurrentMonth = 5 THENMonthSizeS = 0MonthSizeL = 0ELSIF CurrentMonth = 6 THENMonthSizeS = 0.25MonthSizeL = 0ELSIF CurrentMonth = 7 THENMonthSizeS = 0MonthSizeL = 0.25ELSIF CurrentMonth >= 8 AND CurrentMonth <= 9 THENMonthSizeS = 0.25MonthSizeL = 0ELSIF CurrentMonth >= 10 AND CurrentMonth <= 12 THENMonthSizeS = 0MonthSizeL = 0.5ENDIFIF Time = Opening THENIf Day >= 01 AND Day <= 08 THENMonatsanfang = 1ELSIF Day >= 25 AND Day <= 31 THENMonatsende = 1ENDIFENDIFIF Monatsanfang = 1 THENIF CurrentMonth >= 1 AND CurrentMonth <= 7 THENWeekSizeL = 0.25WeekSizeS = 0ELSIF CurrentMonth >= 8 AND CurrentMonth <= 9 THENWeeksizeL = 0WeekSizeS = 0.25ELSIF CurrentMonth = 10 THENWeeksizeL = 0WeekSizeS = 0ELSIF CurrentMonth >= 11 AND CurrentMonth <= 12 THENWeekSizeL = 0.25WeekSizeS = 0ENDIFENDIFIF Monatsende = 1 THENIF CurrentMonth = 1 THENWeekSizeL = 0.25WeekSizeS = 0ELSIF CurrentMonth = 2 THENWeekSizeL = 0WeekSizeS = 0ELSIF CurrentMonth >= 3 AND CurrentMonth <= 6 THENWeeksizeL = 0.25WeekSizeS = 0ELSIF CurrentMonth = 7 THENWeekSizeL = 0WeekSizeS = 0ELSIF CurrentMonth >= 8 AND CurrentMonth <= 9 THENWeekSizeL = 0WeekSizeS = 0.5ELSIF CurrentMonth >= 10 AND CurrentMonth <= 12 THENWeeksizeL = 0.5WeekSizeS = 0ENDIFENDIFIF OpenDayofWeek = 1 THENDaySizeL = 0.25DaySizeS = 0ELSIF OpenDayofWeek = 5 ThenDaySizeL = 0DaySizeS = 0.25ELSIF OpenDayofWeek <1 OR (OpenDayofWeek >= 2 AND OpenDayOfWeek <= 4) OR OpenDayofWeek = 6 THENDaySizeL = 0DaySizeS = 0ENDIFIF Close < DLow(1) AND DaySLFlag = 1 THENIntraSizeL = 0.25IntraSizeS = 0ELSIF Close > DHigh(1) AND DaySLFlag = 1 THENIntraSizeL = 0IntraSizeS = 0.25ELSIF DaySLFlag = 0 THENIntraSizeL = 0IntraSizeS = 0ENDIFIF Time >= Opening AND Time <= Closing THENIF Close > ResR2 THENIDReversalL = 0.25ELSIF Close > ResR3 THENIDReversalL = 0.5ELSIF Close < SupS2 AND Close > SupS3 THENIDReversalS = 0.25ELSIF Close < SupS3 THENIDReversalS = 0.5ELSIF Close < ResR2 AND Close > SupS2 THENIDReversalL = 0IDReversalS = 0ENDIFENDIFIF Time = Closing THENTrendUp = 0TrendDown = 0ENDIFIF Time = Opening THENIF DHigh(1) > DHigh(2) AND DLow(1) > DLow(2) THENTrendUp = 0.25TrendDown = 0ELSIF DHigh(1) < DHigh(2) AND DLow(1) < DLow(2) THENTrendUp = 0TrendDown = 0.25ENDIFENDIFIF Time = Opening AND XetraCloseOld > XetraClose AND Close < XetraClose-10 THENGapCloseup = 0.5GapClosedown = 0ELSIF Time = Opening AND XetraCloseOld < XetraClose AND Close > XetraClose+10 THENGapCloseup = 0GapClosedown = 0.5ENDIFELSIF MarketFlag = 2 THENIF CurrentMonth = 1 THENMonthSizeS = 0.25MonthSizeL = 0ELSIF CurrentMonth = 3 OR CurrentMonth = 4 OR CurrentMonth = 5 THENMonthSizeS = 0PMonthSizeL = 0.25ELSIF CurrentMonth = 6 THENMonthSizeS = 0.25MonthSizeL = 0ELSIF CurrentMonth = 7 OR CurrentMonth = 8 THENMonthSizeS = 0MonthSizeL = 0ELSIF CurrentMonth = 9 THENMonthSizeS = 0.25MonthSizeL = 0ELSIF CurrentMonth >= 10 AND CurrentMonth <= 12 THENMonthSizeS = 0MonthSizeL = 0.5ENDIFENDIFENDIF//Einzelne Komponenten können nach belieben hier gelöscht werden, um die Modifikationen an eigene Vorstellungen anzupassenIF Reinvest = 1 THENPositionSizeLong = (PSizeL*(PSizeL+TrendUp+IDReversalL+IntraSizeL+DaySizeL+WeekSizeL+MonthSizeL+GapCloseup+SentimentSizeL+MidMonthSizeL)*Min(maxsize,(1+(strategyprofit/startingcapital)*Reinvestvalue))*MMpositionsize)PositionSizeShort = (PSizeS*(PSizeS+TrendDown+IDReversalS+IntraSizeS+DaySizeS+WeekSizeL+MonthSizeS+GapClosedown+SentimentSizeS)*Min(maxsize,(1+(strategyprofit/startingcapital)*Reinvestvalue))*MMpositionsize)ELSIF Reinvest = 0 THENPositionSizeLong = Min(maxsize,(PSizeL*(PSizeL+TrendUp+IDReversalL+IntraSizeL+DaySizeL+WeekSizeL+MonthSizeL+GapCloseup+SentimentSizeL+MidMonthSizeL))*MMpositionsize)PositionSizeShort = Min(maxsize,(PSizeS*(PSizeS+TrendDown+IDReversalS+IntraSizeS+DaySizeS+WeekSizeL+MonthSizeS+GapClosedown+SentimentSizeS))*MMpositionsize)ELSIF Modifiers = 0 THENPositionSizeLong = Min(maxsize,(PSizeL*MMpositionsize))PositionSizeShort = Min(maxsize,(PSizeS*MMpositionsize))ENDIF//*************************************************************************////Xetra-Korrektur High Low Close, Pivot, Resistance, Support , Flags ////*************************************************************************//ONCE DayClose = 14536 // last numbers before start of algorithmONCE DayHigh = 14586ONCE DayLow = 14389ONCE XetraClose = 14523ONCE XetraCloseOld = 14423ONCE ReachedXetra = 1ONCE ReachedDayClose = 1ONCE Reachedboth = 1ONCE ClosetryCount = 0IF Time = 060000 THENReachedXetra = 0ReachedDayClose = 0Reachedboth = 0ClosetryCount = 0ENDIFIF Time >= 070000 AND Time <= 113000 THENIF Close >= XetraClose-15 AND Close <= XetraClose+12 THENReachedXetra = 1ENDIFIF Close >= DayClose-10 AND Close <= DayClose+12 THENReachedDayClose = 1ENDIFIF (ReachedXetra = 1) AND (ReachedDayClose = 1) THENReachedboth = 1ENDIFENDIFOverboth = (Close-5 > XetraClose AND XetraClose > DayClose) OR (Close-5 > DayClose AND DayClose > XetraClose)Underboth = (Close+5 < XetraClose AND XetraClose < DayClose) OR (Close+5 < DayClose AND DayClose < XetraClose)AmplitudeMin = 10hi = Highest[15](close[1])lo = Lowest[15](close[1])IF Time = 174400 AND OPENDAYOFWEEK <6 AND OPENDAYOFWEEK >0 AND Tradeday THENIF (Close < XetraClose AND (Highest[585] < XetraClose-5)) OR ((Close > XetraClose) AND Lowest[585] > XetraClose+5) THENXetraCloseOld = XetraCloseENDIFENDIFIF TIME = 174500 AND OPENDAYOFWEEK <6 AND OPENDAYOFWEEK >0 AND Tradeday THENXetraClose = Close[0]ENDIFIF Time = 220000 AND OPENDAYOFWEEK <6 AND OPENDAYOFWEEK >0 AND Tradeday thenDayClose = Close[0]DayHigh = Highest[(840/TF)](close[0])DayLow = Lowest[(840/TF)](close[0])ENDIFif Time = 220000 AND OPENDAYOFWEEK <6 AND OPENDAYOFWEEK >0 AND Tradeday thenPivot = (DayHigh + DayLow + DayClose) / 3ResR1 = Pivot + (Pivot - DayLow)ResR2 = Pivot + (Dayhigh - Daylow)ResR3 = Dayhigh + (2 * (Pivot - Daylow))SupS1 = Pivot - (Dayhigh - Pivot)SupS2 = Pivot - (Dayhigh - Daylow)SupS3 = Daylow - (2 * (Dayhigh - Pivot))ENDIF//*************************************************************************////Moving-Average-Clustering-FilterCode (optional) ////*************************************************************************//xx = 15*pipsize //20-pip rangexy = 15*pipsize //20-pip rangema4500 = Average[4500,0](close)ma2500 = Average[2500,0](close)ma1000 = average[1000,0](close)ma50 = average[50,0](close)ma100 = average[100,0](close)ma200 = average[200,0](close)MaxMA = max(ma1000,max(ma2500,max(ma100,ma200)))MinMA = min(ma1000,min(ma2500,min(ma100,ma200)))IF ClusterSave = 1 OR ClusterSave = 3 THENIF (MaxMA - MinMA) <= xx THENTradeon = 0ELSIF (MaxMA - MinMA) > xx THENIF RobustnessTest = 0 THENTradeon = 1ELSIF opendate >= startdate AND NOT (barindex mod qty = 0 or barindex mod qty = j) THENTradeon = 0ENDIFENDIFENDIFIF ClusterSave >= 2 THENIF (max(ma4500,ma2500)-min(ma4500,ma2500) < xy) OR (max(ma4500,ma1000)-min(ma4500,ma1000) < xy) OR (max(ma2500,ma1000)-min(ma2500,ma1000) < xy) THENTradeon = 0ENDIFENDIF//*************************************************************************////R2-Long/S2-Short Filter (optional) ////*************************************************************************//ONCE ForbiddenLong = 0ONCE ForbiddenShort = 0IF ForbiddenLSFlag = 1 THENForbiddenLong = Close < SupS2ForbiddenShort = Close > ResR2ELSIF ForbiddenLSFlag = 2 THENForbiddenLong = Close > ResR2ForbiddenShort = Close < SupS2ELSIF ForbiddenLSFlag = 3 THENForbiddenLong = Close < SupS1ForbiddenShort = Close > ResR1ELSIF ForbiddenLSFlag = 4 THENForbiddenLong = Close > ResR1ForbiddenShort = Close < SupS1ELSIF ForbiddenLSFlag = 0 THENForbiddenLong = 0ForbiddenShort = 0ENDIF//*************************************************************************////MA20/MA50- MA30/50- MA100/200- Cross-Flag ////*************************************************************************//MA20 = Average[20](close)MA30 = Average[30](close)MA50 = Average[50](close)MA100 = Average[100](close)MA200 = Average[200](close)MA20over = (MA20 crosses over MA50)MA20under = (MA20 crosses under MA50)MA30over = (MA30 crosses over MA50)MA30under = (MA30 crosses under MA50)MA100over = (MA100 > MA200)MA100under = (MA100 < MA200)//*************************************************************************////HexenSabbat-Filter ////*************************************************************************//IF HexSabFilter = 1 THENIF (CurrentMonth = 3 OR CurrentMonth = 6 OR CurrentMonth = 9 OR CurrentMonth = 12) AND OpenDayofWeek = 5 AND Day >= 15 AND Day <= 21 THENTradeDay = 0ELSIF RobustnessTest = 0 AND Opening AND Tradeday THENTradeOn = 1ELSETradeON = 0ENDIFELSIF RobustnessTest = 0 AND Opening AND Tradeday THENTradeON = 1ELSETradeON = 0ENDIF//*************************************************************************////Daytrend-Flag ////*************************************************************************//ONCE TrendFlag = 0IF Time = Opening THENIF DHigh(1) > DHigh(2) AND DLow(1) > DLow(2) THENTrendFlag = 1ELSIF DHigh(1) < DHigh(2) AND DLow(1) < DLow(2) THENTrendFlag = -1ELSIF NOT (DHigh(1) > DHigh(2) AND DLow(1) > DLow(2)) AND NOT (DHigh(1) < DHigh(2) AND DLow(1) < DLow(2)) THENTrendFlag = 0ENDIFENDIFTrendUp = (TrendFlag = 1)TrendDown = (TrendFlag = -1)//*************************************************************************////trailing stop function Risk, Long, Short ////*************************************************************************////wenn gewünscht die Parameter ändern oder die SET STOP-CODES löschen// TrailingFlag = 0 Special (Code im Modul)// TrailingFlag = 1 Normal// TrailingFlag = 2 RisktrailingstartL = 35*FaktorTS*Faktor1 //LONG trailing will start @trailinstart points profit, TrailingFlag = 0trailingstartS = 35*FaktorTS*Faktor1 //SHORT trailing will start @trailinstart points profit, TrailingFlag = 0trailingL = 13*FaktorTS*Faktor1 //trailing to move the "stoploss"trailingS= 13*FaktorTS*Faktor1 //trailing to move the "stoploss"trailingR= 11*FaktorTS*Faktor1 //trailing start+to move the "stoploss" for risky positions, TrailingFlag = 2SaveDistanceL = 16*Faktor1 //Minimum Stop-Abstand 10 lt IGSaveDistanceS = 16*Faktor1 //Minimum Stop-Abstand 10 lt IGSaveDistanceR = 16*Faktor1 //Minimum Stop-Abstand 10 lt IGMinimumPlus = SpreadGeb //Anzahl Pips zum Breakeven inkl. Spread+GebührenONCE TrailingFlag = 0ONCE newSL = 0//reset the stoploss valueIF NOT ONMARKET THENTrailingFlag = 0newSL = 0ENDIF//************************////manage long positions ////***********************//IF LOngONMarket AND TrailingFlag = 1 THENnewSL = tradeprice-(trailingstartL*pipsize)ENDIF//breakevenIF LOngONMarket AND (close-tradeprice) >= ((SaveDistanceL+MinimumPlus)*pipsize) AND TrailingFlag = 1 THENnewSL = Close-((SaveDistanceL)*pipsize)TrailingFlag = 3ENDIFIF LOngONMarket AND (close-newSL) >= ((trailingL)*pipsize) AND TrailingFlag = 3 THENnewSL = close-(trailingL*pipsize)ENDIFIF LongOnMarket AND TrailingFlag = 2 THENnewSL = Close-(trailingR*pipsize)ENDIF//breakevenIF LongOnMarket AND (close-tradeprice) >= ((MinimumPlus+SaveDistanceL)) THENnewSL = Close-(SaveDistanceL)TrailingFlag = 4ENDIFIF LongOnMarket AND (close-newSL) > (trailingL) AND TrailingFlag = 4 THENnewSL = newSL+(close-trailingL)ENDIF//************************////manage Short positions ////************************//IF ShortONMarket AND TrailingFlag = 1 THENnewSL = tradeprice+(trailingstartS*pipsize)ENDIF//breakevenIF ShortOnMarket AND (tradeprice-close) >= ((SaveDistanceS+MinimumPlus)*pipsize) AND TrailingFlag = 1 THENTrailingFlag = 3newSL = Close+((SaveDistanceS)*pipsize)ENDIFIF ShortOnMarket AND (newSL-close) >= (trailingS*pipsize) AND TrailingFlag = 3 THENnewSL = close+(trailingS*pipsize)ENDIFIF ShortOnMarket AND TrailingFlag = 2 THENnewSL = Close+(trailingR*pipsize)ENDIF//breakevenIF ShortOnMarket AND (tradeprice-close) >= ((MinimumPlus+SaveDistanceS)) THENnewSL = Close-(SaveDistanceS)TrailingFlag = 4ENDIFIF ShortOnMarket AND (newSL-close) => (trailingS) AND TrailingFlag = 4 THENnewSL = close+((trailingS))ENDIF//**********************************////stop order to exit the positions ////*********************************//IF LONGONMARKET AND Close <= Lowest[1440] AND newSL > 0 THENSELL AT MARKETTrailingFlag = 0ELSIF ShortOnMarket AND Close >= Highest[1440] AND NewSL > 0 THENEXITSHORT AT MARKETTrailingFlag = 0ENDIFIF LongonMarket AND newSL > 0 AND close < newSL THENSELL AT MARKETELSIF ShortOnMarket AND newSL > 0 AND close > newSL THENEXITSHORT AT MARKETENDIFIF LONGOnMarket AND newSL > 0 AND ((Close < newSL) OR (Average[20] crosses under Average[30] AND Average[30] < Average[50] AND Close < Average[2000] AND Close < Average[100] AND Average[100] < Average[200]) AND Close < Close[1] AND Close < tradeprice-100) THENSELL AT MARKETTrailingFlag = 0ELSIF ShortOnMarket AND newSL > 0 AND ((Close => newSL) OR (Average[20] > Average[30] AND Average[30] > Average[50] AND Close > Average[2000] AND Close > Average[100] AND Average[100] > Average[200]) AND Close > Close[1] AND Close > tradeprice+100 ) THENEXITSHORT AT MARKETTrailingFlag = 0ENDIFIF Time = 220000 THENIF LongOnMarket THENnewSL = newSL +2ELSIF ShortOnMarket THENnewSL = newSL -2ENDIFENDIF//stop order to exit the positions if price went high/low enoughIF LongonMarket AND (Close - TradePrice) > 250 THENSELL AT MARKETnewSL = 0TrailingFlag = 0ELSIF ShortonMarket AND (TradePrice - Close) > 250 THENEXITSHORT AT MARKETnewSL = 0TrailingFlag = 0ENDIF//stop order to exit the positions if marketClose and price went high/low enoughIF LongonMarket AND (Time >= 220000 OR Time <= 070000) AND (Close - TradePrice) > MinimumPlus THENSELL AT MARKETTrailingFlag = 0newSL = 0ELSIF ShortonMarket AND (Time >= 220000 OR Time <= 070000) AND (TradePrice - Close) > MinimumPlus THENEXITSHORT AT MARKETTrailingFlag = 0newSL = 0ENDIF//*************************************************************************////Dayly-Gap-Strategy ////*************************************************************************//IF ClosetryCount < 10 THENIF ((TIME = 065900)) AND TradeON AND TradeDay AND NOT OnMarket THENIF NOT Forbiddenshort AND Close > Pivot+8 AND Close < Pivot+100 AND Aroondown > 5 AND RSI < 75 AND NOT Trendup AND Close < Average[10000] AND Close < Supertrend THENSellshort PositionSizeShort Contracts AT MARKETSET TARGET pProfit (Close-Pivot)-5SET STOP pLOSS 50*Faktor1ClosetryCount = ClosetryCount +1ENDIFIF Not Forbiddenlong AND Close < Pivot-8 AND Close > Pivot-55 AND Aroonup > 0 AND RSI > 20 AND NOT Trenddown AND Close = Highest[30] THENBuy PositionSizeLong Contracts AT MARKETSET TARGET pProfit (Pivot-Close)-5SET STOP pLOSS 50*Faktor1ClosetryCount = ClosetryCount +1ENDIFENDIFIF ((TIME = 075900)) AND NOT Reachedboth AND TradeON AND TradeDay AND NOT OnMarket THENIF NOT Forbiddenshort AND Close > Pivot+8 AND Close < Pivot+100 AND Aroondown > 5 AND RSI < 75 AND MACD < 2 AND NOT Trendup AND Close < Average[10000] AND Close < Supertrend THENSellshort PositionSizeShort Contracts AT MARKETSET TARGET pProfit (Close-Pivot)-5SET STOP pLOSS 50*Faktor1ClosetryCount = ClosetryCount +1ENDIFIF Not Forbiddenlong AND Close < Pivot-8 AND Close > Pivot-55 AND Aroonup > 0 AND RSI > 20 AND MACD > -1 AND NOT Trenddown AND Close = Highest[30] THENBuy PositionSizeLong Contracts AT MARKETSET TARGET pProfit (Pivot-Close)-5SET STOP pLOSS 50*Faktor1ClosetryCount = ClosetryCount +1ENDIFENDIFIF ((TIME >= 085400) AND (TIME <= 085500)) AND TradeON AND TradeDay THENIF NOT Forbiddenshort AND NOT OnMarket AND Close > Pivot+8 AND Close < Pivot+100 AND Aroondown > 10 AND RSI < 75 AND MACD < 2 AND Close < Average[200] AND Close < Average[10] AND NOT Trendup AND Close < Supertrend THENSellshort PositionSizeShort Contracts AT MARKETSET TARGET pProfit (Close-Pivot)-5SET STOP pLOSS 50*Faktor1ClosetryCount = ClosetryCount +1ENDIFIF Not Forbiddenlong AND NOT OnMarket AND Close < Pivot+8 AND Close > Pivot-55 AND Aroonup > 10 AND RSI > 20 AND MACD > -1 AND Close > Average[200] AND CLose > Average[1000] THENBuy PositionSizeLong Contracts AT MARKETSET TARGET pProfit (Pivot-Close)-5SET STOP pLOSS 50*Faktor1ClosetryCount = ClosetryCount +1ENDIFENDIFIF ((TIME >= 092500) AND (TIME <= 093500)) AND TradeON AND TradeDay THENIF NOT Forbiddenshort AND NOT OnMarket AND Close > Pivot+8 AND Close < Pivot+100 AND Aroondown > 20 AND RSI < 70 AND MACD < 1 AND Close < Average[200] AND Average[50] < Average[100] AND Average[100] < Average[200] AND Close < Average[10000] AND Overboth AND Close = Lowest[90] THENSellshort PositionSizeShort Contracts AT MARKETSET TARGET pProfit (Close-Pivot)-5SET STOP pTrailing 100*Faktor1ClosetryCount = ClosetryCount +1ENDIFIF Not Forbiddenlong AND NOT Onmarket AND Close < Pivot+8 AND Close > Pivot-100 AND Aroonup > 20 AND RSI > 25 AND MACD > 0 AND Close > Average[200] AND Average[50] > Average[200] AND Average[100] > Average[200] AND Close < XetraClose AND Underboth AND Close = Highest[90] THENBuy PositionSizeLong Contracts AT MARKETSET TARGET pProfit (Pivot-Close)-5SET STOP pTrailing 100*Faktor1ClosetryCount = ClosetryCount +1ENDIFENDIFIF (TIME >= 080000 AND TIME <= 113000) AND Tradeon AND Tradeday THENIF NOT ForbiddenShort AND Not Onmarket AND Overboth AND Reachedboth = 0 AND (Close > Average[4500]) AND (Close > Average[100]) AND (Close > Average[1000]) AND ((Average[2500] > Average[1000]) OR (Average[4500] > Average[2500]) OR (Average[4500] > Average[1000])) AND Aroondown > 5 AND RSI < 75 AND MACD < 2 AND Close < Highest[600] AND Close < Close[1] AND Close < Supertrend THENSellshort PositionSizeShort Contracts AT MARKETClosetryCount = ClosetryCount +1IF Close > DayClose+10 AND DayClose > (max(Pivot,XetraClose)) THENSET TARGET pProfit (Close - DayClose)-5ELSESET TARGET pProfit (Close-min(min(DayClose,XetraClose),Pivot))-5ENDIFSET STOP pTrailing 220*Faktor1ELSIF NOT ForbiddenShort AND Not Onmarket AND Reachedboth = 0 AND (Close > Average[100]) AND (Close < Average[1000]) AND (Average[2500] < Average[1000]-15) AND (Average[4500] < Average[2500]) AND Aroondown > 5 AND RSI < 75 AND MACD < 2 AND Close < Highest[600] AND NOT Trendup AND Close < Close[1] AND Close < Supertrend THENSellshort PositionSizeShort Contracts AT MARKETClosetryCount = ClosetryCount +1IF Close > DayClose+10 AND DayClose > (max(Pivot,XetraClose)) THENSET TARGET pProfit (Close - DayClose)-5ELSESET TARGET pProfit (Close-max(max(DayClose,XetraClose),Pivot))-5ENDIFSET STOP pTrailing 170*Faktor1ELSIF NOT ForbiddenLong AND NOT OnMarket AND Underboth AND Reachedboth = 0 AND ((Close < Average[4500]) AND Close < Average[100]) AND ((Average[2500] < Average[1000]) OR (Average[4500] < Average[2500]) OR (Average[4500] < Average[1000])) AND Aroonup > 15 AND RSI > 20 AND RSI < 75 AND Close > Close[1] AND Close > Supertrend THENBuy PositionSizeLong Contracts AT MARKETClosetryCount = ClosetryCount +1IF Close < DayClose-10 AND DayClose < (min(XetraClose,Pivot)) THENSET TARGET pProfit (DayClose-Close)-5ELSESET TARGET pProfit (max(max(DayClose,XetraClose),Pivot)-Close)-5ENDIFSET STOP pTrailing 170*Faktor1ELSIF NOT ForbiddenLOng AND NOT OnMarket AND Underboth AND Reachedboth = 0 AND ((Close > Average[4500]) AND Close > Average[100]) AND ((Average[2500] > Average[1000]) AND (Average[4500] < Average[2500]) AND (Average[4500] < Average[1000])) AND Aroonup > 5 AND RSI > 20 AND MACD > -5 AND NOT Trenddown AND RSI < 75 AND Close > Close[1] AND Close > Supertrend THENBuy PositionSizeLong Contracts AT MARKETClosetryCount = ClosetryCount +1IF Close < DayClose-10 AND DayClose < (min(XetraClose,Pivot)) THENSET TARGET pProfit (DayClose-Close)-5ELSESET TARGET pProfit (max(XetraClose,Pivot)-Close)-5ENDIFSET STOP pTrailing 170*Faktor1ELSIF NOT ForbiddenLong AND NOT OnMarket AND Underboth AND Reachedboth = 0 AND ((Average[2500] > Average[1000]) OR (Average[4500] > Average[2500]) OR (Average[4500] > Average[1000])) AND Close > Average[100] AND Average[200] > Average[1000] AND Aroonup > 5 AND RSI > 20 AND MACD > -5 AND NOT Trenddown AND RSI < 75 AND Close > Close[1] AND Close > Supertrend THENBuy PositionSizeLong Contracts AT MARKETClosetryCount = ClosetryCount +1IF Close < DayClose-10 AND DayClose < (min(XetraClose,Pivot)) THENSET TARGET pProfit (DayClose-Close)-5ELSESET TARGET pProfit (max(XetraClose,Pivot)-Close)-5ENDIFSET STOP pTrailing 170*Faktor1ELSIF NOT ForbiddenLong AND NOT OnMarket AND Underboth AND Reachedboth = 0 AND ((Average[2500] > Average[1000]) AND (Average[4500] > Average[2500]) AND (Average[1000] > Average[200]) AND Average[200] > Average[100]) AND Close > Average[100] AND Aroonup > 5 AND RSI > 20 AND MACD > -2 AND RSI < 75 AND Close > Close[1] AND Close > Supertrend THENBuy PositionSizeLong Contracts AT MARKETClosetryCount = ClosetryCount +1IF Close < DayClose-10 AND DayClose < (min(XetraClose,Pivot)) THENSET TARGET pProfit (DayClose-Close)-5ELSESET TARGET pProfit (max(XetraClose,Pivot)-Close)-5ENDIFSET STOP pTrailing 200*Faktor1ENDIFENDIFENDIF//*************************************************************************////Tagesschluss Rallye und Down M/W/D: o/o/o ////*************************************************************************////upIF Time >= 164500 AND Time <= 173000 AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenLong AND Close => hi THENIF Close > (Pivot) THENIF RSI > 20 AND MACD > -2 AND Close > Average[100] AND AroonUp > 5 AND MA20over AND Close < Highest[840] THENBUY PositionsizeLong CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFELSIF Close < Pivot AND RSI > 20 AND MACD > -2 AND Close > Average[100] AND AroonUp > 0 AND MA20over AND Average[50] > Average[100] THENBUY PositionsizeLong CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFENDIFIF Time >= 175000 AND Time <= 210000 AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenLong AND Close => hi THENIF Close < (Pivot) THENIF RSI > 20 AND MACD > -2 AND Close > Average[100] AND Average[100] > Average[200] AND Average[200] < Average[1000] AND Average[1000] < Average[2500] AND Average[2500] < Average[4500] AND AroonUp > 0 AND MA20over THENBUY PositionsizeLong CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFENDIFENDIF//downIF (Time >= 164500 AND Time <= 173000) AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THENIF Close < (Pivot) THENIF RSI < 85 AND MACD < 2 AND Close < Average[50] AND AroonDown > 5 AND MA20under THENSellShort PositionsizeShort CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFENDIFENDIFIF Opendayofweek = 5 AND (Time >= 175000 AND Time <= 184500) AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THENIF Close > Pivot AND RSI < 25 AND MACD < -2 AND Close < Average[20] AND Close < Average[50] AND AroonDown > 5 AND Close < Average[100] THENSellShort PositionsizeShort CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFENDIFIF (Time >= 180000 AND Time <= 190000) AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THENIF Close > Pivot AND NOT ReachedXetra AND RSI < 75 AND MACD < 2 AND Close < Average[50] AND AroonDown > 5 AND MA20under AND Average[100] < Average[200] THENSellShort PositionsizeShort CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFENDIFIF Time >= 180000 AND Time <= 200000 AND TradeDay AND TRADEON AND (hi - lo) > AmplitudeMin AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THENIF Close > (Pivot) THENIF RSI < 75 AND MACD < 2 AND Close < Average[100] AND Average[100] < Average[200] AND Average[100] > Average[1000]+25 AND Average[1000] > Average[2500] AND AroonDown > 0 AND MA20under THENSellshort PositionsizeShort CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFENDIFENDIFIF Time >= 190000 AND Time <= 215900 AND TradeDay AND TRADEON THENIF Close > ResR1 AND NOT ONMARKET AND NOT ForbiddenShort AND Close <= lo THENIF RSI < 75 AND MACD < 2 AND Close < Average[10] AND Average[10] < Average[30] AND Average[100] < Average[200] AND Average[200] > Average[1000] AND MA30under AND AroonDown > 0 THENSellshort PositionsizeShort CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFELSIF Close < SupS1 AND NOT ONMARKET AND NOT ForbiddenLong AND Close >= hi THENIF RSI > 25 AND MACD > -2 AND Close > Average[10] AND Average[10] < Average[30] AND MA30over AND Average[100] > Average[200] AND Average[200] < Average[1000] AND AroonUp > 0 THENBuy PositionsizeLong CONTRACTS AT MARKETSET STOP pLOSS 60*Faktor1ENDIFENDIFENDIF// JahresendRallyeIF Time >= 143000 AND Time <= 171500 AND Close > Average[10000] AND Tradeday AND TradeON AND NOT ForbiddenLong AND NOT Trenddown AND NOT ONMARKET AND Close > Close[1] AND RSI > 25 AND RSI < 85 AND Close > Average[10] AND Average[20] > Average[30] AND AroonUp > 5 AND Close = Highest[60] AND Close < ResR3 AND (Close MOD 100) > 20 AND MACDLine < 10 AND Close > Average[1000] THENBUY PositionSizeLong CONTRACTS AT MARKETSET STOP pTrailing 100*Faktor1ENDIF// NachmittagsanstiegIF Time >= 143000 AND Time <= 200000 AND NOT Reachedboth AND Tradeday AND TradeON AND NOT ForbiddenLong AND Trendup AND CurrentMonth < 10 AND NOT ONMARKET AND Close > Close[1] AND RSI > 25 AND RSI < 85 AND Close > Average[10] AND Average[20] > Average[30] AND AroonUp > 5 AND Close = Highest[60] AND (Close MOD 100) > 20 AND MACDLine < 10 AND Close > Average[1000] THENBUY PositionSizeLong CONTRACTS AT MARKETSET STOP pTrailing 100*Faktor1ENDIF4 users thanked author for this post.
12/14/2022 at 8:12 AM #205730Wow!
2 users thanked author for this post.
12/14/2022 at 11:13 AM #205740Super…Haben Sie etwas doc darüber?
1 user thanked author for this post.
12/14/2022 at 11:16 AM #205741Jein. Der Code ist Stück für Stück aus Recherche im Forum (Codeschnipsel für Trailing-Stops, MA-Filter etc) gewachsen und bei neuen Erkenntnissen erweitert worden.
Er ist recht modular gehalten und kann mit den Flags am Anfang des Codes zB auf einen gewünschten Zielmarkt gestellt und mit gewünschten Parametern gefüttert werden.
Die einzige Dokumentation dazu ist in den Kommentarzeilen im Code selbst.1 user thanked author for this post.
12/15/2022 at 10:08 AM #205784Moin, da hast du dir super viel Mühe gemacht. Kannst du in wenigen Worten zusammen fassen was der Code genau machen soll?
2 users thanked author for this post.
12/15/2022 at 11:27 AM #205795Danke, dass du deinen Job teilst Stefan Sticker 🙂
Es wird für viele Leute interessant sein!
1 user thanked author for this post.
12/15/2022 at 11:58 AM #205811Der Code besteht aus mehreren Modulen, die im Kopf aktiviert/deaktiviert/eingestellt werden können.
Ziel war es, ein modulares, auf unterschiedliche Märkte anpassbares System aus den (meiner Meinung nach) besten Bestandteilen an nützlichen Codesnippets des Forums zusammenzustellen.
er enthält
– einen Header mit den wichtigsten Parametern zu den weiteren Modulen
– eine verbesserte Variante eines Seasonality-Codes (vorbereitet für DJI und DAX) inklusive Jahres-/Monats-/Wochentags/Trend-Anpassung
– einen Strategy-Stop- und Money-Management-Code, der Verluste eindämmt
– einen Robustness-Test-Code für Testzwecke im Backtest
– einen anpassbaren Trailing-Stop-Code mit verschiedenen Parametern
– einen Hexensabbat-Filter, der den Handel an Hexensabbat-Tagen verhindert
– Einen Code, der täglich die Werte für Day-High/Low/Close, XetraClose und letztes offenes XetraClose (XetraCloseOld), Pivot/R1/R2/R3/S1/S2/S3 ermittelt (kann dann im Handelscode verwendet werden)
– ein Code, der anhand der Vortages-Closes einen TrendUp oder Trenddown als Flag ausgibt
– einen Moving-Average-Cluster-FilterCode, der bei Clusterbildung von MAs den Handel verbietet
– einen Code, der Moving-Average-Crossing in Flags ausgibt (nutzbar im Handelscode)
– einen Long/Short-S2/R2-Break-Filter, der den Handel bei Bruch von S2/R2 verbietet oder alternativ erst dann in Gegenrichtung erlaubtnach dem Trailing-Stop-Code folgt der eigentliche Handelscode, der natürlich individuell ausfallen kann.
Die Module können wie schon geschrieben einzeln an/ausgeschaltet werden, so daß der Hauptblock (ohne den Handelscode) praktisch nur kopiert werden muss, dann entsprechend eingestellt auf den Markt, in dem man den (darauf programmierten) Handelscode laufen lassen möchte.
Man muss nicht jedes mal für jeden Markt das Rad neu erfinden, sondern hat die wichtigsten/nützlichsten Codes IMMER direkt am Start bei der Entwicklung.1 user thanked author for this post.
12/15/2022 at 2:44 PM #205816Hier steckt verdammt viel Arbeit drin. Und wie ist die Leistung? Hast du Backtestergebnisse? Für meinen Geschmack sind das sehr viele Filter.
1 user thanked author for this post.
12/15/2022 at 3:31 PM #205818Ja, da ist insgesamt etwas mehr als 1 Jahr Recherche, Backtest, Umprogrammierung und Optimierung hineingeflossen. ^^
Ich habe Backtestergebnisse seit Februar 2022.
Mein ursprüngliches Mindestziel waren 60% Gewinntrades bei (optimal) Faktor 2/1 Gewinn/Verlust.
Aktuell habe ich konstante 90-95% Gewinn bei Faktor 3-4/1 (je nachdem, ob zB Seasonality-Modifier und/oder Reinvestition von Gewinnen aktiviert werden.
90% hält er sowohl im Rallye-Phasen wie auch im Bärenmarkt.Die Filter im Handelscode sind von mir Stück für Stück bewusst inkludiert, da ein Buy oder Sell nur unter bestimmten Bedingungen stattfinden soll.
Bei 220-240 Trades im Backtest (200.000 Einheiten im Minutenchart) habe ich seitdem so etwa 10-15 Verlusttrades.
Realchart-Läufe sind nicht exakt identisch. Die Ausführung der Orders erfolgt wohl etwas zeitverzögert und verändert dadurch die Ergebnisse.
Auch ist mir aufgefallen, daß Realtrades häufiger in den StopLoss laufen, als im Backtest (Stichwort Spikes/Slipping!).
Ebenfalls kritisch ist zu bemerken, daß ich noch keine sinnvollen Filter für zB Spikes/Downer in hochvolatilem Umfeld (wie aktuell im DJI + DAX zB dank FED/EZB finden konnte.
Ich schätze daher die echte Real-Performance deutlich niedriger und VIELLEICHT so etwa an meiner Zielmarke von 60% / 1,5.12/15/2022 at 9:08 PM #205843Addendum:
die 220-240 Trades beziehen sich jeweils auf den Backtest-Zeitraum von 200.000 Ticks/Minuten (ca 5,5 Monate).
12/15/2022 at 9:24 PM #205846Eine kleine aktuelle Code-Ergänzung im Handelscode:
IF ((TIME >= 092000) AND (TIME <= 100000)) AND TradeON AND TradeDay THEN IF NOT Forbiddenshort AND NOT OnMarket AND Aroondown > 10 AND RSI < 70 AND MACD < 0 AND Close < Average[100] AND Close < Average[50] AND Average[50] < Average[100] AND Average[100] < Average[200] AND Close < Average[10000] AND Close = Lowest[90] THEN
Sellshort PositionSizeShort Contracts AT MARKET
SET STOP pTrailing 100*Faktor1
ENDIF
IF Not Forbiddenlong AND NOT Onmarket AND Aroonup > 10 AND RSI > 25 AND MACD > 0 AND Close > Average[100] AND Close > Average[50] AND Average[50] > Average[200] AND Average[100] > Average[200] AND Close > Average[10000] AND Close = Highest[90] THEN
Buy PositionSizeLong Contracts AT MARKET
SET STOP pTrailing 100*Faktor1
ENDIF
ENDIFDie Ergebnisse im Backtest bei 200.000 Ticks im 1m DAX sind dem angehängten Bild zu entnehmen.
12/16/2022 at 12:23 AM #205851Hast du auch eine Kurve dazu? Mir scheint, der SL ist riesig.
1 user thanked author for this post.
12/16/2022 at 7:25 AM #205856Bitteschön.
Die SL sind vergleichweise weit gewählt und im Trailing-Stop-Code eine Breakeven-Sicherung eingebaut, da der Broker IG, über den ich “fahre” ERKENNBAR UND DEFINITIV versucht, zu eng gesetzte Stops abzufischen. Teilweise absurd starke abrupte Spikes in die Gegenrichtung einer starken Bewegung GENAU IM MOMENT der Plazierung. Ein weiter entfernter Stop macht ihn etwas unerreichbarer (weil dann ja der restliche Markt seinen “Willen” hat!!) und sorgt dafür, daß NUR DIE wirklich ins Minus laufen, die auch wirklich “schlecht” sind. Im Gegenzug ist dieses Minus halt höher, ja.
Ich habe versucht, einen für mich akzeptablen Wert zu finden. Für Dich und Deinen Handelscode kannst Du ja auch andere Stops nehmen.
1 user thanked author for this post.
12/16/2022 at 7:35 AM #205858Hier noch die MAE und MFE-Tabellen
2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on