I am trying to rewrite this code to Python: src = input.source(close, "Source") volStop(src) => var max = src var min = src max := math.max(max, src) min := math.min(min, src) [max, min] [max, min] = volStop(src) plot(max, "Max", style=plot.style_cross) Precisely I have a problem with these lines: max := math.max(max, src) min := math.min(min, src) In Python I have a function, leta call it func1, and I want to get the same result the Pinescript is returning. I have only tried for loop since from what I understand calling a function in Pinescript works kind of like for loop. And I tried to replicate the calculation but I couldn't achieve the expected results. This is the line that is being plotted on Tradingview: And this is the line that is being plotted in Python: the area that is framed with red square is the approximate area that is visible on Tradingview screenshot. My current code: maxmin = pd.DataFrame() maxmin["max"] = price_df[f"{name_var}"] maxmin["min"] = price_df[f"{name_var}"] for i in range(price_df.shape[0]): maxmin["max"].iloc = max(maxmin["max"].shift(1).fillna(0).iloc, price_df[f"{name_var}"].iloc) maxmin["min"].iloc = min(maxmin["min"].shift(1).fillna(0).iloc, price_df[f"{name_var}"].iloc) The name_var variable is set to 'Close' column. How can I rewrite the Pinescript code to Python to get the same results? Continue reading...