Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

Issues with 'strategy.position_avg_price'

Jun 3, 2023 - 7:06 PM

Viewed 1113 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/1765043 COPY
  • Hey guys, hope everyone is doing fine. I'm new to pinescript coding and I'm having a fairly simple (I guess) issue that manages to mess up my day entirely.... In my code I have the following lines:

    // Calculate entry price for long position
    entryPriceLong = strategy.position_avg_price(Long Entry)

    // Calculate entry price for short position
    entryPriceShort = strategy.position_avg_price(Short Entry)

    However, this error message is prompted:
    Could not find function or function reference 'strategy.position_avg_price'

    Thanks for anybody that finds the time and manages to save my day!

    0
  • Hi Dominik

    The variable strategy.position_avg_price doesn't take a parameter between parentheses
    Documentation: https://www.tradingview.com/pine-script-reference/v5/#var_strategy.position_avg_price

    The code should be

    if strategy.position_size > 0 // Long
        entryPriceLong = strategy.position_avg_price
    else if strategy.postion_size < 0 // short
       entryPriceShort = strategy.position_avg_price
    
    1
CONTENTS