TSI CCI Hull

faresg7900 · study · 117 行 · 点赞 841 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=4
 
study(title="TSI CCI Hull", shorttitle="TSICCIHULL", overlay=true)
long = input(title="Long Length", type=input.integer, defval=50)
short = input(title="Short Length", type=input.integer, defval=52)
signal = input(title="Signal Length", type=input.integer, defval=24)
price=input(title="Source",type=input.source,defval=close)
Period=input(26, minval=1)
lineupper = input(title="Upper Line", type=input.integer, defval=100)
linelower = input(title="Lower Line", type=input.integer, defval=-100)
p=price
length= Period
double_smooth(src, long, short) =>
    fist_smooth = ema(src, long)
    ema(fist_smooth, short)
pc = change(price)
double_smoothed_pc = double_smooth(pc, long, short)
double_smoothed_abs_pc = double_smooth(abs(pc), long, short)
tsi_value = 100 * (double_smoothed_pc / double_smoothed_abs_pc)
keh = tsi_value*5 > linelower ? color.red : color.lime
teh = ema(tsi_value*5, signal*5) > lineupper ? color.red : color.lime
meh = ema(tsi_value*5, signal*5) > tsi_value*5 ? color.red : color.lime
//i1=plot(tsi_value*5, title="TSI Value", color=color.black, linewidth=1,transp=100)
//i2=plot(ema(tsi_value*5, signal*5), title="TSI Signal", color=color.black, linewidth=1,transp=100)
//fill(i1,i2,color=meh,transp=85)
//plot(cross(tsi_value*5, ema(tsi_value*5, signal*5)) ? tsi_value*5 : na, style=plot.style_circles, color=color.black, linewidth=10)
//plot(cross(tsi_value*5, ema(tsi_value*5, signal*5)) ? tsi_value*5 : na, style=plot.style_circles, color=color.white, linewidth=8,transp=0)
//plot(cross(tsi_value*5, ema(tsi_value*5, signal*5)) ? tsi_value*5 : na, style=plot.style_circles, color=meh, linewidth=5)
n2ma = 2 * wma(p, round(length / 2))
nma = wma(p, length)
diff = n2ma - nma
sqn = round(sqrt(length))
n1 = wma(diff, sqn)
cci = (p - n1) / (0.015 * dev(p, length))
c = cci > 0 ? color.lime : color.red
c1 = cci > 20 ? color.lime : color.silver
c2 = cci < -20 ? color.red : color.silver
//cc=plot(cci, color=c, title="CCI Line", linewidth=2)
//cc2=plot(cci[1], color=color.gray, linewidth=1,transp=100)
//fill(cc,cc2,color=c,transp=85)
//plot(cross(20, cci) ? 20 : na, style=plot.style_cross,title="CCI cross UP",  color=c1, linewidth=2,transp=100,offset=-2)
//plot(cross(-20, cci) ? -20 : na, style=plot.style_cross,title="CCI cross down",  color=c2, linewidth=2,transp=100,offset=-2)
 
TSI1=ema(tsi_value*5, signal*5)
TSI2=ema(tsi_value*5, signal*5)[2]
 
hullma_smoothed = wma(2*wma(n1, Period/2)-wma(n1, Period), round(sqrt(Period)))
//plot(hullma_smoothed*200)
 
longCondition = TSI1>TSI2 and hullma_smoothed<price and cci>0
 
shortCondition = TSI1<TSI2 and hullma_smoothed>price and cci<0
    
bbuy = longCondition and cci>cci[1] and cci > 0 and n1>n1[1]
ssell = shortCondition and cci<cci[1] and cci < 0 and n1<n1[1]
 
//////////////////
////// TP ////////
//////////////////
 
///////////////
/////////
// The Fixed Percent Stop Loss Code
// User Options to Change Inputs (%)
stopPer = input(30, title='Stop Loss %', type=input.float) / 100
takePer = input(0.5, title='Take Profit %', type=input.float) / 100
 
//detect what was last signal (long or short)
long_short = 0
long_last = bbuy and (nz(long_short[1]) == 0 or nz(long_short[1]) == -1)
short_last = ssell and (nz(long_short[1]) == 0 or nz(long_short[1]) == 1)
long_short := long_last ? 1 : short_last ? -1 : long_short[1]
 
//entry price
longPrice = valuewhen(long_last, close, 0)
shortPrice = valuewhen(short_last, close, 0)
//fixed sltp prices
longStop = longPrice * (1 - stopPer)
shortStop = shortPrice * (1 + stopPer)
longTake = longPrice * (1 + takePer)
shortTake = shortPrice * (1 - takePer)
//plot sltp lines
//plot(long_short==1  ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
//plot(long_short==-1 ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
//plot(long_short==1  ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Fixed TP")
//plot(long_short==-1 ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Fixed TP")
 
//remove first bar for SL/TP (you can't enter a trade at bar close THEN hit your SL on that same bar)
longBar1 = barssince(long_last)
longBar2 = longBar1 >= 1 ? true : false
shortBar1 = barssince(short_last)
shortBar2 = shortBar1 >= 1 ? true : false
//check for SL hit during a bar
longSLhit = long_short==1 and longBar2 and low < longStop
plotshape(longSLhit, style=shape.labelup, location=location.belowbar, color=color.gray, size=size.tiny, title="Long SL", text=" Long SL", textcolor=color.white)
shortSLhit = long_short==-1 and shortBar2 and high > shortStop
plotshape(shortSLhit, style=shape.labeldown, location=location.abovebar, color=color.gray, size=size.tiny, title="Short SL", text=" Short SL", textcolor=color.white)
 
//check for TP hit during bar
longTPhit = long_short==1 and longBar2 and close > longTake
plotshape(longTPhit, style=shape.labeldown, location=location.abovebar, color=color.blue, size=size.tiny, title="Long TP", text="Long TP", textcolor=color.white)
shortTPhit = long_short==-1 and shortBar2 and close < shortTake
plotshape(shortTPhit, style=shape.labelup, location=location.belowbar, color=color.blue, size=size.tiny, title="Short TP", text="Short TP", textcolor=color.white)
 
//reset long_short if SL/TP hit during bar
long_short := (long_short==1 or long_short==0) and longBar2 and (longSLhit or longTPhit) ? 0 : (long_short==-1 or long_short==0) and shortBar2 and (shortSLhit or shortTPhit) ? 0 : long_short
//
 
BUY = longCondition and cci>cci[1] and cci > 0 and n1>n1[1] and (not longTPhit)
SELL = shortCondition and cci<cci[1] and cci < 0 and n1<n1[1] and (not shortTPhit)
 
alertcondition(condition=longTPhit, title="Long Take Profit", message='Long TP Hit')
alertcondition(condition=shortTPhit, title="Short Take Profit", message='Short TP Hit')
alertcondition(BUY, title = "buy", message = "BUY")
alertcondition(SELL, title = "sell", message = "SELL")
plotshape(BUY, style=shape.labeldown, location=location.belowbar, color=color.yellow, size=size.tiny, title="Buy", text="Buy", textcolor=color.black)
plotshape(SELL, style=shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, title="Sell", text="Sell", textcolor=color.white)

← 返回列表