You can get the bar index of the trade by using ValueWhen and the trade's entry
date as follows (from within custom backtester code):
bars = BarIndex();
dates = DateTime();
bo = GetBacktesterObject();
...
for ( trade = bo.getFirstOpenPos(); trade; trade = bo.getNextOpenPos() )
{
entryBar = LastValue( ValueWhen( trade.EntryDateTime == dates, bars )
);
...
There may be a better way of handling your stop loss, but the above should
should at least answer your question.
Mike
--- In [email protected], "broman1003" <fredrik_broman1...@...> wrote:
>
> Hi,
> I would like to get hold of the bar where a trade was entered when
> backtesting.
> The reason I need it is that I would like to implement a trailing SL that is
> depending on the highest value the price has hit since the trade was
> initiated.
>
> All hints are appreciated.
> Thanks,
> /Fredrik
>