TradingView
ckrofghkdlxld
25 giu 2019 05:32

cii strategy 

Bitcoin / US Dollar IndexBitMEX

Descrizione

파인스크립트 공부한다고 만들어봤는데 혼자하니깐 피드백이 안되서 올려봅니다.
원리는 짧은 기간의 cci(14)가 긴 기간의 cci(56)을 뚫으면 매수, 뚫리면 매도하게 해놨습니다.
단기 분봉에는 거의 안 맞고 3시간봉 12시간봉에 맞춰서 쓰시면 됩니다. 횡보장때 승률이 많이 낮습니다..
Commenti
stonet3413
일단 같이 함 써볼려고 하는데 혹시 1/3/5분봉도 볼수있게 개조하고싶은데 시간 추가하는곳이 어딘지 모르겟네요....
Shaily01
nice work buddy,you are best :) u got a follower today :)
CryptoRaven
Hi,
Nice job man. Since you're using EMA this script will repaint. I'll try to make it better later and I'll let you know if I could get a better result.
gastongouron
@CryptoRaven, why do you say it repaints? I checked the program on a 1second chart and as far as I'l concerned it doesn't seem to repaint.
I'm curious about your expertise if you don't mind sharing your thoughts.
CryptoRaven
@gastongouron, I can't even remember this script. But I can explain and also I should rephrase my words.

I should've said "Since you're using EMA this script may repaint", but I can't remember, so "maybe" I read the script at the time and was sure that it repaints.

The repaint issue will be noticeable in higher time frames (like >= 4h), since the price movements are larger prior to the last close, so the chance that the price movements interfere with calculations are much higher.

It's not always easy to notice the repaints. Repaints can happen on older signals, and most of the time we're watching just the last signal.

But in the end, if you tested the script and it doesn't repaint, maybe I was wrong and the developer used EMA in a proper way.
gastongouron
@CryptoRaven, thanks for taking the time to reply.

I think it's very easy to understand. As the script uses recalculate on order fills, it prints multiple events on same bar, which means that in its original version it can repaint for the following reason:
- crossover condition or cci condition happens barstats.isrealtime.
- when bar ends and calculations are done for the last time before it prints indefinitely, the crossover (or any other condition can "unhappen").
- in its original state the strategy will not print the trade, which occured in real time.
- the solution is to use on_bar_close while testing the strategy rather than the original recalculate on order fill (that you have to uncheck).

Some other detail that is worth highlighting is that the strategy can cumulate multiple signals in it's current state, which mean that it requires additional logic to handle the lifecycle of positions (and allow pyramiding without failing). Last but not least, this strategy can be very profitable if you have lower fees on brokers, otherwise it's somehow dangerous even tho you can easilly reach sharpe ratios > with the new settings I mentionew above.

- last detail, this sort of strategy makes big difference when you trade it as market maker. I changed the exit so it uses configurable trailing.

Btw, if strat repaints, it is more likely to do so visibly on very low tf than high tf as more events are supposed to occur in lower amount of time.

See the changes and feel free to test it on bybit btc 30mm
gastongouron
//@version=5
strategy(title='[CHZ][STRATEGY][30mn] - IROSHIMA', process_orders_on_close= true, currency=currency.USD, overlay=true, pyramiding=1, max_bars_back=5000, commission_type=strategy.commission.percent, commission_value=0.02, default_qty_type=strategy.percent_of_equity, default_qty_value=30, margin_long = 1./2*50, margin_short = 1./2*50, initial_capital=1000)

source = close
shortlength = input(7) //14?
longlength = input(10) //54
aa = input(5)
len = input.int(8, minval=1, title="len", group="ICHIKOMU")
lenTurn = input.int(8, minval=1, title="lenturn", group="ICHIKOMU")
lenStd = input.int(27, minval=1, title="lenstd", group="ICHIKOMU")
TrailPerc = input.float(title="Trailing Offset (0,1%)", minval=0.1, step=0.1, defval=0.5) * 0.001

//Cci
community_channel_index_1 = ta.cci(source, shortlength)
community_channel_index_2 = ta.cci(source, longlength)

wtm_e(so, l) =>
esa = ta.ema(so, l)
d = ta.ema(math.abs(so - esa), l)
ci = (so - esa) / (0.015 * d)
ta.ema(ci, l * 2 + 1)

alh(len) =>
math.avg(ta.lowest(len), ta.highest(len))

alh_src(src, len) =>
math.avg(ta.lowest(src, len), ta.highest(src, len))

wt = wtm_e(close, len)
turn = alh_src(wt, lenTurn)
std = alh_src(wt, lenStd)

cnt = 0
if wt > turn
cnt += 1
cnt
if wt > std
cnt += 1
cnt

h0 = hline(100)
h1 = hline(-100)

green = color.green
purple = color.purple
red = color.red
blue = color.blue

plot(community_channel_index_1, color=color.new(green, 0))
plot(community_channel_index_2, color=color.new(red, 0))
fill(h0, h1, color=color.new(purple, 90))
bgcolor(cnt == 0 ? red : cnt == 1 ? blue : cnt == 2 ? green : na, transp=90)

// Logic
longEntry = ta.crossover(community_channel_index_1, community_channel_index_2) and ta.change(community_channel_index_2) > 0
longExit = (community_channel_index_2 < 0 and community_channel_index_1 < -50 and ta.change(community_channel_index_1) < 0) or (ta.crossunder(community_channel_index_1, -100) and ta.change(cnt) < 0)
shortEntry = ta.crossunder(community_channel_index_1, community_channel_index_2) and ta.change(community_channel_index_2) < 0 and ta.falling(community_channel_index_1, aa)
shortExit = (community_channel_index_2 > 0 and community_channel_index_1 > 100 and ta.change(community_channel_index_1) > 0) or (ta.crossover(community_channel_index_2, 100) and ta.change(cnt) > 0)

trailingOffset = (strategy.position_avg_price - (strategy.position_avg_price * (1 - TrailPerc))) / syminfo.mintick

// signals entries and exits
l = longEntry and not shortEntry and not longExit
s = shortEntry and not longEntry and not shortExit

if l
strategy.entry('L', strategy.long, comment='L')

if s
strategy.entry('S', strategy.short, comment='S')

lex = longExit and strategy.position_size > 0
sex = shortExit and strategy.position_size < 0

if lex
strategy.exit(id = "L", alert_trailing = "Exit Long Order", trail_price = close, trail_offset =trailingOffset, comment = "long Exit")

if sex
strategy.exit(id = "S", alert
gastongouron
this line is missing
if sex
strategy.exit(id = "S", alert_trailing = "Exit short Order", trail_price = close, trail_offset =trailingOffset, comment = "short Exit")
gastongouron
@CryptoRaven, I'd love any eventual feedback of course
Altro