Help with errors in strategy

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #244206 quote
    JoshPhoenix
    Participant
    New

    Someone on X/Twitter has shared a good strategy, I am trying to implement it but there are errors generated.

    I’ve asked AI to convert it to code/txt from the image they shared. The strategy looks quite good, they’ve documented it in the post.

    https://x.com/AlgomaticTrade/status/1893249375758893545

    can anyone help / figure out why it’s not working?

     

    Here’s the converted code:

     

    defparam preLoadBars = 10000
    defparam cumulateOrders = false
    atrPeriods = 39  // ATR calculation period
    
    // Variables
    trueRange = Max(High - Low, Max(Abs(High - Close[1]), Abs(Low - Close[1])))
    atr = Average[atrPeriods](trueRange)  // ATR based on True Range
    
    // Dynamic Position Sizing
    // User Inputs
    riskPercent = 1  // Risk percentage for position sizing
    portfolioSize = 20000  // Default portfolio size
    // ATR calculation period
    
    contractsToTrade = 1  // Number of contracts to trade
    
    // Position Sizing Calculation
    positionEquity = Max(PortfolioEquity, portfolioSize)  // Use real equity or default portfolio size
    contractsToTrade = (riskPercent / 100 * positionEquity) / (atr * PointValue)
    
    // Indicators
    bodyRatio = abs(close-open) / (high-low)
    
    // Conditions
    cl = summation[3](close-open)=3
    cl = cl and highest[3](bodyRatio) >= 0.7
    clk = summation[3](close-open)=-3
    
    // Action
    if cl then
        buy contractsToTrade contract at market
    endif
    
    if clk then
        sell contractsToTrade contract at market
    endif
    strat.png strat.png
    #244211 quote
    fifi743
    Participant
    Master
    #244239 quote
    JS
    Participant
    Senior

    • I have adjusted the conditions, can you see if you mean this…

    • // Checks if the closing price has been higher than the opening price for the last 3 candles
    • C1 = SUMMATION[3](close > open) = 3

    • // Checks if the highest BodyRatio in the last 3 candles is at least 0.7
    • C2 = HIGHEST[3](ABS(close – open) / (high – low)) >= 0.7

    • // Long signal when both conditions are met
    • LongSignal = C1 AND C2

    • // Sell signal when the closing price has been lower than the opening price for the last 3 candles
    • SellSignal = SUMMATION[3](close < open) = 3 • // Execution of buy and sell orders • IF LongSignal THEN • BUY contractsToTrade CONTRACT AT MARKET • ENDIF • IF SellSignal THEN • SELL contractsToTrade CONTRACT AT MARKET • ENDIF

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

Help with errors in strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by JS
11 months, 4 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/23/2025
Status: Active
Attachments: 3 files
Logo Logo
Loading...