SuperTrend Backtest + BB

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #208775 quote
    Edisone
    Participant
    Average

    Buongiorno,

    sto cercando di programmare un SuperTrend Backtest con condizioni di uscita basate sulle Bande di Bollinger.

    La condizione d’entrata è il cambio di colore (long) del supertrend.

    Le condizioni d’uscita:

    1. exit al cambio di colore del supertrend oppure
    2. exit quando una candela ha il range completamente out alla BB Superiore oppure
    3. exit quando il massimo di una candela è oltre alla BB superiore del 50% del valore del range e quando la candela successiva chiude in rosso.

    Grazie

    Saluti

    DEFPARAM CumulateOrders=False
    var1=3
    var2=10
    
    indicator1 = close
    indicator2 = SuperTrend[var1,var2]
    c1 = (indicator1 CROSSES OVER indicator2)
    
    indicatorBB = BollingerUp[20](close) //BB UP
    
    IF NOT LONGONMARKET and (c1 and ((high) < indicatorBB[0])) THEN
    BUY 1 SHARES AT MARKET
    ENDIF
    
    // Condizioni per uscire da posizioni long
    
    // 1) Candela con High e Low completamente out BB+
    cond1=0
    IF (high[1] and low[1]) > indicatorBB[0] Then
    cond1=1
    ENDIF
    
    // 2) Candela con metà range out BB+
    cond2=0
    aa = high[1] - low[1] //range
    bb = high[1] - indicatorBB[1] //
    IF (aa > (aa/2)) > indicatorBB[1]  THEN
    cond2=1
    ENDIF
    
    // 3) Candela rossa dopo condizione 2
    cond3=0
    rossa = (open[0] > close[0])
    IF rossa and cond2 and (rossa < indicatorBB) THEN
    cond3=1
    ENDIF
    
    // 4) Exit Cambio colore da Long a Short
    c2 = (indicator1 CROSSES UNDER  indicator2)
    
    IF LONGONMARKET and cond1 or cond2 or c2 THEN
    SELL AT MARKET
    ENDIF
    #208840 quote
    Nicolas
    Keymaster
    Master

    Dovresti cambiare il modo in cui hai codificato le condizioni per chiudere l'ordine, con parentesi:

    IF LONGONMARKET and (cond1 or cond2 or c2) THEN
    SELL AT MARKET
    ENDIF
    #208936 quote
    Edisone
    Participant
    Average

    Grazie,

    non riesco ad uscire dal trade  quando la candela è uscita dalla BB superiore per metà del suo range

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

SuperTrend Backtest + BB


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Edisone @edisone Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Edisone
3 years ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 01/30/2023
Status: Active
Attachments: No files
Logo Logo
Loading...