简体   繁体   中英

"cross", crossunder and crossover function of pinescript in python

I am trying to convert a pine script into python.

in pine I use function cross, crossunder and crossover for checking the if a particular series has crossed the other (say sma and ema crossing) over other to arrive at entry positions for stock.

I am not able to find equivalent function in python.

can anybody help me with that?

I use these ones. Works for me.

import pandas as pd

def crossover_series(x: pd.Series, y: pd.Series, cross_distance: int = None) -> pd.Series:
    shift_value = 1 if not cross_distance else cross_distance
        return (x > y) & (x.shift(shift_value) < y.shift(shift_value))

def crossunder_series(x: pd.Series, y: pd.Series, cross_distance: int = None) -> pd.Series:
    shift_value = 1 if not cross_distance else cross_distance
    return (x < y) & (x.shift(shift_value) > y.shift(shift_value))

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