Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Cycle MA + Deviations", overlay=true)
- // Input for moving average type
- ma_type = input.string("VWMA", title="Moving Average Type", options=["SMA", "EMA", "WMA", "HMA", "VWMA", "RMA", "ALMA"])
- // Input for the length of the moving average
- ma_length = 1460
- // Function to select the chosen moving average type
- f_ma(source, length) =>
- switch ma_type
- "SMA" => ta.sma(source, length)
- "EMA" => ta.ema(source, length)
- "WMA" => ta.wma(source, length)
- "HMA" => ta.hma(source, length)
- "VWMA" => ta.vwma(source, length)
- "RMA" => ta.rma(source, length)
- "ALMA" => ta.alma(source, length, 0.85, 6)
- // Calculate the selected moving average with the user-defined length
- selected_ma = f_ma(close, ma_length)
- // Deviation levels (percentages)
- deviation_up_50 = selected_ma * 1.50
- deviation_up_100 = selected_ma * 2.00
- deviation_up_200 = selected_ma * 3.00
- deviation_up_300 = selected_ma * 4.00
- deviation_up_400 = selected_ma * 5.00
- deviation_down_25 = selected_ma * 0.75
- // Plot the selected moving average
- plot(selected_ma, color=#ff0000, linewidth=2, title="Selected Moving Average")
- // Plot the deviation bands
- plot(deviation_up_400, color=#5d606b, linewidth=1, title="+400% Deviation")
- plot(deviation_up_300, color=#5d606b, linewidth=1, title="+300% Deviation")
- plot(deviation_up_200, color=#5d606b, linewidth=1, title="+200% Deviation")
- plot(deviation_up_100, color=#5d606b, linewidth=1, title="+100% Deviation")
- plot(deviation_up_50, color=#5d606b, linewidth=1, title="+50% Deviation")
- plot(deviation_down_25, color=#ff5a00, linewidth=1, title="-25% Deviation")
- // Table position selection
- table_position = input.string("Bottom Right", title="Table Position", options=["Top Right", "Middle Right", "Bottom Right"])
- // Table layout selection
- table_layout = input.string("Vertical", title="Table Layout", options=["Vertical", "Horizontal"])
- // Table coordinates based on selected position
- var label_position = switch table_position
- "Top Right" => position.top_right
- "Middle Right" => position.middle_right
- "Bottom Right" => position.bottom_right
- // Create the table with dynamic size based on layout
- var table deviation_table = table.new(label_position, table_layout == "Vertical" ? 7 : 7, table_layout == "Vertical" ? 7 : 7, bgcolor=#363a45, border_width=1)
- // Update the table with the current prices of each plot
- if (barstate.islast)
- if (table_layout == "Vertical")
- table.cell(deviation_table, 0, 0, " Cycle MA: " + str.tostring(selected_ma, "#.##"), text_color=color.white)
- table.cell(deviation_table, 0, 1, "+400%: " + str.tostring(deviation_up_400, "#.##"), text_color=color.white)
- table.cell(deviation_table, 0, 2, "+300%: " + str.tostring(deviation_up_300, "#.##"), text_color=color.white)
- table.cell(deviation_table, 0, 3, "+200%: " + str.tostring(deviation_up_200, "#.##"), text_color=color.white)
- table.cell(deviation_table, 0, 4, "+100%: " + str.tostring(deviation_up_100, "#.##"), text_color=color.white)
- table.cell(deviation_table, 0, 5, "+50%: " + str.tostring(deviation_up_50, "#.##"), text_color=color.white)
- table.cell(deviation_table, 0, 6, "-25%: " + str.tostring(deviation_down_25, "#.##"), text_color=color.white)
- else
- table.cell(deviation_table, 0, 0, "Cycle MA: " + str.tostring(selected_ma, "#.##"), text_color=color.white)
- table.cell(deviation_table, 1, 0, "+400%: " + str.tostring(deviation_up_400, "#.##"), text_color=color.white)
- table.cell(deviation_table, 2, 0, "+300%: " + str.tostring(deviation_up_300, "#.##"), text_color=color.white)
- table.cell(deviation_table, 3, 0, "+200%: " + str.tostring(deviation_up_200, "#.##"), text_color=color.white)
- table.cell(deviation_table, 4, 0, "+100%: " + str.tostring(deviation_up_100, "#.##"), text_color=color.white)
- table.cell(deviation_table, 5, 0, "+50%: " + str.tostring(deviation_up_50, "#.##"), text_color=color.white)
- table.cell(deviation_table, 6, 0, "-25%: " + str.tostring(deviation_down_25, "#.##"), text_color=color.white)
Advertisement
Add Comment
Please, Sign In to add comment