Going to be a slightly tricky one to explain. I'm in the process of writing my very first Pine script, its a very simple system using RSI, I'm not expecting it to be successful necessarily I'm just trying to get my head around writing a system using Pine.
In simple terms, the system executes a long position when the RSI reads at or below 25 and a short position when the RSI reads at or above 75. Take profit is 2% or if the RSI reaches overbought/oversold (the opposite of whatever the direction of the position is). Stop loss price will be set at 1.5x the current ATR (not yet coded into the script). My issue is calculating position size:
What I want is to code the system to use a position size where 1.5x the ATR = 1% of the account's value. When manually placing trades, my stop is placed at 1.5x the ATR and then my position size is chosen so that the stop loss is equal to (or as close as possible to) 1% of my total account size. Is there a combination of functions/inputs which would allow me to do this within a Pine script? Apologies if this is poorly explained/not enough info, this is also my first post on Stack Overflow!