The goal is to sell at first positive open after buy. Using Norgate platinum EOD OLHC data. In backtesting, this code with any generic buy condition results in multiple exits for a loss (no same bar entry/exit ). Also several positions held beyond the first positive open. I would expect the position to either remain open or exit above buyprice.
What additional code is needed to accomplish the goal?
PO = Open > Buyprice;
Sell = PO;
Buyprice = Close;
Sellprice = Open;
use ApplyStop profit target instead of your coding
One comment regarding your idea: exiting on first positive open is a recipe for guaranteed disaster as you are NOT accepting profits, but accepting huge drawdowns.
Instead of buyprice, try the valuewhen() function for tracking the close price at buy. Need Exrem() function for buy/sell for valuewhen() to get rid of excess buy signals.