I'm trying to make a strategy that will buy and sell right on pivots. Don't rush with conclusions, I know it can't be used in real trading ;) The idea is, that we can use the perfect buy signals based on pivots, to look for the custom sell signal which will not be affected by bad buy signals, and vice versa.
I tried many different approaches, but the signal comes with delay equal to the length of the pivot. How can we force the buy/sell condition right at the bar where pivot was detected? Thank you!
P.S.: Here is what must be closest to the solution, but it still doesn't work
legs = input(17)
pHi = pivothigh(legs, legs)
pLw = pivotlow(legs, legs)
longCondition = bar_index[barssince(pLw)]
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = bar_index[barssince(pHi)]
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)