// ============================================================ // Inputs // ============================================================{ var CHoCH_Group = "Visual Settings" var CHoCH_Style_in = input.string("┈┈┈┈", "CHoCH Style", options=["──────", "┈┈┈┈", "╌╌╌╌"], inline = "CH1_line", group = CHoCH_Group) var CHoCH_Style = (CHoCH_Style_in == "┈┈┈┈") ? line.style_dotted : (CHoCH_Style_in == "╌╌╌╌") ? line.style_dashed : line.style_solid var CHoCH_Color = input.color(color.new(color.blue,20),"Color", inline = "CH1_line", group = CHoCH_Group) var CHoCH_Thickness = input.int(1, "Thickness", minval = 1, step = 1, inline = "CH1_line", group = CHoCH_Group)
var CHoCH_Change = input(false,"Show CHoCH continuations", group = CHoCH_Group, tooltip = "If unset then only show CHoCHs on Change of Trend") var CHoCH_cont_Style_in = input.string("┈┈┈┈", "CHoCH Cont Style", options=["──────", "┈┈┈┈", "╌╌╌╌"], inline = "CH2_line", group = CHoCH_Group) var CHoCH_cont_Style = (CHoCH_cont_Style_in == "┈┈┈┈") ? line.style_dotted : (CHoCH_cont_Style_in == "╌╌╌╌") ? line.style_dashed : line.style_solid var CHoCH_cont_Color = input.color(color.new(color.aqua,45),"Color", inline = "CH2_line", group = CHoCH_Group) var CHoCH_cont_Thickness = input.int(1, "Thickness", minval = 1, step = 1, inline = "CH2_line", group = CHoCH_Group) var CHoCH_number = input.int(6, "Number of CHoCHs to display", minval = 0, group = CHoCH_Group)
var CHoCH_extras = "CHoCH Prediction" var CHoCH_helper_Style_in= input.string("┈┈┈┈", "Prediction Style", options=["──────", "┈┈┈┈", "╌╌╌╌"], inline = "CH1_line", group = CHoCH_extras) var CHoCH_helper_Style = (CHoCH_helper_Style_in == "┈┈┈┈") ? line.style_dotted : (CHoCH_helper_Style_in == "╌╌╌╌") ? line.style_dashed : line.style_solid var CHoCH_helper_Color = input.color(color.new(color.blue,20),"Color", inline = "CH1_line", group = CHoCH_extras) var CHoCH_helper_Thickness= input.int(2, "Thickness", minval = 1, step = 1, inline = "CH1_line", group = CHoCH_extras) var show_CHoCH_fractal_HL= input(false,"Show Fractal High and Low Line", group = CHoCH_extras, tooltip = "Shows the current fractal range, good when learning how to draw CHoCHs.") var show_next_CHoCH = input(true,"Show Next CHoCH line", group = CHoCH_extras, tooltip = "Shows the the line where the next CHoCH will happen.")
alert_bull_choch = input.bool(true,"Activate alerts for bullish CHoCHs", group = grp) alert_bear_choch = input.bool(true,"Activate alerts for bearish CHoCHs", group = grp) alert_cont_choch = input.bool(false,"Activate alerts for continuation CHoCHs", group = grp)
ts(value) => // converts int, float, bool into strings // [any] value -> variable to be converted // returns -> // string value -> a string str.tostring(value)
print(value) => // Print log to screen // any value -> variable to be printed db.print(c, f, ts(value))
drawLine(lin_array, x1, y1, x2, y2, style = line.style_solid, width = 1, linecolor = color.white) => // Draw a line // [line] lin_array -> array to add the line to // int x1 -> index to draw the start of the line at // float y1 -> price to draw the start of the line at // int x2 -> index to draw the end of the line at // float y2 -> price to draw the end of the line at // print("New CHoCH at " + ts(x1) + " " + ts(y1))
clearDrawing(line_array) => // erase CHoCH drawings that are beyond the requested number of CHoCH's // [line] line_array -> an array of lines to be deleted if array.size(line_array) > CHoCH_number for i = CHoCH_number to array.size(line_array) - 1 line.delete(array.get(line_array,i)[0]) for i = array.size(line_array) - 1 to CHoCH_number array.remove(line_array,i)
changeHighLowLines(hi, hp, li, lp) => // Change the fractal high and low lines // int hi -> index of high // float hp -> price of high // int li -> index of low // float lp -> price of low
highSince(int end, start = 0) => // Find the highest value since start bars back // int start -> bars back // returns -> //int -> bars back to highest high int hIndex = 0 float hPrice = 0 for i = (end) to (start) if high > hPrice hIndex := i hPrice := high hIndex
lowSince(int end, start = 0) => // Find the lowest value since start bars back // int start -> bars back // returns -> // int -> bars back to lowest low int hIndex = 0 float hPrice = 99999999 for i = (end) to (start) if low < hPrice hIndex := i hPrice := low hIndex
findBreakInLow() => // finds where the low run stops // returns -> // int highSince(_i) -> index of highest candle since low int _i = 0 cond = low[_i + 1] > low[_i] while cond _i := _i + 1 cond := low[_i + 1] > low[_i] highSince(_i)
findBreakInHigh() => // finds where the high run stops // returns -> // int lowSince(_i) -> index of lowest candle since low int _i = 0 cond = high[_i + 1] < high[_i] while cond _i := _i + 1 cond := high[_i + 1] < high[_i] lowSince(_i)
// ============================== } // ====================== End of Function =====================}
// ============================================================ // Main Code // ============================================================{ engulfed = false
// Candle is engulfing candle if high > CH_high_price and low < CH_low_price and low < CH_low_price and low[1] > CH_low_price[1] // candle engulfs previous candle and takes out both low and high in one move engulfed := true if CHoCH_trend == "Bearish" drawLine(CH_line_array, CH_high_index, CH_high_price, bar_index, CH_high_price, style = CHoCH_Style, width = CHoCH_Thickness, linecolor = CHoCH_Color) clearDrawing(CH_line_array) CHoCH_trend := "Bullish" if CHoCH_trend == "Bullish" drawLine(CH_line_array, CH_low_index, CH_low_price, bar_index, CH_low_price, style = CHoCH_Style, width = CHoCH_Thickness, linecolor = CHoCH_Color) clearDrawing(CH_line_array) CHoCH_trend := "Bearish"
// breaks fractal high if high > CH_high_price if high[1] <= CH_high_price[1] and not engulfed // candle caused CHoCH or continuation CHoCH (name?) if CHoCH_trend == "Bearish" drawLine(CH_line_array, CH_high_index, CH_high_price, bar_index, CH_high_price, style = CHoCH_Style, width = CHoCH_Thickness, linecolor = CHoCH_Color) clearDrawing(CH_line_array) if alert_bull_choch // modification to add alerts alert("Bullish CHoCH",alert_freq) else if alert_cont_choch // modification to add alerts alert("Bullish Cont CHoCH",alert_freq) else if CHoCH_Change drawLine(CH_cont_line_array, CH_high_index, CH_high_price, bar_index, CH_high_price, style = CHoCH_cont_Style, width = CHoCH_cont_Thickness, linecolor = CHoCH_cont_Color) clearDrawing(CH_cont_line_array) CHoCH_trend := "Bullish" // calculate new fractal high and low CH_high_price := high CH_high_index := bar_index lowOffset = findBreakInHigh() CH_low_index := bar_index - lowOffset CH_low_price := low[lowOffset]
// breaks fractal low if low < CH_low_price if low[1] >= CH_low_price[1] and not engulfed // candle caused CHoCH or continuation CHoCH (name?) if CHoCH_trend == "Bullish" drawLine(CH_line_array, CH_low_index, CH_low_price, bar_index, CH_low_price, style = CHoCH_Style, width = CHoCH_Thickness, linecolor = CHoCH_Color) clearDrawing(CH_line_array) if alert_bear_choch // modification to add alerts alert("Bearish CHoCH",alert_freq) else if alert_cont_choch // modification to add alerts alert("Bearish Cont CHoCH",alert_freq)
// Draw in fractal high and low if selected if show_CHoCH_fractal_HL changeHighLowLines(CH_high_index, CH_high_price, CH_low_index, CH_low_price) else if show_next_CHoCH changeNextCHoCH(CH_high_index, CH_high_price, CH_low_index, CH_low_price) // ==================== End of Main Code ======================} // plot(bar_index)
ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יוכלו להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אבל השימוש החוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.
המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.