STOP LOSS LONG E SHORT

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #56177 quote
    traderwintraderwin
    Participant
    Average
    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    
    // Condizioni per entrare su posizioni long
    indicator1 = SuperTrend[3,10]
    c1 = (close[1] CROSSES OVER indicator1)
    
    IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Condizioni per uscire da posizioni long
    indicator2 = SuperTrend[3,10]
    c2 = (close CROSSES UNDER indicator2)
    
    IF c2 THEN
    SELL AT MARKET
    ENDIF
    
    // Condizioni per entrare su posizioni short
    indicator3 = SuperTrend[3,10]
    c3 = (close[1] CROSSES UNDER indicator3)
    
    IF c3 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Condizioni per uscire da posizioni short
    indicator4 = SuperTrend[3,10]
    c4 = (close CROSSES OVER indicator4)
    
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stop e target
    SET STOP pLOSS 50
    SET TARGET PPROFIT 80

    In questo codice di TS, imposto uno stop loss di 50 punti. Come fare a impostare due stop diversi a seconda la posizione?

    Vorrei che se il ts è in posizione long, mi sia impostato uno stop loss di 50 punti e un target di 100, mentre se il ts è short mi sia impostato uno stop loss di 30 punti e target di 70.

    E possibile farlo ? cioe’ impostare stop e target in base la posizione

    #56186 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Sposti SL e TP dove prima sia dell’entrata LONG che SHORT, e modifichi le righe 8 e 24:

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
     
    // Condizioni per entrare su posizioni long
    indicator1 = SuperTrend[3,10]
    c1 = (close[1] CROSSES OVER indicator1)
     
    IF c1 AND Not OnMarket THEN
       // Stop e target
       SET STOP pLOSS 50
       SET TARGET PPROFIT 100
       BUY 1 CONTRACT AT MARKET
    ENDIF
     
    // Condizioni per uscire da posizioni long
    indicator2 = SuperTrend[3,10]
    c2 = (close CROSSES UNDER indicator2)
     
    IF c2 THEN
       SELL AT MARKET
    ENDIF
     
    // Condizioni per entrare su posizioni short
    indicator3 = SuperTrend[3,10]
    c3 = (close[1] CROSSES UNDER indicator3)
     
    IF c3 AND NotOnMarket THEN
       // Stop e target
       SET STOP pLOSS 30
       SET TARGET PPROFIT 70
       SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
     
    // Condizioni per uscire da posizioni short
    indicator4 = SuperTrend[3,10]
    c4 = (close CROSSES OVER indicator4)
     
    IF c4 THEN
       EXITSHORT AT MARKET
    ENDIF

    Roberto

    #56194 quote
    GianlucaGianluca
    Participant
    Master
    IF c1 AND Not OnMarket THEN
       // Stop e target
       SET STOP pLOSS 50
       SET TARGET PPROFIT 100
       BUY 1 CONTRACT AT MARKET
    ENDIF
    Grazie Roberto, un info, se si invertisse l’ordine con:
    IF c1 AND Not OnMarket THEN
       // Stop e target
    “”””””””””””””BUY 1 CONTRACT AT MARKET  
    SET STOP pLOSS 50
       SET TARGET PPROFIT 100
       ENDIF “””””””””””””””””””””””””””
    Cambierebbe qualcosa?
    #56204 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    No, non cambierebbe assolutamente niente!

    #56243 quote
    traderwintraderwin
    Participant
    Average

    Perfetto, funziona alla grande.

    inoltre, senza aprire un’altra discussione vorrei sapere come dire al ts:

    Se apri una posizione e dopo “n” candele non sei in gain, chiudimi la posizione

    #56250 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Questo codice chiuderà ogni operazione aperta se dopo 6 (o qualunque altro numero tu preferisca) candela la posizione risulterà < 0.

    IF (BarIndex - TradeIndex) > 6 AND PositionPerf < 0 AND OnMarket THEN
       SELL AT MARKET
       EXITSHORT AT MARKET
    ENDIF

    Potrebbe succedere che alla sesta barra la posizione sia in profitto e non la chiude, ma alla 9 scende sotto 0 e la chiude!

    #56254 quote
    traderwintraderwin
    Participant
    Average

    Ciao Roberto. quindi se sono long e dopo 100 candele dall’apertura della posizione, la posizione si trova in negativo devo usare questo comando?

    IF longonmarket and (BarIndex - TradeIndex) > 100 AND PositionPerf < 0 AND OnMarket THEN
    SELL AT MARKET

     

     

    e Viceversa per le posizioni short?

    IF shortonmarket and (BarIndex - TradeIndex) > 100 AND PositionPerf > 0 AND OnMarket THEN
    exitshort AT MARKET
    #56290 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Puoi farlo, certo. Il mio esempio serviva sia per i Long che gli Short insieme, ma puoi anche separare le due cose.

    #56315 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Scusami, ma prima ero sul cellulare e non avevo visto bene il tuo codice per gli SHORFT, perché hai scritto

    IF shortonmarket and (BarIndex - TradeIndex) > 100 AND PositionPerf > 0 AND OnMarket THEN

    ?

    Anche per gli SHORT se l’operazione è in perdita PositionPerf è sempre < 0!

Viewing 9 posts - 1 through 9 (of 9 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

STOP LOSS LONG E SHORT


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
traderwin @traderwin Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by robertogozzirobertogozzi
8 years, 9 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 12/20/2017
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...