Spostamento Stop Lost

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #136200 quote
    Giovanni Belli
    Participant
    Average

    Buonasera, non riesco a programmare un’aggiunta al codice originale che vedrebbe spostare lo stop lost al raggiungimento di un prezzo pivot.

    Mi spiego meglio prendendo ad esempio un entrata long. Quando si riscontrano tutte le casistiche lui entra long e imposta TP e SL.

    Mi piacerebbe che qualora il prezzo raggiungesse un prezzo che ho chiamato PIVOTLONG , potesse spostare il livello di Stop Lost.

    Allego il codice in questione.

    Grazie mille x il supporto

    //-------------------------------------------------------------------------
    // Codice principale : Price action rev3
    //-------------------------------------------------------------------------
    DEFPARAM CumulateOrders = false
    DEFPARAM FLATBEFORE = 070000
    DEFPARAM FLATAFTER = 220000
    //
    TIMEFRAME(default)
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0 //or OpenDayOfWeek = 1
    c1 = not daysForbiddenEntry
    c2 = time >= 070000 AND time <= 190000
    //
    TIMEFRAME(1 Day,UpdateOnClose)
    Level75 = low + (range * 0.65)
    Level25 = low + (range * 0.35)
    Bullish = (close > open) AND close > Level75
    Bearish = (close < open) AND close < level25
    PrezzoLong = high
    PrezzoShort = low
    Tp = abs(close - open) * 0.7
    pivotlong=prezzoLong + ((tp * 0.5)* pointsize)
    pivotshort=prezzoshort - ((tp * 0.5)* pointsize)
    
    //SlLong = high - close
    //SlShort = close - low
    //
    TIMEFRAME(5 minute,UpdateOnClose)
    
    IF intradaybarindex = 0 then
    countposition=0
    endif
    
    count=countposition < 1
    
    
    
    
    
    // Long
    
    if longonmarket and close crosses over pivotlong then
    set stop loss prezzolong
    else
    iF c1 AND c2 AND Bullish and count AND close crosses over PrezzoLong AND Not Onmarket THEN
    BUY 1 CONTRACT AT MARKET
    SET TARGET PROFIT Tp
    //SET STOP pLOSS 60 //Sllong
    countposition=countposition + 1
    ENDIF
    endif
     
    
    // Short
    
    if SHORTONMARKET and close crosses under pivotshort then
    set stop loss prezzoshort
    else
    IF c1 AND c2 AND Bearish and count AND close crosses under PrezzoShort AND Not Onmarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    SET TARGET PROFIT Tp
    //SET STOP pLOSS 60 //SlShort
    countposition=countposition + 1
    ENDIF
    endif
    #136201 quote
    robertogozzi
    Moderator
    Master

    Aggiungi in fondo al codice:

    GRAPH PrezzoLong
    GRAPH PrezzoShort
    GRAPH pivotlong
    GRAPH pivotshort

    e potrai vedere, nel riquadro delle variabile del backtest, i valori che hanno candela per candela.

    Tieni presnte che set stop loss vuole una differenza di prezzo.

    #136207 quote
    Giovanni Belli
    Participant
    Average

    Risolto grazie mille Roberto!

    #136209 quote
    robertogozzi
    Moderator
    Master

    Mi fa molto piacere che tu l’abbia risolto, non solo col mio aiuto, ma col tuo impegno e passione.

    Ti ho dato uno spunto, piuttosto che scriverti io il codice, un pò per il tempo (lo ammetto), ma principalmente perché preferisco in genere insegnare a pescare piuttosto che fornire il pesce già pronto!

    #136213 quote
    Giovanni Belli
    Participant
    Average

    In effetti poter vedere cosa gli facevo leggere al programma è stata la soluzione. Ma poi sono arrivato alla conclusione che quando volevo spostare lo stop lost a livello di entrata, mi bastava inserire SET STOP LOSS 0.0001

    non serviva la differenza ma bisognava sempre partire dal punto di entrata.

    Scriverlo magari può aiutare nel caso qualcuno leggesse questo post

    alla prossima..

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

Spostamento Stop Lost


ProOrder: Trading Automatico & Backtesting

New Reply
Author
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Giovanni Belli
5 years, 9 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 06/16/2020
Status: Active
Attachments: No files
Logo Logo
Loading...