Course Name: Short Selling in Trading, Section No: 7, Unit No: 11, Unit type: Notebook
Hello, as we're here obtaining the last swing low this should be:
(last_swing_low_date != data.loc[last_swing_low_date:, "swing_low"].idxmin())
Instead of .idxmax()?
Imgur: The magic of the Internet
Can you explain more clearly what we want to achieve with this adjustment?
Hi Daniel,
To make sure that the high and low swings are alternate, from the last high dates it checks for all the dates till the current date of the window. And then it finds the most latest date from it using idxmax() and tries to match it to last_swing low_dates, if there is a match then that low_swing date is consistent. Otherwise, it is changed to NaN. If we use idxmin() then it will not find the latest date to match as it would find the earliest date with the minimum value.
Hope this helps.