How do i fix this error Cannot call 'line.new' with 'y1'=series[line] in Pine-Script v4?
I am trying to make bull_open = bearEngulfingOpen but I am getting the following error line 79: Cannot call 'line.new' with 'y1'=series[line]. The argument should be of type: series[float]. The value of bearEngulfOpen is being plotted on the chart so I don't know why I can't use it again.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © MGoBlue74
//@version=4
study("1 Profit Target", overlay=true, max_bars_back=500)
maxBarsBack = 500
previousRange = open[1] - close[1]
line bullEngulfOpen = na
line bullEngulfLow = na
line bullEngulfMid = na
line bullEngulfStop = na
line bullEngulfProfit1 = na
line bearEngulfOpen = na
line bearEngulfHigh = na
line bearEngulfMid = na
line bearEngulfStop = na
line bearEngulfProfit1 = na
isBullEngulf = previousRange > 0 and close > open[1]
isBearEngulf = previousRange < 0 and close < open[1]
// Get inputs
showStop = input(true, title="ATR Trailing Stop", group="ATR Trailing Stop")
atrLength = input(title="Length", type=input.integer, defval=14, minval=1, group="ATR Trailing Stop")
useStructure = input(title="Use Structure?", type=input.bool, defval=true, group="ATR Trailing Stop")
lookback = input(title="How Far To Look Back For High/Lows", type=input.integer, defval=7, minval=1, group="ATR Trailing Stop")
atrStopMultiplier = input(title="ATR Multiplier", type=input.float, defval=1.0, minval=0.1, group="ATR Trailing Stop")
// Calculate data
atr = atr(atrLength)
lowestLow = lowest(low, lookback)
highestHigh = highest(high, lookback)
longStop = (useStructure ? lowestLow : close) - atr * atrStopMultiplier
shortStop = (useStructure ? highestHigh : close) + atr * atrStopMultiplier
// Draw data to chart
plot(showStop and atr ? atr : na, color=color.new(color.blue,100), title="ATR")
plot(showStop and longStop ? longStop : na, color=color.new(color.green,0), title="Long Trailing Stop")
plot(showStop and shortStop ? shortStop : na, color=color.new(color.red,0), title="Short Trailing Stop")
This is where the code is that is creating the error. Line 79 and 80.
low_mark = nz(min(low, low[1]), low)
high_mark = nz(max(high, high[1]), high)
bull_open = bearEngulfOpen
bear_open = bullEngulfOpen
mid_markL = (open[1] + low_mark) /2
mid_markH = (open[1] + high_mark) /2
long_stop = low_mark-round(atr)
//long_stop = round(longStop)
//short_stop = round(shortStop)
short_stop = high_mark+round(atr)
long_takeprofit1 = bear_open
short_takeprofit1 = bull_open
//long_takeprofit1 = (open[1] + (open[1] *.10))
//short_takeprofit1 =(open[1] - (open[1] *.10))
X_ = bar_index -1
if isBullEngulf
bullEngulfOpen := line.new(X_, open[1], bar_index, open[1], extend=extend.right, color=color.green)
bullEngulfLow := line.new(X_, low_mark, bar_index, low_mark, extend=extend.right, color=color.red)
bullEngulfMid := line.new(X_, mid_markL, bar_index, mid_markL, extend=extend.right, color=color.yellow)
bullEngulfStop := line.new(X_, long_stop, bar_index, long_stop, extend=extend.right, color=color.white)
bullEngulfProfit1 := line.new(X_, long_takeprofit1, bar_index, long_takeprofit1, extend=extend.right, color=color.gray)
buy_message_1 = syminfo.ticker + " " + " "+ "Buy 1(Open) = " + tostring(open[1]) + " Buy 2(Mid) = " + tostring(mid_markL) + " Buy 3(Low) = " + tostring(low_mark) + " Long Stop Loss = " + tostring(long_stop) + " Profit 1 = " + tostring(long_takeprofit1)
alert(message=buy_message_1)
if isBearEngulf
bearEngulfOpen := line.new(X_, open[1], bar_index, open[1], extend=extend.right, color=color.green)
bearEngulfHigh := line.new(X_, high_mark, bar_index, high_mark, extend=extend.right, color=color.red)
bearEngulfMid := line.new(X_, mid_markH, bar_index, mid_markH, extend=extend.right, color=color.yellow)
bearEngulfStop := line.new(X_, short_stop, bar_index, short_stop, extend=extend.right, color=color.white)
bearEngulfProfit1 := line.new(X_, short_takeprofit1, bar_index, short_takeprofit1, extend=extend.right, color=color.purple)
sell_message_1 = syminfo.ticker + " " + " "+ "Sell 1(Open) = " + tostring(open[1]) + " Sell 2(Mid) " + tostring(mid_markH) + " Sell 3(High) " + tostring(high_mark) + " Short Stop Loss = " + tostring(short_stop) + " Profit 1 = " + tostring(short_takeprofit1)
alert(message=sell_message_1)
from Recent Questions - Stack Overflow https://ift.tt/3iPlPkh
https://ift.tt/eA8V8J
Comments
Post a Comment