Im trying modificate my simple script which buy position when price crossover 200 MA and sell when price is crossunder 200 EMA.
I wanna add pyramiding: 5 positions max - each position is 20% of the total capital next position when price is 2% higher than previous long Sell all positions when price crossunde 200 EMA
@version=3
strategy("EMA200", shorttitle="EMA200", overlay=true, initial_capital=10000, pyramiding=1)
EMA=input(200, minval=1)
s=ema(close,EMA) // sma values stored in s1 and s2 variables
plot(s)
buy= close>s
sell= close<s
addToLong = (strategy.position_size > 0) and strategy.position_avg_price +
strategy.position_avg_price*0.02 //close > high[1]
ordersize=floor(strategy.equity/close) // To dynamically calculate the order size as the account equity increases or decreases.
strategy.entry("long",strategy.long,ordersize,when=buy) // Buys when buy condition met
strategy.order(id="Additional Long", when = addToLong, long=true)
strategy.close("long", when = sell ) // Closes position when sell condition me
when price crossover 200 MAdo you mean 200EMA? - Michel_T.