Professional Documents
Culture Documents
TTK
TTK
calcx()=>
bufferDn= high + Multiplier * wma(tr,ATR)
bufferUp= low - Multiplier * wma(tr,ATR)
if (thisCCI >= 0 and lastCCI < 0)
bufferUp := bufferDn[1]
if (thisCCI <= 0 and lastCCI > 0)
bufferDn := bufferUp[1]
if (thisCCI >= 0)
if (bufferUp < bufferUp[1])
bufferUp := bufferUp[1]
else
if (thisCCI <= 0)
if (bufferDn > bufferDn[1])
bufferDn := bufferDn[1]
x = 0.0
x := thisCCI >= 0 ?bufferUp:thisCCI <= 0 ?bufferDn:x[1]
x
tempx = calcx()
calcswap() =>
swap = 0.0
swap := tempx>tempx[1]?1:tempx<tempx[1]?-1:swap[1]
swap
tempswap = calcswap()
swap2=tempswap==1?color.green:color.red
swap3=thisCCI >=0 ?color.green :color.red
swap4=original?swap3:swap2
plot(htfx,color=htfswap4,transp=0,linewidth=3)
if(buy)
strategy.entry("buy",true)
if(sell)
strategy.entry("sell",false)
if (strategy.position_size > 0)
strategy.exit(id="Target", limit=longExitPrice , stop = stop_buy)
if (strategy.position_size < 0)
strategy.exit(id="Target", limit=shortExitPrice , stop = stop_sell)
startPrice = i + s * (len0 - 1)
endPrice = i
var line baseLine = na
if na(baseLine)
baseLine := line.new(bar_index - len0 + 1, startPrice, bar_index, endPrice,
width=4, extend=extend.right)
else
line.set_xy1(baseLine, bar_index - len0 + 1, startPrice)
line.set_xy2(baseLine, bar_index, endPrice)
na
//
[Bx,By,Axbis,Aybis,slope]
// Function to get trendline price for X bars ago ("0" = current value)
line_get_price(_start_time,_start_price,_slope,_lookback_period,_log_chart) =>
var float current_price=0.0
elapsed_time = (time-_start_time)
current_price := _log_chart?(_start_price*exp((elapsed_time-
(_lookback_period*bar_time))*_slope)):(_start_price + (elapsed_time-
(_lookback_period*bar_time))*_slope)
// Initialition of pseudo array to keep track of last 10 high and 10 low trendline
values
var int high_x0=0, var float high_y0=0.0, var float high_sl0=0.0
var int high_x1=0, var float high_y1=0.0, var float high_sl1=0.0
var int high_x2=0, var float high_y2=0.0, var float high_sl2=0.0
var int high_x3=0, var float high_y3=0.0, var float high_sl3=0.0
var int high_x4=0, var float high_y4=0.0, var float high_sl4=0.0
var int high_x5=0, var float high_y5=0.0, var float high_sl5=0.0
var int high_x6=0, var float high_y6=0.0, var float high_sl6=0.0
var int high_x7=0, var float high_y7=0.0, var float high_sl7=0.0
var int high_x8=0, var float high_y8=0.0, var float high_sl8=0.0
var int high_x9=0, var float high_y9=0.0, var float high_sl9=0.0
cross_high1=
disp_select and high_sl1*time>0?0:
line_cross(close,high_x1,high_y1,high_sl1,log_chart)
cross_low1=
disp_select and low_sl1*time<0?0:
line_cross(close,low_x1,low_y1,low_sl1,log_chart)
cross_high2=
disp_select and high_sl2*time>0?0:
line_cross(close,high_x2,high_y2,high_sl2,log_chart)
cross_low2=
disp_select and low_sl2*time<0?0:
line_cross(close,low_x2,low_y2,low_sl2,log_chart)
cross_high3=
disp_select and high_sl3*time>0?0:
line_cross(close,high_x3,high_y3,high_sl3,log_chart)
cross_low3=
disp_select and low_sl3*time<0?0:
line_cross(close,low_x3,low_y3,low_sl3,log_chart)
cross_high4=
disp_select and high_sl4*time>0?0:
line_cross(close,high_x4,high_y4,high_sl4,log_chart)
cross_low4=
disp_select and low_sl4*time<0?0:
line_cross(close,low_x4,low_y4,low_sl4,log_chart)
cross_high5=
disp_select and high_sl5*time>0?0:
line_cross(close,high_x5,high_y5,high_sl5,log_chart)
cross_low5=
disp_select and low_sl5*time<0?0:
line_cross(close,low_x5,low_y5,low_sl5,log_chart)
cross_high6=
disp_select and high_sl6*time>0?0:
line_cross(close,high_x6,high_y6,high_sl6,log_chart)
cross_low6=
disp_select and low_sl6*time<0?0:
line_cross(close,low_x6,low_y6,low_sl6,log_chart)
cross_high7=
disp_select and high_sl7*time>0?0:
line_cross(close,high_x7,high_y7,high_sl7,log_chart)
cross_low7=
disp_select and low_sl7*time<0?0:
line_cross(close,low_x7,low_y7,low_sl7,log_chart)
cross_high8=
disp_select and high_sl8*time>0?0:
line_cross(close,high_x8,high_y8,high_sl8,log_chart)
cross_low8=
disp_select and low_sl8*time<0?0:
line_cross(close,low_x8,low_y8,low_sl8,log_chart)
cross_high9=
disp_select and high_sl9*time>0?0:
line_cross(close,high_x9,high_y9,high_sl9,log_chart)
cross_low9=
disp_select and low_sl9*time<0?0:
line_cross(close,low_x9,low_y9,low_sl9,log_chart)
long_break=
(trendline_nr>9?cross_high9==1 or (select_breaks?false:cross_low9==1):false) or
(trendline_nr>8?cross_high8==1 or (select_breaks?false:cross_low8==1):false) or
(trendline_nr>7?cross_high7==1 or (select_breaks?false:cross_low7==1):false) or
(trendline_nr>6?cross_high6==1 or (select_breaks?false:cross_low6==1):false) or
(trendline_nr>5?cross_high5==1 or (select_breaks?false:cross_low5==1):false) or
(trendline_nr>4?cross_high4==1 or (select_breaks?false:cross_low4==1):false) or
(trendline_nr>3?cross_high3==1 or (select_breaks?false:cross_low3==1):false) or
(trendline_nr>2?cross_high2==1 or (select_breaks?false:cross_low2==1):false) or
(trendline_nr>1?cross_high1==1 or (select_breaks?false:cross_low1==1):false) or
cross_high0==1 or (select_breaks?false:cross_low0==1)
short_break=
(trendline_nr>9?(select_breaks?false:cross_high9==-1) or cross_low9==-1:false) or
(trendline_nr>8?(select_breaks?false:cross_high8==-1) or cross_low8==-1:false) or
(trendline_nr>7?(select_breaks?false:cross_high7==-1) or cross_low7==-1:false) or
(trendline_nr>6?(select_breaks?false:cross_high6==-1) or cross_low6==-1:false) or
(trendline_nr>5?(select_breaks?false:cross_high5==-1) or cross_low5==-1:false) or
(trendline_nr>4?(select_breaks?false:cross_high4==-1) or cross_low4==-1:false) or
(trendline_nr>3?(select_breaks?false:cross_high3==-1) or cross_low3==-1:false) or
(trendline_nr>2?(select_breaks?false:cross_high2==-1) or cross_low2==-1:false) or
(trendline_nr>1?(select_breaks?false:cross_high1==-1) or cross_low1==-1:false) or
(select_breaks?false:cross_high0==-1) or cross_low0==-1
////////////
// INPUTS //
////////////
/////////////////////
// Get HLC from HT //
// Calc High
high_cur = 0.0
high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high)
phigh = 0.0
phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1]
// Calc Low
low_cur = 0.0
low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low)
plow = 0.0
plow := is_newbar(pp_res) ? low_cur[1] : plow[1]
// Calc Close
pclose = 0.0
pclose := is_newbar(pp_res) ? close[1] : pclose[1]