Greetings for the day.
@Tomasz I would like to exit all intraday trades based on the portfolio PNL , If possible can you some exit option based on the portfolio based in Amibroker 7.
SetPositionSize(1000000, spsValue);
SetCustomBacktestProc("");
// Trading System Logic
ShortEMAPeriod = 10;
LongEMAPeriod = 50;
ShortEMA = EMA(Close, ShortEMAPeriod);
LongEMA = EMA(Close, LongEMAPeriod);
Buy = Cross(ShortEMA, LongEMA) AND TimeNum() < 151500;
Sell = TimeNum() >= 151500;
if (Status("action") == actionPortfolio)
{
bo = GetBacktesterObject(); // Get the backtester object
bo.PreProcess();
for (bar = 0; bar < BarCount; bar++)
{
bo.ProcessTradeSignals(bar);
CurEquity = bo.Equity;
if (CurEquity > HighestEquity)
{
HighestEquity = CurEquity;
}
// Check if the equity drops below 1% of the highest equity
if (CurEquity < 0.99 * HighestEquity)
{
for (openpos = bo.GetFirstOpenPos(); openpos; openpos = bo.GetNextOpenPos())
{
bo.ExitTrade(bar, openpos.Symbol, openpos.GetPrice(bar, "C"));
}
}
}
bo.PostProcess();
}
// Plot signals and portfolio metrics
Plot(Close, "Close", colorBlack, styleCandle);
Plot(ShortEMA, "Short EMA", colorBlue, styleLine);
Plot(LongEMA, "Long EMA", colorRed, styleLine);