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

Viewing 15 posts - 1 through 15 (of 36 total)
  • #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 = 0

    ONCE 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-Multiplikator

    IF 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
    ENDIF

    IF 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
    ENDIF

    IF 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 = 1

    IF 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
    endif

    if 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 = 0

    IF 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 = 0

    IF 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 = 14423

    ONCE ReachedXetra = 1
    ONCE ReachedDayClose = 1
    ONCE Reachedboth = 1
    ONCE ClosetryCount = 0

    IF Time = 060000 THEN
    ReachedXetra = 0
    ReachedDayClose = 0
    Reachedboth = 0
    ClosetryCount = 0
    ENDIF

    IF 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
    ENDIF

    Overboth = (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]
    ENDIF

    IF 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])
    ENDIF

    if 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 = 0

    IF 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 = 0

    IF 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
    ENDIF

    IF ((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
    ENDIF

    IF ((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
    ENDIF

    IF ((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
    ENDIF

    IF (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
    ENDIF

    IF 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
    ENDIF

    IF 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
    ENDIF

    IF (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
    ENDIF

    IF 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
    ENDIF

    IF 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
    ENDIF

    3 users thanked author for this post.
    #205729
    4 users thanked author for this post.
    #205730

    Wow!

    2 users thanked author for this post.
    #205740

    Super…Haben Sie etwas doc darüber?

    1 user thanked author for this post.
    #205741

    Jein. 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.
    #205784

    Moin, 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.
    #205795

    Danke, dass du deinen Job teilst Stefan Sticker 🙂

    Es wird für viele Leute interessant sein!

     

    1 user thanked author for this post.
    #205811

    Der 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 erlaubt

    nach 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.
    #205816

    Hier 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.
    #205818

    Ja, 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.

    #205843

    Addendum:

    die 220-240 Trades beziehen sich jeweils auf den Backtest-Zeitraum von 200.000 Ticks/Minuten (ca 5,5 Monate).

    #205846

    Eine 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
    ENDIF

    Die Ergebnisse im Backtest bei 200.000 Ticks im 1m DAX sind dem angehängten Bild zu entnehmen.

    #205851

    Hast du auch eine Kurve dazu? Mir scheint, der SL ist riesig.

    1 user thanked author for this post.
    #205856

    Bitteschö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.
    #205858

    Hier noch die MAE und MFE-Tabellen

    2 users thanked author for this post.
Viewing 15 posts - 1 through 15 (of 36 total)

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