0

I'm creating a strategy in Tradingview where it will enter a long position when EMA 25 crossover EMA50. This is my script:

strategy("MyStrategy", overlay=true, initial_capital = 10000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity )

EMA25 = ema(close,25)
EMA50 = ema(close,50)

goLongCondition1 = crossover(EMA20,EMA50)
timePeriod = time >= timestamp(syminfo.timezone, 2019,6,1,0,0)
notInTrade = strategy.position_size <= 0

stoploss = close*0.95
takeprofit = close*1.1

if(goLongCondition1 and timePeriod and notInTrade)
    strategy.entry("long",strategy.long)
    strategy.exit("exit", "long", stop = stoploss, limit = takeprofit)

Based on the current script, the number of unit to buy is calculated based on the total capital they I have currently. However, the actual number of unit that I want enter is using 1% of my capital divide by the ATR(14) at that time.

For example, if I have $9500 now, 1% of $9500 is = $95. Let say the ATR(14) on the date that I want to buy a stock is 6.61, then the number of unit that I should buy = Rounddown(95/6.61) = 14 units.

May I know how should I modified the default_qty_value in strategy in order to achieve this? I'm very new to pine editor, any help will be greatly appreciated!

weizer
  • 1,009
  • 3
  • 16
  • 39
  • Why not use qty parameter in the strategy.entry() function? – Starr Lucky Jun 04 '21 at 10:12
  • What should I use as the parameter for `strategy.entry()` so that it will use 1% of my current capital to calculate number of unit to buy? Because my capital is not a constant as it will change after entering some position. – weizer Jun 07 '21 at 07:23

0 Answers0