Lipi Reference Lipi

Functions

talib.cross()

This function detects when one series crosses over or under another series. It is commonly used for trend-following strategies, moving average crossovers, and indicator signals.

Syntax

                talib.cross(series float source1, series float source2) → series bool
              

Arguments

source1 required series float First data series.
source2 required series float Second data series.

Return Type

series bool

Example


          indicator("MACD Crossover Strategy", overlay=true)
// MACD parameters
fastLength = input(12, title="Fast EMA Length")
slowLength = input(26, title="Slow EMA Length")
signalSmoothing = input(9, title="Signal Smoothing")
// Compute MACD components
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)
// Detect crossovers
bullishCrossover = talib.cross(macdLine, signalLine)
bearishCrossover = talib.cross(signalLine, macdLine)
// Plot Buy and Sell signals
plotshape(bullishCrossover, location=location.belowbar, color=color.green, shape=shape.labelup, title="Buy Signal")
plotshape(bearishCrossover, location=location.abovebar, color=color.red, shape=shape.labeldown, title="Sell Signal")