Updated
This is caclulating the pct change from when the trade was opened and setting the Sell variable to the results of each function accordingly.
function sell_below10() {
return Close < HHV(High,20) * 0.9;
}
function sell_abv10() {
return Close < HHV(High,20) * 0.8;
}
Buy = Cross(Close, MA(Close, 50));
openPrice = Ref(Close, -BarsSince(Buy));
pctChange = IIf(openPrice == 0, 0, (openPrice - Close) / openPrice) * 100;
Sell = IIf(pctChange > 10, sell_abv10(), IIf(pctChange < 10, sell_below10(), False));
The easiest way is to use stop loss and profit stops then you wouldn't have to calculate the percentages yourself. Set your buy and sell signals like you normally would and add the stops.
Buy = ExRem(YourBuySignal, YourSellSignal);
Sell = ExRem(YourSellSignal, YourBuySignal);
ApplyStop(stopTypeLoss, stopModePercent, 10);
ApplyStop(stopTypeProfit, stopModePercent, 10);