Impostazioni di stop e reverse per un solo trade

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #245494 quote
    Superpensionato
    Participant
    New

    Ho impostato una strategia short e vorrei che se il trade va in stop mi faccia lo stop e reverse UNA SOLA VOLTA. Riporto il codice che ho utilizzato. Il problema è che il trade (long) di stop and reverse continua a entrare di nuovo se anche il trade stop&reverse è andato in stop. Come posso fare per fare in modo che faccia SOLO un trade di stop e reverse e non continui a farne altri long indipendentemente dal profitto o stop di quest’ultimo? Grazie

    //strategia short

    if condizioni short then

    sellshort 1 contract at market
    mystop=20

    Myprofit=30
    endif

    Set stop loss mystop
    Set target profit myprofit

    //strategia di stop&reverse

    if strategyprofit<>strategyprofit[1] then
    if positionperf(1)<0 then
    if close>tradeprice(1) then
    gain=-1
    elsif close>tradeprice(1) then
    gain=1
    endif
    else
    gain=0
    endif
    endif

    IF gain=-1 then
    buy 1 contracts at market
    mystopb= 20
    Myprofitb=40

    Set stop loss mystopb
    Set target profit myprofitb
    endif

    #245498 quote
    robertogozzi
    Moderator
    Master

    Prova questo codice:

    ONCE Trade = 0
    //strategia short
    
    if condizionishort then
    sellshort 1 contract at market
    mystop=20
    Myprofit=30
    Trade = -1
    endif
    
    Set stop loss mystop
    Set target profit myprofit
    
    //strategia di stop&reverse
    
    IF Trade = -1 THEN
    if strategyprofit<strategyprofit[1] then
    buy 1 contracts at market
    mystopb= 20
    Myprofitb=40
    Set stop loss mystopb
    Set target profit myprofitb
    Trade = 0
    endif
    endif
    Iván González thanked this post
    #245506 quote
    Superpensionato
    Participant
    New

    Il codice non legge la performance del sistema. Fa alternativamente short e long. Inoltre quando va in stop in base alla prima strategia non rispetta lo stop ma chiude come gli pare, anche in profitto (Nel mio codice era tutto ok con i valori tranne che continuava a fare a ripetizioni long e si fermava solo al primo trade di nuovo in profit)

    #245522 quote
    robertogozzi
    Moderator
    Master

    Prova questa versione. Ho usato la tua ed ho solo inserito un flag per impedire che ci siano più operazioni LONG senza che prima ce ne sia stata una SHORT:

    ONCE StopReverse = 0
    //strategia short
    
    if condizionishort then
    
    sellshort 1 contract at market
    mystop=20
    
    Myprofit=30
    StopReverse = 1
    endif
    
    Set stop loss mystop
    Set target profit myprofit
    
    //strategia di stop&reverse
    
    if strategyprofit<>strategyprofit[1] then
    if positionperf(1)<0 then
    if close>tradeprice(1) then
    gain=-1
    elsif close>tradeprice(1) then
    gain=1
    endif
    else
    gain=0
    endif
    endif
    
    IF gain=-1 then
    IF StopReverse THEN
    buy 1 contracts at market
    mystopb= 20
    Myprofitb=40
    
    Set stop loss mystopb
    Set target profit myprofitb
    StopReverse = 0
    ENDIF
    endif
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Impostazioni di stop e reverse per un solo trade


Trading Generale: Analisi Mercati & Discrezionale

New Reply
Author
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
11 months ago.

Topic Details
Forum: Trading Generale: Analisi Mercati & Discrezionale
Language: Italian
Started: 04/01/2025
Status: Active
Attachments: No files
Logo Logo
Loading...