简体   繁体   中英

How to get close price of bar when my boolean criteria is met?

I've created some criteria that creates a shape on the chart; now I need to know if the close price of the next candle is higher than the close price of the candle where my callSignal shape occurs.

Currently getting this error, which makes sense:

line 177: Cannot call 'operator <' with arguments (series[bool], series[bool]); available overloads: <(float, float) => bool; <(input float, input float) => input bool; <(const float, const float) => const bool; <(float, series[float]) => series[bool]; <(series[float], float) => series[bool]; <(series[float], series[float]) => series[bool];

Here is my code:

// ... //
expiryLength = 1
callSignal = Cond1[1] ? na : Cond1 and rightTime? Cond1 : na
putSignal = Cond1[2] ? na : Cond2 and rightTime? Cond1 : na

plotshape(callSignal, style=shape.triangleup, location=location.belowbar, size=size.tiny)
plotshape(putSignal, style=shape.triangledown, location=location.abovebar, size=size.tiny)

// This is the part I am struggling with... //
callWL = callSignal[expiryLength] < callSignal
plotshape(callWL, size=size.large)

I don't know how to incorporate close within my callWL variable, or if I just need to rework this further.

Here's a sample script that generates call entries whenever price crosses SMA 30 from below and after expiryLength bars, plots a shape for gain/loss.

//@version=4
study("Call lookback", overlay=true)

_expiryLength = input(title="Expire length in bars", type=input.integer, defval=10, minval=1)
_callSma = input(title="Call entry SMA period", type=input.integer, defval=30, minval=1)
_callSignal = false

// Make call entries
_callSignal := crossover(close, sma(close, _callSma))
plotshape(_callSignal?close:na, style=shape.triangleup, location=location.belowbar, size=size.tiny)

// Lookback for call entry and draw a symbol for gain/loss
_callWL = _callSignal[_expiryLength]
_color = close > close[_expiryLength]?color.green:color.red
plotshape(_callWL?close:na, color=_color, size=size.tiny)

plot(sma(close, _callSma))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM