Hi
@samer800
May I request your help to convert this script. Thanks
https://www.tradingview.com/script/NHt4hBzv-3-Weeks-Tight-CANSLIM-Technical-Indicator/
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// Copyright © John Muchow
//@version=4
study("3 Weeks Tight", overlay = true)
//---------------------------------------------------------
// User configurable values and variable initialization
//----------------------------------------------------------
iThreshold = input(title = "% threshold between closes", type = input.float, minval = .5, defval = 1.0, step = .05)
iShowIndicatorLine = input(title = "Horizontal indicator at tight areas?", type = input.bool, defval = true, group = "Visual Indicators")
iIndicatorStyle = input(title = " Style", type=input.string, options=["Solid", "Dotted", "Dashed", "Arrow Left", "Arrow Right", "Arrow Both"], defval="Solid", group = "Visual Indicators")
iIndicatorLineThickness = input(title = " Thickness", type = input.integer, minval = 1, maxval = 10, defval = 2, group = "Visual Indicators")
iIndicatorLineColor = input(title = " Color", type = input.color, defval = #5A98C6, group = "Visual Indicators")
iOffset = input(title = " Offset up/down", type = input.integer, minval = -5, maxval = 5, defval = 1, step = .1, group = "Visual Indicators")
iShowVerticalBars = input(title = "Vertical band at tight areas?", type = input.bool, defval = true, group = "Visual Indicators")
iShowBuyPrice = input(title = "Show buy price at tight area?", type = input.bool, defval = true, group = "Buy Price")
iBuyPriceOffset = input(title = "Buy price offset up/down", type = input.integer, minval = 0, maxval = 15, defval = 5, step = .5, group = "Buy Price")
iTextSizeOption = input(title = "Text size", type = input.string, options=["Normal", "Large", "Huge"], defval = "Normal", group = "Buy Price")
// Only show content if on a weekly timeframe
onWeeklyChart = timeframe.isweekly
highestHigh = max(high, high[1], high[2])
//---------------------------------------------------------
// Calculate % change between closes
//----------------------------------------------------------
percentChange1 = ((close - close[1]) / close[1]) * 100
percentChange2 = ((close[1] - close[2]) / close[2]) * 100
//---------------------------------------------------------
// 3 weeks tight if closes meet threshold
//----------------------------------------------------------
threeWeeksTight = (abs(percentChange1) <= iThreshold) and (abs(percentChange2) <= iThreshold)
lineStyle = (iIndicatorStyle == "Dotted") ? line.style_dotted :
(iIndicatorStyle == "Dashed") ? line.style_dashed :
(iIndicatorStyle == "Arrow Left") ? line.style_arrow_left :
(iIndicatorStyle == "Arrow Right") ? line.style_arrow_right :
(iIndicatorStyle == "Arrow Both") ? line.style_arrow_both : line.style_solid
//---------------------------------------------------------
// Draw horizontal line above three weeks tight
//----------------------------------------------------------
if (onWeeklyChart and threeWeeksTight and iShowIndicatorLine)
line.new(bar_index[2], high + iOffset, bar_index, high + iOffset, style = lineStyle, width = iIndicatorLineThickness, color = iIndicatorLineColor)
//---------------------------------------------------------
// Show vertical bar indicating tight area?
//----------------------------------------------------------
bgcolor(onWeeklyChart and iShowVerticalBars and threeWeeksTight ? #5A98C6 : na, editable = false)
bgcolor(onWeeklyChart and iShowVerticalBars and threeWeeksTight ? #5A98C6 : na, offset = -1, editable = false)
bgcolor(onWeeklyChart and iShowVerticalBars and threeWeeksTight ? #5A98C6 : na, offset = -2, editable = false)
//---------------------------------------------------------
// Optional alert when 3 weeks tight is detected
//----------------------------------------------------------
alertcondition(threeWeeksTight, title="3 Weeks Tight", message="3 Weeks Tight pattern has been found.")
//---------------------------------------------------------
// Round to specified number of decimal places
//----------------------------------------------------------
fRound(_number, _decimals) =>
power = pow(10, _decimals)
int(_number * power) / power
//---------------------------------------------------------
// Label showing highest high of the tight range
//----------------------------------------------------------
fontSize = (iTextSizeOption == "Normal") ? size.normal :
(iTextSizeOption == "Large") ? size.large : size.huge
var label labelID = label.new(x = na, y = na, textcolor = color.white, color = #15B72C, size = fontSize, tooltip = "Highest high of the tight area + ten cents.")
if (onWeeklyChart and threeWeeksTight and iShowBuyPrice)
// Notice the buy price is $.1 above the highest high,
// the traditional CANSLIM entry to ensure push through resistance
label.set_text(id = labelID, text = "Buy price: \n" + tostring(fRound(highestHigh + .1, 2)))
label.set_x(id = labelID, x = bar_index)
label.set_y(id = labelID, y = high + iBuyPriceOffset)