trailing stop basato su frazioni dell’atr

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

    buongiorno,
    su un sistema che agisce long in breakout ho provato ad adattare una delle versioni di trailing stop presenti sul sito, sfruttando le frazioni dell’atr a 5 periodi daily,
    il sistema entra long su timeframe daily sul massimo del giorno precedente. l’idea è quella di spostare lo stop dopo che il close supera il close del giorno precedente+ i 2/8 dell’atr a 5 periodi con step successivi di 1/8.
    lo schema sarebbe il seguente:
    buy sul massimo del giorno precedente a quello corrente
    quando il prezzo raggiunge il close del giorno prima +2/8 dell’atr si sposta lo stop sul close del giorno prima (stop in pari)
    successivamente quando il prezzo supera il successivo ottavo anche lo stop incrementa di 1/8
    potreste dirmi se il codice è corretto?

    //trailing stop function
    myatr=AverageTrueRange[5](close)
    myatrstep= myatr/8
    
    
    trailingstartL = Dclose(0) + 2*(myatrstep)
    trailingstep    = myatrstep //trailing step to move the "stoploss"
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>= tradeprice(1)+ trailingstartL THEN
    newSL = tradeprice(1)// DCLOSE(0)
    ENDIF
    //next moves
    IF newSL>0 AND close>trailingstartL+trailingstep THEN
    newSL = newSL+trailingstep
    ENDIF
    ENDIF
    
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    #187273 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    La riga 21 dovrebbe essere così (non l’ho provato):

    IF newSL>0 AND close>newSL+trailingstep THEN
    #187280 quote
    KAMJKAZEKAMJKAZE
    Participant
    Junior

    grazie mille!!!
    sempre preciso roberto!

    #187361 quote
    elfuego77elfuego77
    Participant
    Junior

    Per utilizzare lo stesso criterio sullo short, è corretto il così il codice? Grazie!!

    //manage short positions
    IF SHORTONMARKET then
    //first move breakeven
    IF newSL=0 And close-tradeprice(1)<=tradeprice(1)+trailingstartS then
    newSL = tradeprice (1) // DCLOSE(0)
    endif
    //next moves
    IF newSL>0 and close<newsl+trailingstep then
    newsl=newsl-trailingstep
    endif
    endif
    
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    ENDIF
    #187366 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Non esattamente, basta usare il meno al posto del più:

    IF newSL>0 and close<newsl-trailingstep then

    🙂

    #187367 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Anche la riga 4 va cambiata:

    IF newSL=0 And close<=tradeprice(1)-trailingstartS then

    Però, guardando bene, anche la riga 17 del primo post va cambiata:

    IF newSL=0 AND close>= tradeprice(1)+ trailingstartL THEN
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

trailing stop basato su frazioni dell’atr


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
KAMJKAZE @kamjkaze Participant
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 02/01/2022
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...