Aggiunta condizione di uscita in un codice

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #220558 quote
    Ciccarelli Franco
    Participant
    Junior

    Potrebbe aver senso mettere una condizione di uscita in questo semplice codice (Allegato)? E se si quale potrebbe essere?

    Grazie

    #220571 quote
    robertogozzi
    Moderator
    Master

    Per favore posta sempre anche il codice, a meno che non sia varie centinaia di righe. Grazie 🙂

    Ecco il tuo codice a cui ho aggiunto l’uscita quando avviene l’incrocio contrario tra il volume e la sua media (purché sia in profitto in quel momento):

    DEFPARAM CumulateOrders = FALSE
    ONCE l   = 2
    ONCE p   = 4
    ONCE tra = 25
    TradingTime=Time>=090000and Time<=210000
    // LONG
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c1 = (indicator1 >= indicator2)
    c2 = (indicator1 CROSSES UNDER indicator2)
    IF ( close > open and close[1] > open[1]  ) and c1 and TradingTime  and Not LongOnMarket Then
    BUY 1 CONTRACTS AT MARKET
    SET STOP   LOSS   l*AverageTrueRange[10](close)
    SET TARGET PROFIT p*AverageTrueRange[12](close)
    ENDIF
    IF LongOnMarket AND c2 AND PositionPerf > 0 THEN
    SELL AT MARKET
    ENDIF
    //trailing stop
    trailingstop = tra
     //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    MINPRICE = close
    priceexit = 0
    endif
     //case SHORT order
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    endif
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Aggiunta condizione di uscita in un codice


ProOrder: Trading Automatico & Backtesting

New Reply
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
2 years, 5 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 09/08/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...