sistema stop&reverce che non funziona

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #209471 quote
    KAMJKAZEKAMJKAZE
    Participant
    Junior

    salve a tutti,

    da qualche tempo sto studiando dei sistemi di stop and reverce, che alcune volte funzionano ed altre no…

    questo è il caso del sistema in questione

    ho provato diverse possibilità di scrittura ma non ne sono venuto a capo.

    il sistema è multitimeframe:

    
    
    TIMEFRAME (4H,UPDATEONCLOSE)
    
    
    
    RSI14LONG= RSI[14](close)>=50
    CCILONG= CCI[20](typicalPrice)>=0
    MEDIA20EXPO= CLOSE CROSSES OVER ExponentialAverage[20](close)
    
    IF RSI14LONG AND CCILONG AND MEDIA20EXPO AND REVERCE=0 THEN
    BUY 1 CONTRACT AT MARKET
    STOPPE=(LOWEST[2](LOW))
    ENDIF
    
    TIMEFRAME (15MN,DEFAULT)
    
    
    IF LONGONMARKET AND REVERCE=0 THEN
    SET TARGET %PROFIT 2
    SELL AT STOPPE STOP
    reverce=0
    ENDIF
    
    
    //trailingstop
    
    // NewTrade is true whenever a new trade is opened, be it:
    //
    //   - a trade when there was none previously
    //   - a trade that has changed direction due to a Stop & Reverse (it's Long and previously was Short and viceversa)
    //
    // This will be useful to reset variables to their initial values after a trade has been opened.
    //
    NewTrade         = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket)
    //
    // Reset variables to their initial value when a new trade shows
    //
    IF Not OnMarket and reverce=0 OR NewTrade and reverce=0 THEN //reset to default values when a new trade has been opened (or none is OnMarket)
    PerCentTP     = 1.0           //2.0%  is TP
    PerCentStart  = x           //0.2%  is the Trailing Stop trigger level
    PerCentStep   = y           //0.2%  is each subsequent step
    PerCentSaved  = z           //0.1%  is how much profit has to be saved when trailing starts and every step
    Multiplier    = M           //1.5   is how much PerCentSaved is incremented each trailing step
    //                                    1.5 is a 50% increment, so that:
    //                                         0.1%   becomes 0.15%,   then
    //                                         0.15%  becomes 0.225%,  then
    //                                         0.225% becomes 0.3375%, etc...
    Distance      = 6             //6     pip distance from current price (if required by the broker)
    MySL          = 0
    ProfitPerCent = 0
    ENDIF
    //
    // The trailing stop can operate only when OnMarket
    //
    IF OnMarket AND REVERCE=0 THEN
    //
    // before the trailing stop is triggered some calculations need to be done, accordin to settings
    //
    IF MySL = 0 THEN
    PCent      = PositionPrice * PerCentTP    / 100
    PStart     = PositionPrice * PerCentStart / 100
    PStep      = PositionPrice * PerCentStep  / 100
    PSaved     = PositionPrice * PerCentSaved / 100
    ENDIF
    //
    // check if Trailing Stop has to be triggered
    //
    IF MySL = 0 THEN
    IF LongOnMarket THEN
    IF (close - PositionPrice) >= PStart THEN
    MySL   = min(close,PositionPrice + PSaved)
    PSaved = PSaved * Multiplier
    ENDIF
    ELSIF ShortOnMarket THEN
    IF (PositionPrice - close) >= PStart THEN
    MySL   = max(close,PositionPrice - PSaved)
    PSaved = PSaved * Multiplier
    ENDIF
    ENDIF
    ELSE
    //
    // check if another Step has been triggered
    //
    IF LongOnMarket THEN
    IF (close - MySL) >= PStep THEN
    MySL   = min(close,MySL + PSaved)
    PSaved = PSaved * Multiplier
    ENDIF
    ELSIF ShortOnMarket THEN
    IF (MySL - close) >= PStep THEN
    MySL   = max(close,MySL - PSaved)
    PSaved = PSaved * Multiplier
    ENDIF
    ENDIF
    ENDIF
    //
    // place Pending STOP orders
    //
    IF MySL > 0 and reverce=0 THEN
    IF (MySL = close) OR (abs(MySL - close) < Distance) THEN //exit immediately in case MySL has reached
    //                                                      the current price or there's not enough DISTANCE
    SELL      AT MARKET
    EXITSHORT AT MARKET
    ELSE
    SELL      AT MySL STOP
    EXITSHORT AT MySL STOP
    ENDIF
    ENDIF
    ENDIF
    
    
    //reverceside
    
    IF NOT ONMARKET THEN
    reverce=0
    ENDIF
    
    
    IF LONGONMARKET and POSITIONPERF<0 and CLOSE CROSSES UNDER DonchianChannelDown[10] THEN
    SELL AT MARKET
    REVERCE= 1
    ENDIF
    
    IF longonmarket[1]  AND REVERCE=1  THEN
    SELLSHORT 1 CONTRACT AT MARKET
    STOPPEREVERCE= HIGHEST[1] (HIGH)
    TARGETREVERCE= CLOSE-((HIGHEST[1](HIGH)- CLOSE))
    reverce=1
    ENDIF
    
    IF SHORTONMARKET and reverce=1  THEN
    EXITSHORT AT STOPPEREVERCE STOP
    EXITSHORT AT TARGETREVERCE stop
    ENDIF
    
    if shortonmarket[1] or not onmarket then
    reverce=0
    endif
    
    GRAPHONPRICE TARGETREVERCE
    GRAPHONPRICE STOPPEREVERCE
    GRAPH REVERCE
    

     

    il primo ingresso è solo long, la condizione principale è sulle 4h, l’entry e il trailing stop a 15 minuti

    il reverce entra in funzione nella condizione in cui il close cross under il canale di donchian a 10 periodi.

    vi allego il sistema è uno screeshot del problema.

    immagine-sistema-2.png immagine-sistema-2.png Immagine-sistema-1.png Immagine-sistema-1.png
    #209502 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Le righe 123-128 toglile e scrivi queste al  posto delle righe 119-120:

    SELLSHORT 1 CONTRACT AT MARKET
    STOPPEREVERCE= HIGHEST[1] (HIGH)
    TARGETREVERCE= CLOSE-((HIGHEST[1](HIGH)- CLOSE))
    #209503 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Però c’è un altro errore logico, TARGETREVERCE e STOPPEREVERCE non possono essere piazzati entrambi come ordini pendenti dello stesso tipo, se uno è STOP l’altro dovrebbe essere LIMIT.

    #209516 quote
    KAMJKAZEKAMJKAZE
    Participant
    Junior

    ciao roberto,

    intanto grazie,

    alcune cose che non ho capito:

    1: io per indicare il trade principale e il reverce utilizzo una variabile (reverce=0/1) , serve o non serve in questo sistema in  particolare o in generale?

    2: quindi posso entrare in una posizione short senza chiudere una posizione long in essere? in quel caso viene eseguita subito o alla prossima barra?

    3 : le righe  130-133 io ho provato tutte le combinazioni sia con ordini pendenti stop/limit; limit/stop ecc eppure mi da backtest mi salta lo stop o il target o entrambi.

    non ne cavo un ragno dal buco…

    #209522 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    1. Non serve, ma se ti serve per SL e TP degli Short, lascialo:

    2. quando entri Long prima chiude eventuali operazioni Short aperte, poi apre la nuova operazione Long. L’opposto per lo Short;

    3. STOP si usa quando il prezzo di uscita è peggiorativo rispetto all’attuale (ad esempio SL), mentre LIMIT si usa quando è migliorativo (ad esempio TP).

    Esempio di entrata SENZA Stop & Reverse:

    If Not OnMarket then
       If CondizioniLong then
          Buy at Market
       ElsIf CondizioniShort then
          SellShort at Market
       Endif
    Endif

    Esempio di entrata CON Stop & Reverse:

    If Not LongOnMarket  and CondizioniLong then
          Buy at Market
    ElsIf Not ShortOnMarket  and  CondizioniShort then
       SellShort at Market
    Endif
    #209683 quote
    KAMJKAZEKAMJKAZE
    Participant
    Junior

    risolto

    grazie mille 😀

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

sistema stop&reverce che non funziona


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
KAMJKAZE @kamjkaze Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by KAMJKAZEKAMJKAZE
3 years, 7 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 02/10/2023
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...