TradingView
ikoskela
2018년 5월 25일 오후 11시 15분

EMA Cross Strategy - Angara123 

Bitcoin / United States DollarCoinbase

설명

Based on Anvamsi's script.

Added a filter to only enter trades when the RSI is greater than (or less than if shorting) the 26 period EMA of the RSI.
Turned off stop losses for better gains.

will add other features as we collaborate in chat
코멘트
whitesiroi
Hello, again I finally made it work, u were right, "loss" does work
here is the working example I found tradingview.com/script/o5InDPbl-Open-Close-Cross-Strategy/
Thank you
whitesiroi
whitesiroi
Hi, thank you for your script. I'm knew to pine script.

Is there a way to put stop loss with fixed amount, like exit a trade if it goes 100 pips in opposite direction?

I tried strategy.exit("Buy", loss = close - 100), but it doesn't work. if I entered long at 9700 I want SL to be at 9600, is it possible?

Thank you
ikoskela
@whitesiroi, there is stop loss functionality built into this one. Look at the last lines:

if (UseStopLoss)
strategy.exit("StopLoss", "LongId", loss = close * stopLoss / 1000 / syminfo.mintick)
strategy.exit("StopLoss", "ShortId", loss = close * stopLoss / 1000 / syminfo.mintick)

try:
if (UseStopLoss)
strategy.exit("StopLoss", "LongId", loss = close -100)

I'm new to this too so let me know if that works
whitesiroi
@ikoskela, thank you for your reply.
still it doesn't close when I expect it to :)
gonna try different variations :)
Looks like I need to use "stop" instead of "loss" but still it doesn't work as expected:)

just in case, here is mine code & stuff I tried:

//@version=2
strategy("Working 55 & 200 EMA strategy", overlay = true, initial_capital=1000, commission_type=strategy.commission.percent, commission_value=0.2)

fast = input(defval = 55, step = 5)
slow = input(200)
inverse = input(false, title = "Inverse Buy & Sell")

ma1 = ema(close, fast)
ma2 = ema(close, slow)

plot(ma1, title = "Fast MA", color = lime, style = line, linewidth = 3)
plot(ma2, title = "Slow MA", color = black, style = line, linewidth = 3)

short = strategy.short
long = strategy.long

//sl = 100
//long_signal = crossover(ma1, ma2)
//last_open_long_signal = long_signal ? open : nz(last_open_long_signal[1])
//long_sl = low <= (last_open_long_signal - sl)

//short_signal = crossunder(ma1, ma2)
//last_open_short_signal = short_signal ? open : nz(last_open_short_signal[1])
//short_sl = high >= (last_open_short_signal + sl)


//slLong = if crossover(ma1, ma2)
// close - 100
//slShort = if crossover(ma2, ma1)
// close + 100

strategy.entry("LongId", long, when = crossover(ma1, ma2))
strategy.entry("ShortId", short, when = crossunder(ma1, ma2))

//strategy.close("Buy", when=long_sl)
//strategy.close("Sell", when=short_sl)

strategy.exit("StopLoss", "LongId", loss = close * 100 / 1000 / syminfo.mintick)
strategy.exit("StopLoss", "ShortId", loss = close * 100 / 1000 / syminfo.mintick)

//strategy.exit("Buy SL", "Buy", loss = close - 500)
//strategy.exit("Sell SL", "Sell", loss = close + 500)

//strategy.exit("SL", "Buy", stop = close - 500)
//strategy.exit("SL", "Sell", stop = close + 500)

Thank you, if I found solution how to do it - I'll post it here ;)
ikoskela
I know its mess. oh well
더보기