convert this pinescript so that i can run it in mql5 //@version=5…
- User
convert this pinescript so that i can run it in mql5 //@version=5 indicator("Autocorrelation Candles [SS]", max_labels_count = 500, overlay=true) import HeWhoMustNotBeNamed/arrays/1 as arrays
show_reversals = input.bool(true, "Show Reversals") limit_labels = input.bool(false, "Limit Labels") limit_len = input.int(30, "Limit Labels to #") size = input.string("Tiny", "Label Size", ["Tiny", "Normal", "Large"]) col = input.string("White", "Text Colour", ["White", "Black"])
cor = math.round(ta.correlation(close, close[1], 14), 2) highest = ta.highest(cor, 75) trend = ta.correlation(time, close, 14) atr = ta.atr(10) bool reversal = cor >= highest bool generic = cor >= 0.94
color text_color = na
if col == "White" text_color := color.white else if col == "Black" text_color := color.rgb(0, 0, 0) color transp = color.new(color.white, 100) color collah = reversal ? color.orange : generic ? color.red : text_color
bool upside_reversal = trend <= -0.5 and cor >= 0.94 bool downside_reversal = trend >= 0.5 and cor >= 0.94
string reversal_string = upside_reversal ? "Likely \n Upside Reversal" : downside_reversal ? "Likely \n Downside Reversal" : na
label_array = array.new() reversal_array = array.new()
create_label(id) => label.new(bar_index[id], y = low[id], text = str.tostring(cor[id]), color = transp, textcolor = reversal[id] ? color.orange : cor[id] >= 0.94 ? color.red : text_color, style = label.style_label_up, size = size == "Tiny" ? size.tiny : size == "Normal" ? size.normal : size == "Large" ? size.large : size.tiny) reversal_label(id) => label.new(bar_index[id], y = high[id] + atr[id], text = upside_reversal[id] or downside_reversal[id] ? str.tostring(reversal_string[id]) : na, color = transp, textcolor = trend[id] <= -0.5 ? color.lime : trend[id] >= 0.5 ? color.red : text_color, style = label.style_label_up, size =size == "Tiny" ? size.tiny : size == "Normal" ? size.normal : size == "Large" ? size.large : size.tiny)
if limit_labels != true label.new(bar_index, y = low, text = str.tostring(cor), color = transp, textcolor = collah, style = label.style_label_up, size = size == "Tiny" ? size.tiny : size == "Normal" ? size.normal : size == "Large" ? size.large : size.tiny) if show_reversals label.new(bar_index, y = high + atr, text = upside_reversal or downside_reversal ? str.tostring(reversal_string) : na, color = transp, textcolor = trend <= -0.5 ? color.lime : trend >= 0.5 ? color.red : color.white, style = label.style_label_up, size = size == "Tiny" ? size.tiny : size == "Normal" ? size.normal : size == "Large" ? size.large : size.tiny)
else if limit_labels for i = 0 to limit_len arrays.push(label_array, create_label(i), limit_len) if show_reversals arrays.push(reversal_array, reversal_label(i), limit_len)
- Assistant
- User
rewrite the indicator so that i can copy and paste it to Mql5 editor
- Assistant
- User
':'unexpected token error in this line fix string labelText = trend >= TrendThreshold ? “Likely Downside Reversal” : trend <= -TrendThreshold ? “Likely Upside Reversal” : “”;
- Assistant
The error you're encountering often arises due to the use of typographic quotation marks (“ ”) instead of straight quotation marks (" ") in code. Programming languages, including MQL5, require the use of straight quotation marks to denote strings. Additionally, to ensure the ternary operator works correctly in MQL5 and to avoid confusion or errors with complex conditions, it may help to slightly refactor the code for clarity.
Here's the corrected line with straight quotation marks and a clearer formulation that should work without the 'unexpected token' error:
string labelText = ""; if(trend >= TrendThreshold) { labelText = "Likely Downside Reversal"; } else if(trend <= -TrendThreshold) { labelText = "Likely Upside Reversal"; }This approach separates the logic into distinct conditions, making it easier to read and debug. It removes the nested ternary operators, which, while concise, can sometimes lead to confusion or unexpected behavior if not structured correctly.
- User
now fix all of those instancces in the cod u gave me
- Assistant