I am using Amibroker v6.3
I would like to find out the profit percentage of a trade taken during backtest, then adjust the sell criteria accordingly. When profit is below 10%, I want to use this function sell_below10(). When profit is >10%, then use function sell_abv10().
How can the profit percentage of a trade be detected during backtest so that I can use the right sell function accordingly?
Thank you.
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);