//@version=5 indicator("cRSI Candles MTF",overlay = true) cdlCount = input.int(9,"Candle Show Table",maxval=100,minval=0) showRepaint = input.bool(false,"Show Repaint",inline = "1") isAtutoTime = input.bool(true,"Automatic Dominant Cycle Timeframe") tbltxt = input.string(defval='Small', title='Table', options=['Auto', 'Normal', 'Tiny', 'Small', 'Large', 'huge'],inline="pivot") tblps = input.string(defval='Bottom Right', title='', options=['Top Right','Top Left','Top Center', 'Bottom Right', 'Bottom Left', 'Bottom Center','Middle Right','Middle Left','Middle Center'],inline="pivot") upClr = input.color(color.green,"Color Table: Up ",inline = "tabl") dnClr = input.color(color.red,"down ",inline = "tabl") tmfclr = input.color(color.white,"Color Table: Text ",inline = "tabl1") tmfBG = input.color(color.gray,"Background ",inline = "tabl1") grTm_ = "========== Dominant Cycle Chart Timeframe ===============" domcycle_ = input.int(20, minval=10, title='Dominant Cycle Length',group = grTm_) grTm_1 = "========== Dominant Cycle Timeframe 1 ===============" tmf_11 = input.timeframe("","Timeframe",group = grTm_1) domcycle_1 = input.int(20, minval=10, title='Dominant Cycle Length',group = grTm_1) grTm_2 = "========== Dominant Cycle Timeframe 2 ===============" tmf_21 = input.timeframe("","Timeframe",group = grTm_2) domcycle_2 = input.int(20, minval=10, title='Dominant Cycle Length',group = grTm_2) grTm_3 = "========== Dominant Cycle Timeframe 3 ===============" tmf_31 = input.timeframe("","Timeframe",group = grTm_3) domcycle_3 = input.int(20, minval=10, title='Dominant Cycle Length',group = grTm_3) grTm_4 = "========== Dominant Cycle Timeframe 4 ===============" tmf_41 = input.timeframe("","Timeframe",group = grTm_4) domcycle_4 = input.int(20, minval=10, title='Dominant Cycle Length',group = grTm_4) getTmf()=> if isAtutoTime tmf_1 = "" tmf_2 = "" tmf_3 = "" tmf_4 = "" if timeframe.period == "S" tmf_1 := "S" tmf_2 := "5S" tmf_3 := "15S" tmf_4 := "30S" else if timeframe.period == "5S" tmf_1 := "5S" tmf_2 := "15S" tmf_3 := "30S" tmf_4 := "1" else if timeframe.period == "15S" tmf_1 := "15S" tmf_2 := "30S" tmf_3 := "1" tmf_4 := "3" else if timeframe.period == "30S" tmf_1 := "30S" tmf_2 := "1" tmf_3 := "3" tmf_4 := "5" else if timeframe.period == "1" tmf_1 := "1" tmf_2 := "3" tmf_3 := "5" tmf_4 := "15" else if timeframe.period == "5" tmf_1 := "5" tmf_2 := "15" tmf_3 := "30" tmf_4 := "60" else if timeframe.multiplier == 15 tmf_1 := "15" tmf_2 := "30" tmf_3 := "60" tmf_4 := "120" else if timeframe.multiplier == 30 tmf_1 := "30" tmf_2 := "60" tmf_3 := "120" tmf_4 := "180" else if timeframe.multiplier == 60 tmf_1 := "60" tmf_2 := "120" tmf_3 := "180" tmf_4 := "240" else if timeframe.multiplier == 120 tmf_1 := "120" tmf_2 := "180" tmf_3 := "240" tmf_4 := "720" else if timeframe.multiplier == 180 tmf_1 := "180" tmf_2 := "240" tmf_3 := "720" tmf_4 := "D" else if timeframe.multiplier == 240 tmf_1 := "240" tmf_2 := "720" tmf_3 := "D" tmf_4 := "W" else if timeframe.multiplier == 720 tmf_1 := "720" tmf_2 := "D" tmf_3 := "W" tmf_4 := "M" else if timeframe.period == "D" tmf_1 := "D" tmf_2 := "W" tmf_3 := "M" tmf_4 := "3M" else if timeframe.period == "D" tmf_1 := "D" tmf_2 := "W" tmf_3 := "M" tmf_4 := "3M" else if timeframe.period == "W" tmf_1 := "W" tmf_2 := "M" tmf_3 := "3M" tmf_4 := "6M" else if timeframe.period == "M" tmf_1 := "M" tmf_2 := "3M" tmf_3 := "6M" tmf_4 := "12M" [tmf_1,tmf_2,tmf_3,tmf_4] else [tmf_11,tmf_21,tmf_31,tmf_41] [tmf_1,tmf_2,tmf_3,tmf_4] = getTmf() // c // crsi function get_crsi(src,domcycle) => var cyclelen = domcycle / 2 var vibration = 10 var cyclicmemory = domcycle * 2 var torque = 2.0 / (vibration + 1) var phasingLag = (vibration - 1) / 2.0 crsi = 0.0 up = ta.rma(math.max(ta.change(src), 0), cyclelen) down = ta.rma(-math.min(ta.change(src), 0), cyclelen) rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down) crsi := torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * nz(crsi[1]) crsi actual_timeframe() => _tf = str.tostring(timeframe.multiplier) _output = str.tostring(timeframe.period) if(timeframe.isseconds) _output := _tf + "s" else if(timeframe.isminutes) if(timeframe.multiplier < 59) _output := _tf + "M" else _output := str.tostring(timeframe.multiplier / 60) + "H" _output getDir(domcycle)=> var arrClr = array.new_int(0) if arrClr.size() > cdlCount + 1 arrClr.pop() dir = get_crsi(close,domcycle) > get_crsi(open,domcycle) ? 1 : -1 arrClr.unshift(dir) [dir,arrClr,actual_timeframe()] [dir_tmf_1,arrClr_1,act_1] = request.security(syminfo.tickerid,tmf_1, getDir(domcycle_1))//,gaps = isUseGap_1 ? barmerge.gaps_on : barmerge.gaps_off) [dir_tmf_2,arrClr_2,act_2] = request.security(syminfo.tickerid,tmf_2, getDir(domcycle_2))//,gaps = isUseGap_2 ? barmerge.gaps_on : barmerge.gaps_off) [dir_tmf_3,arrClr_3,act_3] = request.security(syminfo.tickerid,tmf_3, getDir(domcycle_3))//,gaps = isUseGap_3 ? barmerge.gaps_on : barmerge.gaps_off) [dir_tmf_4,arrClr_4,act_4] = request.security(syminfo.tickerid,tmf_4, getDir(domcycle_4))//,gaps = isUseGap_4 ? barmerge.gaps_on : barmerge.gaps_off) var lastDir = 0 isBuyr = dir_tmf_1 == 1 and dir_tmf_2 == 1 and dir_tmf_3 == 1 and dir_tmf_4 == 1 isSellr = dir_tmf_1 == -1 and dir_tmf_2 == -1 and dir_tmf_3 == -1 and dir_tmf_4 == -1 isBuy = isBuyr and not isBuyr[1] isSell = isSellr and not isSellr[1] plotshape(isBuy and showRepaint and lastDir == 1? low : na,"Up Repaint",shape.labelup,location.belowbar,color.blue,size = size.small) plotshape(isSell and showRepaint and lastDir == -1 ? high : na,"Down Repaint",shape.labeldown,location.abovebar,color.yellow,size = size.small) plotshape(isBuy and lastDir != 1? low : na,"Up",shape.labelup,location.belowbar,color.green,size = size.small) plotshape(isSell and lastDir != -1 ? high : na,"Down",shape.labeldown,location.abovebar,color.red,size = size.small) if isBuy lastDir := 1 if isSell lastDir := -1 // bgcolor(dir_tmf_1 == 1 ? color.rgb(76, 175, 79, 88) : dir_tmf_1 == -1 ? color.rgb(255, 82, 82, 86) : na) // plotcandle(get_crsi(open,domcycle_1), get_crsi(high,domcycle_1), get_crsi(low,domcycle_1), get_crsi(close,domcycle_1), "cRSI Candles", color = get_crsi(close,domcycle_1) > get_crsi(open,domcycle_1) ? color(#00a7d1) : color(#af144a), wickcolor = get_crsi(close,domcycle_1) > get_crsi(open,domcycle_1) ? color(#00a7d1) : color(#af144a), bordercolor = get_crsi(close,domcycle_1) > get_crsi(open,domcycle_1) ? color(#00a7d1) : color(#af144a)) [dir_,_,_] = getDir(domcycle_) isBuy1 = dir_ == 1 and dir_ != dir_[1] isSell1 = dir_ == -1 and dir_ != dir_[1] alertcondition(isBuy1,"Buy","Buy") alertcondition(isSell1,"Sell","Sell") alertcondition(isBuy,"Buy T4","Buy T4") alertcondition(isSell,"Sell T4","Sell T4") //-------------------------------- if barstate.islast or barstate.ishistory tblpost = switch tblps 'Middle Right'=>position.middle_right 'Middle Left' =>position.middle_left 'Middle Center' =>position.middle_center 'Top Right' =>position.top_right 'Top Left' =>position.top_left 'Top Center' =>position.top_center 'Bottom Right' =>position.bottom_right 'Bottom Left' =>position.bottom_left 'Bottom Center' =>position.bottom_center var txt_siz = tbltxt == 'Auto' ? size.auto : tbltxt == 'Normal' ? size.normal : tbltxt == 'Tiny' ? size.tiny : tbltxt == 'Small' ? size.small : tbltxt == 'Large' ? size.large : tbltxt == 'huge' ? size.huge : size.normal var table tbl = table.new(tblpost,4, 150, border_color=color.rgb(120, 123, 134, 100),border_width=1) table.clear(tbl, 0, 0,2, 149) greenClr = upClr redClr = dnClr table.cell(tbl, 0, 0, "cRSI", bgcolor= tmfBG,text_color = tmfclr) table.merge_cells(tbl,0,0,3,0) table.cell(tbl, 0, 1, act_1, bgcolor= tmfBG,text_color = tmfclr) table.cell(tbl, 1, 1, act_2, bgcolor= tmfBG,text_color = tmfclr) table.cell(tbl, 2, 1, act_3, bgcolor= tmfBG,text_color = tmfclr) table.cell(tbl, 3, 1, act_4, bgcolor= tmfBG,text_color = tmfclr) if arrClr_1.size() >= cdlCount +1 for i = 0 to cdlCount table.cell(tbl, 0, i+2, " ", bgcolor= arrClr_1.get(i) == 1 ? greenClr : arrClr_1.get(i) == -1 ? redClr : na ) if arrClr_2.size() >= cdlCount +1 for i = 0 to cdlCount table.cell(tbl, 1, i+2, " ", bgcolor= arrClr_2.get(i) == 1 ? greenClr : arrClr_2.get(i) == -1 ? redClr : na ) if arrClr_3.size() >= cdlCount +1 for i = 0 to cdlCount table.cell(tbl, 2, i+2, " ", bgcolor= arrClr_3.get(i) == 1 ? greenClr : arrClr_3.get(i) == -1 ? redClr : na ) if arrClr_4.size() >= cdlCount +1 for i = 0 to cdlCount table.cell(tbl, 3, i+2, " ", bgcolor= arrClr_4.get(i) == 1 ? greenClr : arrClr_4.get(i) == -1 ? redClr : na )