Hello everyone,
I'm new to pine script and have been playing with the script below.
My strategy.exit executes perfectly fine for take profit = 50pips (ie. exits trade when 50 pips profit are made resulting in £2.5 of profit). However the loss = 25 never executes correctly. I'm expecting exit on loss of £1.25 but the amount is always different and mostly larger than 1.25. Any hints would be much appreciated.
script :
//@version=5
strategy(title='Multi-RSI Trend Indicator', shorttitle='Multi-RSI', overlay=false)
rsiSource1 = input(title='RSI Source1', defval=ohlc4)
rsiLength1 = input(title='RSI Length1', defval=4)
rsiValue1 = ta.rsi(rsiSource1, rsiLength1)
plot1 = plot(rsiValue1)
rsiSource2 = input(title='RSI Source2', defval=close)
rsiLength2 = input(title='RSI Length2', defval=10)
rsiValue2 = ta.rsi(rsiSource2, rsiLength2)
plot2 = plot(series=rsiValue2, color=rsiValue2 > 50 ? color.green : color.red)
fillCond = false
if (rsiValue1 > rsiValue2)
fillCond := true
fillCond
fill(plot1, plot2, color=fillCond ? color.green : color.gray, transp=10)
ma(source, length, type) => ta.sma(source, length)
len = input.int(30, minval=1, title="Length")
src = rsiValue1
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)
out = ta.sma(src, len)
plot(out, color=color.blue, title="MA", offset=offset)
//maCond = false
//plot(rsiValue1, color=maCond ? color.green : color.gray)
//BackgroundData(symbol, timeframe, data) =>
// isLive = barstate.isrealtime
// request.security(symbol, timeframe, data[isLive ? 1 : 0]) [isLive ? 0 : 1]
//TimeFrame = input.timeframe("1", title="1 Minute")
CondLong = rsiValue1>out and rsiValue1>50 and rsiValue2>out and rsiValue2>50
CondShort = rsiValue1<out and rsiValue1<50 and rsiValue2<out and rsiValue2<50
grp_STRAT = "Strategy settings"
timeInput = input.time(timestamp("01 Feb 2023"), title="Start date", group=grp_STRAT)
tpInPips = input.int(50, title="TP (in pips)", group = grp_STRAT)
slInPips = input.int(25, title="SL (in pips)", group = grp_STRAT)
timePeriod = time >= timeInput
notInTrade = strategy.position_size == 0
if (CondLong and barstate.islast and notInTrade)
strategy.entry("My Long Entry", strategy.long, qty=5)
strategy.exit("My Long Exit", "My Long Entry", loss=slInPips, profit=tpInPips)
if (CondShort and barstate.islast and notInTrade)
strategy.entry("My Short Entry", strategy.short, qty=5)
strategy.exit("My Short Exit", "My Short Entry", loss=slInPips, profit=tpInPips)