Quit – Routine

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #187275 quote
    akira1988
    Participant
    Average

    Hallo,
    ich würde gerne eine Quit-Routine codieren welche ein Handelssystem stoppt , wenn der aktuelle Profit eines Handelssystems (inklusive des negativen Profits der aktuell offenen Position) unter einen festgelegten Prozentsatz des bis dahin maximal erwirtschafteten Gewinns eines Handelssystems fällt. Ich habe mich selbst schon daran versucht, aber mit meinem Code stimmt irgendetwas nicht, das Handelssystem wird nicht nach den festgelegten Prozentwerten angehalten. Es wäre nett wenn sich jemand den Code mal anschauen würde.

    //_______________________________________________________________________Quit-Strategy
    
    //_______________________________________________________________________DAX-Spread
    if opentime>=011500 and opentime<080000 then
    SPREAD=4
    elsif opentime>=080000 and opentime<085900 then
    SPREAD=2
    elsif opentime>=090000 and opentime<=173000 then
    SPREAD=1.2
    elsif opentime>173000 and opentime<=220000 then
    SPREAD=2
    elsif opentime>220000 and opentime<011500 then
    SPREAD=5
    endif
    
    
    //___________________________________________
    if not onmarket then
    setENTRY=0
    endif
    
    //___________________________________________LONG
    if longonmarket then
    if not setENTRY then
    ENTRY=tradeprice+SPREAD
    setENTRY=1
    endif
    //___________________________________________positionPROFIT (negative)
    if setENTRY and close<ENTRY then
    positionPROFIT=(ENTRY-close)*abs(countofposition)
    endif
    endif
    
    
    
    //___________________________________________SHORT
    if shortonmarket then
    if not setENTRY then
    ENTRY=tradeprice-SPREAD
    setENTRY=1
    endif
    //___________________________________________positionPROFIT (negative)
    if setENTRY and close>ENTRY then
    positionPROFIT=(close-ENTRY)*abs(countofposition)
    endif
    endif
    
    
    //______________________________________________QUIT
    once maxPROFIT=0
    maxPROFIT=max(strategyprofit,maxPROFIT)
    
    if (strategyprofit-positionPROFIT)<=-250 then
    quit
    endif
    
    if maxPROFIT>500 and maxPROFIT<=2500 then
    if (strategyprofit-positionPROFIT)<maxPROFIT*0.5 then
    quit
    endif
    endif
    
    if maxPROFIT>2500 and maxPROFIT<=10000 then
    if (strategyprofit-positionPROFIT)<maxPROFIT*0.6 then
    quit
    endif
    endif
    
    if maxPROFIT>10000 then
    if (strategyprofit-positionPROFIT)<maxPROFIT*0.7 then
    quit
    endif
    endif
    
    #187283 quote
    Stefan Sticker
    Participant
    New

    Wenn ich es richtig verstehe, dann ist im Verlustfall Dein positionPROFIT natürlich negativ.
    (strategyprofit-positionPROFIT) ist daher gleichbedeutend mit strategyprofit minus minus xxxx,-€.
    minus*minus gibt PLUS, ergo rechnest Du: wenn strategyprofit PLUS Verlustbetrag <= soundsoviel ist, dann… was natürlich zu keinem Zeitpunkt erreicht werden kann.
    Je mehr Verlust Du machst, desto größer wird ja der Betrag. 😉

    #187284 quote
    Stefan Sticker
    Participant
    New

    Mathematisch richtiger wäre es, die Faktoren schlicht in der Reichenfolge zu tauschen: “positionPROFIT + strategyprofit”. Dann sollte das funktionieren.

    #187312 quote
    akira1988
    Participant
    Average

    Danke für die schnelle Hilfe, ich sollte wohl nochmal die Grundrechenarten durchgehen 😁. Ich habe jetzt mal einen Backtest mit der von Dir vorgeschlagenen Änderung vorgenommen. Leider funktioniert die geänderte Version nur mit einiger Verzögerung, wenn das Handelssystem z.B. bei 70% des bis dahin erwirtschafteten Maximalgewinns aussteigen soll geschieht das erst bei rund 40% – 50% des Maximalgewinns. Ist das einfach nur ein Fehler im Backtest oder stimmt noch etwas anderes nicht an meinem Code?

    #187313 quote
    Stefan Sticker
    Participant
    New

    Das ist jetzt etwas schwieriger zu beantworten.
    Ich könnte mir vorstellen, daß es etwas mit Deinem STOP-Code und ggf Slippage zu tun hat.
    Ein Beispiel: Dein Profit steigt auf über 10.000,-€ und damit in die 3. Stufe Deiner Tabelle.
    Er soll aussteigen sobald der Profit unter 7.000,-€ fällt
    Nun kommen die nächsten Trades… Er fällt auf zB 7.050,- €
    Noch ein Trade… ZACK! 6.700,- € (Du hast vielleicht hohe TRAILING-STOP-Werte und die Volatilität (Bewegung im Markt) ist hoch !?
    Dann löst er halt entsprechend nicht bei exakt 70% aus.
    Grundsätzlich lösen Deine Quit-Funktionen halt immer NACH (!!) Unterschreiten aus.

    akira1988 thanked this post
    #187314 quote
    robertogozzi
    Moderator
    Master

    Hier ein Beispiel (nur SHORT, auf Dax 5 €, h1):

    ONCE PerCentage = 20
    ONCE MaxProfit  = 0
    CurrentProfit   = PositionPrice * PositionPerf / PipSize * PipValue
    TotalProfit     = StrategyProfit + CurrentProfit
    MaxProfit       = max(MaxProfit,TotalProfit)
    IF close crosses under average[200] then
        sellshort at market
    endif
    if close crosses over average[200] and (barindex - tradeindex > 5) then
        exitshort at market
    endif
    IF (StrategyProfit > 0) AND (TotalProfit <= (MaxProfit - (MaxProfit * Percentage / 100))) THEN
        QUIT
    ENDIF
    graph CurrentProfit
    graph StrategyProfit
    graph TotalProfit
    Stefan Sticker and akira1988 thanked this post
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Quit – Routine


ProOrder: Automatischer Handel & Backtesting

New Reply
Author
author-avatar
akira1988 @akira1988 Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by robertogozzi
4 years ago.

Topic Details
Forum: ProOrder: Automatischer Handel & Backtesting
Language: German
Started: 02/01/2022
Status: Active
Attachments: No files
Logo Logo
Loading...