I have been trying to write some code, and I came up with this so far, but I am not being able to figure out the error that it keeps outputting. "'if' can not return String when Series is used inside it" I tried to correct the If statements but it just does not seem to work. Any help would be appreciated if you can help me get this complied. Thanks in advance
//@version=2
study("MOVES")
length = input(title="Length", type=integer, defval=100)
multiplier = input(title="Multiplier", type=float, defval=2)
take_profit_multiplier = input(title="Take Profit Multiplier", type=float, defval=1.5)
reversal_zone_length = input(title="Reversal Zone Length", type=integer, defval=5)
avg = sma(close, length)
std = stdev(close, length)
// Calculate the upper and lower bounds for the big move
upper = avg + multiplier * std
lower = avg - multiplier * std
// Plot the bounds on the chart
plot(upper, color=red, linewidth=2, title="Upper Bound")
plot(lower, color=red, linewidth=2, title="Lower Bound")
// Check if the current close price is outside the bounds
if (close > upper)
direction = "Up"
else
if (close < lower)
direction = "Down"
else
direction = ""
// Check if the next candle confirms the move
if (direction == "Up" and close[1] < upper)
direction = ""
else
if (direction == "Down" and close[1] > lower)
direction = ""
// Provide alerts for entering additional positions in the same trend
if (direction == "Up")
alertcondition(close < upper and close > lower, title="Buy Alert", message="The price has dipped lower within the bounds. Consider buying more positions in the same trend.")
else
if (direction == "Down")
alertcondition(close > lower and close < upper, title="Sell Alert", message="The price has dipped lower within the bounds. Consider selling more positions in the same trend.")
alertcondition(direction != "", title="Big Move Alert", message="The close price has moved outside the bounds and the next candle confirms the trend. This could indicate a big move is coming in the " + direction + " direction.")
// Display a label indicating when to add more to your position
if (direction == "Up")
label_bg = color.green
else
if (direction == "Down")
label_bg = color.red
else
label_bg = color.transparent
label.new(bar_index, upper, text="Add more\n" + direction, yloc=yloc.abovebar, color=color.white, background=label_bg)
// Create take profit zones before the trend finishes
if (direction == "Up")
take_profit = upper + take_profit_multiplier * std
plot(take_profit, color=green, linewidth=2, title="Take Profit Zone")
alertcondition(close < take_profit)