Conversione della strategia @DP – XAUUSD – Strtg

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #244959 quote
    davide.prini
    Participant
    New

    Chiedo per favore di convertire la mia strategia scritta con Pine Script. Grazie.

    //////////////////////////////INIZIO STRATEGIA “@DP – XAUUSD – Strtg”///////////////////////////////////

    //definizione del range di date entro le quali vengono aperte le nuove transazioni, sia long che short

    yearStart = 2000 //anno di inizio

    monthStart = 01 //mese di inizio

    dayStart = 01 //giorno di inizio

    hourStart = 00 //ora di inizio

    minuteStart = 00 //minuto di inizio

    secondStart = 00 //secondo di inizio

    yearEnd = 2999 //anno di fine

    monthEnd = 12 //mese di fine

    dayEnd = 31 //giorno di fine

    hourEnd = 23 //ora di fine

    minuteEnd = 59 //minuto di fine

    secondEnd = 59 //secondo di fine

    //verifica che la data attuale sia compresa nel range di date definito sopra

    dateRange = ((time >= timestamp(syminfo.timezone, yearStart, monthStart, dayStart, hourStart, minuteStart, secondStart)) and (time <= timestamp(syminfo.timezone, yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd))) //dichiarazione variabili utilizzate per aprire e chiudere le transazioni Var spread = 30 //spread applicato ad ogni transazione (espresso in pip) Var pipXunita = 0.010000 //valore di 1 pip per 1 unità (espresso in $) Var delta_TPSL = spread*pipXunita*100 //valore utilizzato per ottimizzare il calcolo di TP e SL Var delta_Plot = 100 //valore utilizzaro per ottimizzare la stampa di TP e SL Var commissioni = spread*pipXunita/2 //commissione applicata ad ogni transazione per 1 unità (espressa in $) Var mrgXunita = 164.83 //costo della leva per 1 unità (espresso in $) Var unita = 1 //numero di unità acquistate ad ogni transazione Var leva = 10 //leva applicata ad ogni transazione Var capitale = mrgXunita*unita*3 //capitale iniziale (espresso in $) Var float TP = 10000+delta_TPSL //TP espresso in 0,1 pip. Il profitto è pari a circa al 100,00% del capitale investito per aprire una transazione, compresa la leva Var float SL = 1000-delta_TPSL //SL espresso in 0,1 pip. La perdita è pari a circa al 10,00% del capitale investito per aprire una transazione, compresa la leva //dichiarazione strategia: Nome strategia, Mostra sul grafico, Valuta in Dollari, Unità acquistate ad ogni transazione, Capitale iniziale, Commissione applicata per ogni unità acquistata Strategy(“@DP – XAUUSD – Strtg”, overlay = true, currency = “USD”, default_qty_type = strategy.fixed, default_qty_value = unita, initial_capital = capitale, commission_type = strategy.commission.cash_per_contract, commission_value = commissioni) //verifica che non sia già stato modificato lo SL nella precedente candela If SL[1]<(1000-delta_TPSL) TP := TP[1] SL := SL[1] //aumento dello SL se la transazione in corso raggiunge o supera un determinato profitto Var profit_Line1 = 10 Var profit_Line2 = 15 Profit_Line1 := profit_Line1[1] Profit_Line2 := profit_Line2[1] For i = 100 to 10 by 5 If (SL>((i*-100)+500-delta_TPSL) and (strategy.openprofit/unita)>i)

    SL := (i*-100)+500-delta_TPSL

    Profit_Line1 := i+5

    Profit_Line2 := i+10

    If i==95 or i==100

    Profit_Line1 := 100

    Profit_Line2 := 100

    Break

    If SL[1]>SL

    Alert(“XAUUSD – Lo SL è aumentato al +”+str.tostring((SL+delta_TPSL)/100*-1)+”%/+”+str.tostring(((SL+delta_TPSL)/100*-1)*unita)+”€”)

    Strategy.exit(“ExitAcq”, “Acq”, profit = TP, loss = SL, comment_profit = “XAUUSD – Exit Long – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€”, comment_loss = “XAUUSD – Exit Long – SL +”+str.tostring((SL+delta_TPSL)/100*-1)+”%/+”+str.tostring(((SL+delta_TPSL)/100*-1)*unita)+”€”, alert_message = alertcloselong)

    Strategy.exit(“ExitVen”, “Ven”, profit = TP, loss = SL, comment_profit = “XAUUSD – Exit Short – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€”, comment_loss = “XAUUSD – Exit Short – SL +”+str.tostring((SL+delta_TPSL)/100*-1)+”%/+”+str.tostring(((SL+delta_TPSL)/100*-1)*unita)+”€”, alert_message = alertcloseshort)

    //stampa su grafico di Take Profit, Entry Price e Stop Loss

    //verifica se è aperta una transazione in acquisto o in vendita

    Var posizione_Plot = 0

    If (strategy.position_size>0)

    Posizione_Plot := 1

    If (strategy.position_size<0)

    Posizione_Plot := -1

    //stampa su grafico di Take Profit, Entry Price e Stop Loss

    Var Entry_Price = strategy.opentrades.entry_price(0)

    Var color_EP = bar_index % 2 == 0 ? color.green : #00000000

    Entry_Price := strategy.opentrades.entry_price(0)

    Color_EP := bar_index % 2 == 0 ? color.green : #00000000

    Plot((strategy.opentrades.entry_price(0)+(TP/delta_Plot*posizione_Plot)), title = “TP”, color = color.green, linewidth = 2, style = plot.style_linebr)

    Plot((Entry_Price), title = “EP”, color = color_EP, linewidth = 1, style = plot.style_linebr)

    Plot((strategy.opentrades.entry_price(0)-(SL/delta_Plot*posizione_Plot)), title = “SL”, color = color.gray, linewidth = 2, style = plot.style_linebr)

    //stampa su grafico dell’area nella quale, se una candela “passa” al suo interno, viene aumentato lo SL

    Var Profit_1 = (strategy.opentrades.entry_price(0)+(profit_Line1*posizione_Plot/delta_Plot*100))

    Var color_P1 = color.green

    Var Profit_2 = (strategy.opentrades.entry_price(0)+(profit_Line2*posizione_Plot/delta_Plot*100))

    Var color_P2 = color.green

    Var color_Fill_Area = color.rgb(191, 244, 193)

    Profit_1 := (strategy.opentrades.entry_price(0)+(profit_Line1*posizione_Plot/delta_Plot*100))

    Color_P1 := color.green

    Profit_2 := (strategy.opentrades.entry_price(0)+(profit_Line2*posizione_Plot/delta_Plot*100))

    Color_P2 := color.green

    Color_Fill_Area := color.rgb(191, 244, 193)

    Fill_1 = plot((Profit_1), title = “P1”, color = color_P1, linewidth = 1, style = plot.style_linebr)

    Fill_2 = plot((Profit_2), title = “P2”, color = color_P2, linewidth = 1, style = plot.style_linebr)

    Fill(Fill_1, Fill_2, color = color_Fill_Area)

    //calcolo degli indicatori

    Ema = ta.ema(close, 21)

    [middleBand, upperBand, lowerBand] = ta.bb(close, 20, 2)

    highestClose = ta.highest(close, 850)

    lowestClose = ta.lowest(close, 850)

    change = ta.change(close, 14)

    atr = ta.atr(14)

    [macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)

    rsiValue = ta.rsi(close, 14)

    stochD = ta.stoch(close, high, low, 14)

    //stampa su grafico degli indicatori

    //EMA21

    Plot(ema, color = color.orange)

    //Bande di Bollinger

    Plot(middleBand, color = color.blue)

    Fill_A = plot(upperBand, color = color.red)

    Fill_B = plot(lowerBand, color = color.green)

    Color_Fill_BB = color.new(#007FFF, 95)

    Fill(Fill_A, Fill_B, color = color_Fill_BB)

    //Etichetta

    Atr_Plot = atr

    If change<0

    Atr_Plot := atr*-1

    Color_Label = color.new(#007FFF, 100)

    Label_1 = label.new(chart.point.now(), “Highest: “+str.tostring(highestClose)+” / Lowest: “+str.tostring(lowestClose)+”\nChange: “+str.tostring(change, “###.###”)+” / ATR: “+str.tostring(atr_Plot, “###.###”)+”\nMACD: “+str.tostring(macdLine, “###.###”)+” / Signal: “+str.tostring(signalLine, “###.###”)+”\nRSI: “+str.tostring(rsiValue, “###.###”)+” / Stoch: “+str.tostring(stochD, “###.###”), style = label.style_label_left, color = color_Label, textcolor = color.purple)

    Label.delete(label_1[1])

    Label_2 = label.new(chart.point.now(), “\n\n\n\n\n\nStrg XAUUSD – Max +”+str.tostring(strategy.opentrades.max_runup(0)/unita, “###.###”)+”% / Min –“+str.tostring(strategy.opentrades.max_drawdown(0)/unita, “###.###”)+”%\n”, style = label.style_label_left, color = color_Label, textcolor = color.purple)

    Label.delete(label_2[1])

    Plot(highestClose, color = #27b097, display = display.status_line)

    Plot(lowestClose, color = #27b097, display = display.status_line)

    Plot(change, color = color.purple, display = display.status_line)

    Plot(atr_Plot, color = color.purple, display = display.status_line)

    Plot(macdLine, color = #27b097, display = display.status_line)

    Plot(signalLine, color = #27b097, display = display.status_line)

    Plot(rsiValue, color = color.purple, display = display.status_line)

    Plot(stochD, color = color.purple, display = display.status_line)

    Plot(strategy.opentrades.max_runup(0)/unita, color = #27b097, display = display.status_line)

    Plot(strategy.opentrades.max_drawdown(0)/unita, color = color.red, display = display.status_line)

    //calcolo delle variabili per l’apertura di posizioni long

    Longcondition1 = (macdLine>0.00 and rsiValue<30 and stochD<20)

    //apertura posizioni long se si verificano le condizioni di cui sopra (senza transazione in corso)

    If (dateRange and strategy.position_size==0 and (strategy.closedtrades==0 or (strategy.closedtrades>=1 and ((bar_index – strategy.closedtrades.exit_bar_index(strategy.closedtrades – 1))>=2))) and longcondition1)

    Profit_Line1 := 10

    Profit_Line2 := 15

    SL := 500-delta_TPSL

    Strategy.entry(“Acq”, strategy.long, comment = “XAUUSD1 – Open Long – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€ – SL –“+str.tostring((SL+delta_TPSL)/100)+”%/-“+str.tostring(((SL+delta_TPSL)/100)*unita)+”€”, alert_message = alertlong)

    Strategy.exit(“ExitAcq”, “Acq”, profit = TP, loss = SL, comment_profit = “XAUUSD1 – Exit Long – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€”, comment_loss = “XAUUSD1 – Exit Long – SL –“+str.tostring((SL+delta_TPSL)/100)+”%/-“+str.tostring(((SL+delta_TPSL)/100)*unita)+”€”, alert_message = alertcloselong)

    //calcolo delle variabili per l’apertura di posizioni short

    Shortcondition1 = (macdLine<0.00 and rsiValue>70 and stochD>80)

    //apertura posizioni short se si verificano le condizioni di cui sopra (senza transazione in corso)

    If (dateRange and strategy.position_size==0 and (strategy.closedtrades==0 or (strategy.closedtrades>=1 and ((bar_index – strategy.closedtrades.exit_bar_index(strategy.closedtrades – 1))>=2))) and shortcondition1)

    Profit_Line1 := 10

    Profit_Line2 := 15

    SL := 500-delta_TPSL

    Strategy.entry(“Ven”, strategy.short, comment = “XAUUSD1 – Open Short – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€ – SL –“+str.tostring((SL+delta_TPSL)/100)+”%/-“+str.tostring(((SL+delta_TPSL)/100)*unita)+”€”, alert_message = alertshort)

    Strategy.exit(“ExitVen”, “Ven”, profit = TP, loss = SL, comment_profit = “XAUUSD1 – Exit Short – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€”, comment_loss = “XAUUSD1 – Exit Short – SL –“+str.tostring((SL+delta_TPSL)/100)+”%/-“+str.tostring(((SL+delta_TPSL)/100)*unita)+”€”, alert_message = alertcloseshort)

    //calcolo delle variabili per l’apertura di posizioni long

    Longcondition2 = (open-close<0.00 and openema and openupperBand and change>atr and macdLine>0.00 and macdLine>signalLine)

    //apertura posizioni long se si verificano le condizioni di cui sopra (senza transazione in corso)

    If (dateRange and strategy.position_size==0 and (strategy.closedtrades==0 or (strategy.closedtrades>=1 and ((bar_index – strategy.closedtrades.exit_bar_index(strategy.closedtrades – 1))>=2))) and longcondition2)

    Profit_Line1 := 10

    Profit_Line2 := 15

    SL := 1000-delta_TPSL

    Strategy.entry(“Acq”, strategy.long, comment = “XAUUSD2 – Open Long – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€ – SL –“+str.tostring((SL+delta_TPSL)/100)+”%/-“+str.tostring(((SL+delta_TPSL)/100)*unita)+”€”, alert_message = alertlong)

    Strategy.exit(“ExitAcq”, “Acq”, profit = TP, loss = SL, comment_profit = “XAUUSD2 – Exit Long – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€”, comment_loss = “XAUUSD2 – Exit Long – SL –“+str.tostring((SL+delta_TPSL)/100)+”%/-“+str.tostring(((SL+delta_TPSL)/100)*unita)+”€”, alert_message = alertcloselong)

    //calcolo delle variabili per l’apertura di posizioni short

    Shortcondition2 = (open-close>0.00 and open>ema and closelowerBand and close=1 and ((bar_index – strategy.closedtrades.exit_bar_index(strategy.closedtrades – 1))>=2))) and shortcondition2)

    Profit_Line1 := 10

    Profit_Line2 := 15

    SL := 1000-delta_TPSL

    Strategy.entry(“Ven”, strategy.short, comment = “XAUUSD2 – Open Short – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€ – SL –“+str.tostring((SL+delta_TPSL)/100)+”%/-“+str.tostring(((SL+delta_TPSL)/100)*unita)+”€”, alert_message = alertshort)

    Strategy.exit(“ExitVen”, “Ven”, profit = TP, loss = SL, comment_profit = “XAUUSD2 – Exit Short – TP +”+str.tostring((TP-delta_TPSL)/100)+”%/+”+str.tostring(((TP-delta_TPSL)/100)*unita)+”€”, comment_loss = “XAUUSD2 – Exit Short – SL –“+str.tostring((SL+delta_TPSL)/100)+”%/-“+str.tostring(((SL+delta_TPSL)/100)*unita)+”€”, alert_message = alertcloseshort)

    ///////////////////////////////FINE STRATEGIA “@DP – XAUUSD – Strtg”////////////////////////////////////

    #244977 quote
    Iván González
    Moderator
    Master

    Buongiorno. A dire il vero, mi è impossibile tradurre questo codice così come lo hai condiviso. Sto provando a trasferirlo in Trading View, ma è pieno di errori… Non riesco a vederlo in Trading View e la struttura condizionale rende impossibile seguirlo. Se puoi pubblicarlo su TradingView e condividere il link, posso aiutarti. Altrimenti, lo trovo difficile…

    #244980 quote
    davide.prini
    Participant
    New

    Buongiorno, hai ragione e mi scuso per il copia-incolla del codice venuto male. Ho tolto tutta la roba extra non necessaria e ti riallego il file con il contenuto del codice corretto (te lo riporto anche sotto). Spero che così sia più semplice convertirlo. Grazie in anticipo!

     

    // @version=5

     

    //dichiarazione variabili utilizzate per aprire e chiudere le transazioni

    var spread = 30                                     //spread applicato ad ogni transazione (espresso in pip)

    var valorePip = 0.010000                            //valore di 1 pip per 1 contratto (espresso in $)

    var delta_TPSL = spread*valorePip*100               //valore utilizzato per ottimizzare il calcolo di TP e SL

    var commissioni = spread*valorePip/2                //commissione applicata ad ogni transazione per 1 contratto (espressa in $)

    var contratto = 1                                   //numero di contratti acquistati ad ogni transazione

    var float TP = 10000+delta_TPSL                     //TP espresso in 0,1 pip. Il profitto è pari a circa al 100,00% del capitale investito per aprire una transazione, compresa la leva

    var float SL = 1000-delta_TPSL                      //SL espresso in 0,1 pip. La perdita è pari a circa al 10,00% del capitale investito per aprire una transazione, compresa la leva

     

    //dichiarazione strategia: Nome strategia, Mostra sul grafico, Valuta in Dollari, Contratti acquistati ad ogni transazione, Commissione applicata per ogni contratto acquistato

    strategy(“Pine Script – Strategy”, overlay = true, currency = “USD”, default_qty_type = strategy.fixed, default_qty_value = contratto, commission_type = strategy.commission.cash_per_contract, commission_value = commissioni)

     

    //verifica che non sia già stato modificato lo SL nella precedente candela

    if SL[1]<(1000-delta_TPSL)

    TP := TP[1]

    SL := SL[1]

     

    //aumento dello SL se la transazione in corso raggiunge o supera un determinato profitto

    for i = 100 to 10 by 5

    if (SL>((i*-100)+500-delta_TPSL) and (strategy.openprofit/contratto)>i)

    SL := (i*-100)+500-delta_TPSL

    break

    if SL[1]>SL

    strategy.exit(“ExitAcq”, “Acq”, profit = TP, loss = SL)

    strategy.exit(“ExitVen”, “Ven”, profit = TP, loss = SL)

     

    //calcolo degli indicatori

    ema = ta.ema(close, 21)

    [middleBand, upperBand, lowerBand] = ta.bb(close, 20, 2)

    change = ta.change(close, 14)

    atr = ta.atr(14)

    [macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)

    rsiValue = ta.rsi(close, 14)

    stochD = ta.stoch(close, high, low, 14)

     

    //calcolo delle variabili per l’apertura di posizioni long

    longcondition1 = (macdLine>0.00 and rsiValue<30 and stochD<20)

    //apertura posizioni long se si verificano le condizioni di cui sopra (senza transazione in corso)

    if (strategy.position_size==0 and longcondition1)

    SL := 500-delta_TPSL

    strategy.entry(“Acq”, strategy.long)

    strategy.exit(“ExitAcq”, “Acq”, profit = TP, loss = SL)

     

    //calcolo delle variabili per l’apertura di posizioni short

    shortcondition1 = (macdLine<0.00 and rsiValue>70 and stochD>80)

    //apertura posizioni short se si verificano le condizioni di cui sopra (senza transazione in corso)

    if (strategy.position_size==0 and shortcondition1)

    SL := 500-delta_TPSL

    strategy.entry(“Ven”, strategy.short)

    strategy.exit(“ExitVen”, “Ven”, profit = TP, loss = SL)

     

    //calcolo delle variabili per l’apertura di posizioni long

    longcondition2 = (open-close<0.00 and open<ema and close>ema and open<upperBand and close>upperBand and change>atr and macdLine>1.00 and macdLine>signalLine)

    //apertura posizioni long se si verificano le condizioni di cui sopra (senza transazione in corso)

    if (strategy.position_size==0 and longcondition2)

    SL := 1000-delta_TPSL

    strategy.entry(“Acq”, strategy.long)

    strategy.exit(“ExitAcq”, “Acq”, profit = TP, loss = SL)

     

    //calcolo delle variabili per l’apertura di posizioni short

    shortcondition2 = (open-close>0.00 and open>ema and close<ema and open>lowerBand and close<lowerBand and change<(atr*-1) and macdLine<-1.00 and macdLine<signalLine)

    //apertura posizioni short se si verificano le condizioni di cui sopra (senza transazione in corso)

    if (strategy.position_size==0 and shortcondition2)

    SL := 1000-delta_TPSL

    strategy.entry(“Ven”, strategy.short)

    strategy.exit(“ExitVen”, “Ven”, profit = TP, loss = SL)

    #245094 quote
    Iván González
    Moderator
    Master

    Bene, eccoti qui.

    // Prevents order accumulation
    DEFPARAM cumulateorders = false
    
    //--------------------------------------------//
    // Strategy Configuration Parameters
    //--------------------------------------------//
    spread = 30                      // Spread in pips
    valorePip = 0.01                  // Value of 1 pip per contract in USD
    deltaTPSL = spread * valorePip * 100  // Adjustment factor for TP & SL calculation
    commissioni = spread * valorePip / 2  // Commission per contract
    contratto = 2                      // Number of contracts per trade
    
    // Set initial SL and TP (Take Profit & Stop Loss)
    ONCE sl = 1000 - deltaTPSL
    tp = 1000 + deltaTPSL
    //--------------------------------------------//
    // Technical Indicators
    //--------------------------------------------//
    ema = Average[21,1](close)  // 21-period Exponential Moving Average (EMA)
    
    // Bollinger Bands (20-period, 2 standard deviations)
    middleBand = Average[20](close)
    upperBand = middleBand + (2 * Std[20](close))
    lowerBand = middleBand - (2 * Std[20](close))
    
    change = close - close[14]  // 14-period price change
    atr = AverageTrueRange[14](close)  // 14-period ATR (Average True Range)
    
    // MACD Calculation
    mymacdLine = macdLine[12,26,9](close)
    signalLine = macdsignal[12,26,9](close)
    
    // RSI & Stochastic D
    rsiValue = RSI[14](close)
    stochD = (close - Lowest[14](low)) / (Highest[14](high) - Lowest[14](low)) * 100
    
    //--------------------------------------------//
    // Entry Conditions - Basic Trading Logic
    //--------------------------------------------//
    // Long Entry Condition (MACD above zero, RSI oversold, Stochastic oversold)
    longcondition1 = mymacdLine > 0 AND rsiValue < 30 AND stochD < 20
    
    // Short Entry Condition (MACD below zero, RSI overbought, Stochastic overbought)
    shortcondition1 = mymacdLine < 0 AND rsiValue > 70 AND stochD > 80
    
    // Open Long Position if No Open Trade & Condition Met
    IF NOT OnMarket AND longcondition1 THEN
    sl = 500 - deltaTPSL
    BUY contratto CONTRACTS AT MARKET
    SET STOP PLOSS sl
    SET TARGET PPROFIT tp
    ENDIF
    
    // Open Short Position if No Open Trade & Condition Met
    IF NOT OnMarket AND shortcondition1 THEN
    sl = 500 - deltaTPSL
    SELLSHORT contratto CONTRACTS AT MARKET
    SET STOP PLOSS sl
    SET TARGET PPROFIT tp
    ENDIF
    
    //--------------------------------------------//
    // Advanced Entry Conditions (Breakout Strategy)
    //--------------------------------------------//
    // Long Entry Condition - Price breaks above EMA & Upper Bollinger Band
    longcondition2 = open < close AND open < ema AND close > ema AND  open < upperBand AND close > upperBand AND change > atr AND mymacdLine > 1.00 AND mymacdLine > signalLine
    
    // Short Entry Condition - Price breaks below EMA & Lower Bollinger Band
    shortcondition2 = open > close AND open > ema AND close < ema AND open > lowerBand AND close < lowerBand AND change < -atr AND mymacdLine < -1.00 AND mymacdLine < signalLine
    
    // Open Long Position if Advanced Condition is Met
    IF NOT OnMarket AND longcondition2 THEN
    sl = 1000 - deltaTPSL
    BUY contratto CONTRACTS AT MARKET
    SET STOP PLOSS sl
    SET TARGET PPROFIT tp
    ENDIF
    
    // Open Short Position if Advanced Condition is Met
    IF NOT OnMarket AND shortcondition2 THEN
    sl = 1000 - deltaTPSL
    SELLSHORT contratto CONTRACTS AT MARKET
    SET STOP PLOSS sl
    SET TARGET PPROFIT tp
    ENDIF
    
    //--------------------------------------------//
    // Profit Calculation for Dynamic Stop Adjustment
    //--------------------------------------------//
    // Determines the current profit/loss of the open position
    IF ONMARKET THEN
    profitNow = strategyprofit + (PositionPrice * POSITIONPERF * PipValue * abs(CountOfPosition))
    ELSE
    profitNow = strategyprofit
    ENDIF
    
    //--------------------------------------------//
    // Dynamic Stop Loss Adjustment
    //--------------------------------------------//
    // Ensures SL never drops below a minimum level
    MinSL = 100
    
    // Loop from 100 down to 10 (similar to Pine Script logic)
    FOR i = 100 DOWNTO 10 DO
    tempSL = (i * -100) + 500 - deltaTPSL  // Compute the provisional SL level
    
    // Ensure SL is valid & adjust dynamically based on profit level
    IF tempSL > MinSL AND (profitNow / contratto) > i THEN
    sl = tempSL
    SET STOP PLOSS sl
    BREAK  // Stop loop once SL is adjusted
    ENDIF
    NEXT
    //--------------------------------------------//
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Conversione della strategia @DP – XAUUSD – Strtg


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Iván González
10 months, 3 weeks ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 03/16/2025
Status: Active
Attachments: 2 files
Logo Logo
Loading...