Help with fixiing code

Forums ProRealTime English forum ProBuilder support Help with fixiing code

Viewing 7 posts - 1 through 7 (of 7 total)
  • #245068

    Can someone help me with the problem showing on the following code? line 6 between period and close I dont have any knowlege regarding coding and have created this code using chatGTP. Many thanks.

     

    // Set the period for calculation
    period = 50

    // Calculate linear regression line
    slope = LinearRegressionSlope[period](close)
    intercept = LinearRegressionIntercept[period](close)
    regression_line = intercept + slope * BarIndex

    // Calculate standard error
    sum_squared_errors = 0
    for i = 0 to period – 1 do
    predicted = intercept + slope * (BarIndex – i)
    sum_squared_errors = sum_squared_errors + (close[i] – predicted)^2
    next
    std_error = sqrt(sum_squared_errors / period)

    // Upper and lower channel lines
    upper_channel = regression_line + std_error
    lower_channel = regression_line – std_error

    // Plot the lines
    RETURN regression_line AS “Regression Line”, upper_channel AS “Upper Channel”, lower_channel AS “Lower Channel”

    #245069

    Thanks, how can I access this?

     

    #245070

    // Set the period for calculation
    period = 50

    // Calculate linear regression line
    slope = LinearRegressionSlope[period](close)
    intercept = LinearRegressionIntercept[period](close)
    regression_line = intercept + slope * BarIndex

    // Calculate standard error
    sum_squared_errors = 0
    for i = 0 to period – 1 do
    predicted = intercept + slope * (BarIndex – i)
    sum_squared_errors = sum_squared_errors + (close[i] – predicted)^2
    next
    std_error = sqrt(sum_squared_errors / period)

    // Upper and lower channel lines
    upper_channel = regression_line + std_error
    lower_channel = regression_line – std_error

    // Plot the lines
    RETURN regression_line AS “Regression Line”, upper_channel AS “Upper Channel”, lower_channel AS “Lower Channel”

    #245079

    hi! here you have the code. Be careful with “_”.

     

    2 users thanked author for this post.
    #245394

    I need help with the same thing so Im borrowing this thread. Can someone help me please? 🙂

     

    // ProRealTime backtest för DAX, Nasdaq och OMXS30 (med Shorting, Slippage & Optimeringar)
    DEFPARAM PreloadBars = 200   // Säkerställ att vi har tillräckligt med historiska data
    DEFPARAM CumulateOrders = False
    DEFPARAM Slippage = 0.1      // Simulerar slippage på 0.1% per affär

    // Initialt kapital & riskhantering
    INITIAL_CAPITAL = 100000
    POSITION_SIZE = 1    // Antal kontrakt per affär
    SL_MULTIPLIER = 2    // Stop-loss på 2x ATR
    TSL_MULTIPLIER_TREND = 3  // Trailing Stop för trendföljande strategier
    TSL_MULTIPLIER_SHORT = 2  // Trailing Stop för kortsiktiga strategier
    COURTAGE = 10        // Courtage per affär

    // Tidsfilter (undviker första & sista timmen av handeln)
    HOUR = Hour
    IF HOUR < 10 OR HOUR > 16 THEN
    RETURN
    ENDIF

    // — Beräkning av indikatorer —
    MA20 = Average[20](Close)
    MA70 = Average[70](Close)
    MA150 = Average[150](Close)
    ATR14 = AverageTrueRange[14](Close)
    RSI14 = RSI[14](Close)
    BOLL_TOP = BollingerUp[20](Close,2)
    BOLL_BOTTOM = BollingerDown[20](Close,2)

    // — Variabel för Trailing Stop —
    TrailingStop = 0

    // — Strategi 1: Super Simple Bollinger Bands (SSBB) (Long & Short) —
    IF Close < BOLL_BOTTOM THEN
    BUY POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close – (TSL_MULTIPLIER_TREND * ATR14)
    ENDIF

    IF Close > BOLL_TOP THEN
    SELL AT MARKET
    ENDIF

    IF Close > BOLL_TOP THEN
    SELLSHORT POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close + (TSL_MULTIPLIER_TREND * ATR14)
    ENDIF

    IF Close < BOLL_BOTTOM THEN
    EXITSHORT AT MARKET
    ENDIF

    // — Strategi 2: Stark trend & jämviktspendling (Long & Short) —
    IF Close > MA150 AND Close < MA70 THEN
    BUY POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close – (TSL_MULTIPLIER_TREND * ATR14)
    ENDIF

    IF Close > MA20 THEN
    SELL AT MARKET
    ENDIF

    IF Close < MA150 AND Close > MA70 THEN
    SELLSHORT POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close + (TSL_MULTIPLIER_TREND * ATR14)
    ENDIF

    IF Close < MA20 THEN
    EXITSHORT AT MARKET
    ENDIF

    // — Strategi 3: Long Trend High Momentum (LTHM) (Long & Short) —
    IF MA20 > MA70 AND Close > MA150 THEN
    BUY POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close – (TSL_MULTIPLIER_TREND * ATR14)
    ENDIF

    IF Close < ENTRYPRICE – (SL_MULTIPLIER * ATR14) THEN
    SELL AT MARKET
    ENDIF

    IF MA20 < MA70 AND Close < MA150 THEN
    SELLSHORT POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close + (TSL_MULTIPLIER_TREND * ATR14)
    ENDIF

    IF Close > ENTRYPRICE + (SL_MULTIPLIER * ATR14) THEN
    EXITSHORT AT MARKET
    ENDIF

    // — Strategi 4: Hög Volatilitet (ATR) (Long & Short) —
    IF ATR14 > 1.5 * Average[50](ATR14) THEN
    BUY POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close – (TSL_MULTIPLIER_SHORT * ATR14)
    ENDIF

    IF BarsSinceEntry >= 5 THEN
    SELL AT MARKET
    ENDIF

    IF ATR14 < 0.8 * Average[50](ATR14) THEN
    SELLSHORT POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close + (TSL_MULTIPLIER_SHORT * ATR14)
    ENDIF

    IF BarsSinceEntry >= 5 THEN
    EXITSHORT AT MARKET
    ENDIF

    // — Strategi 5: Kortsiktig RSI (Long & Short) —
    IF RSI14 < 30 THEN
    BUY POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close – (TSL_MULTIPLIER_SHORT * ATR14)
    ENDIF

    IF RSI14 > 50 THEN
    SELL AT MARKET
    ENDIF

    IF RSI14 > 70 THEN
    SELLSHORT POSITION_SIZE CONTRACTS AT MARKET
    TrailingStop = Close + (TSL_MULTIPLIER_SHORT * ATR14)
    ENDIF

    IF RSI14 < 50 THEN
    EXITSHORT AT MARKET
    ENDIF

    // — Hantera Trailing Stop-Loss —
    IF PositionSize > 0 THEN
    IF Close – (TSL_MULTIPLIER_TREND * ATR14) > TrailingStop THEN
    TrailingStop = Close – (TSL_MULTIPLIER_TREND * ATR14)
    ENDIF
    IF Close < TrailingStop THEN
    SELL AT MARKET
    ENDIF
    ENDIF

    IF PositionSize < 0 THEN
    IF Close + (TSL_MULTIPLIER_TREND * ATR14) < TrailingStop THEN
    TrailingStop = Close + (TSL_MULTIPLIER_TREND * ATR14)
    ENDIF
    IF Close > TrailingStop THEN
    EXITSHORT AT MARKET
    ENDIF
    ENDIF

    #245395

    Hi. First you should remove “_”

    1 user thanked author for this post.
    #245397

    User variables names can only use the characters A to Z, a to z and 0 to 9.

    The variable name must start with a letter, and letters are not case sensitive, ‘A’ is the same as ‘a’.

    They must be unique and not clash with any of the reserved keywords, HOUR = Hour.

    Also the RETURN keyword is reserved for indicator program code files not back-testing files.

     

    3 users thanked author for this post.
Viewing 7 posts - 1 through 7 (of 7 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login