Hi, looking for the way to limit trades if equity for single symbol drops below initial value. Equity() does not work for me. Interpretation shows correct equity value (below initial value) but backterster takes another trade anyway.
Is it because Equity() values are filled only after backtest is complete?
What should I use to make it working?
SetChartOptions(0, chartShowArrows|chartShowDates);
_N(Title = EncodeColor(colorGold) + StrFormat("{{NAME}} - {{INTERVAL}} | {{DATE}} | O %g | H %g | L %g | C %g | V %.10g |\n{{VALUES}}", O, H, L, C, V));
Plot(C, "Close", IIf(C > O, colorBrightGreen, IIf(C < O, colorRed, colorWhite)), styleCandle|styleNoTitle);
Plot(EMA(Close,50), "MA50", colorDefault, styleDashed);
SetPositionSize(1000, spsValue);
SetOption("InitialEquity", 100000 );
Short = Cover = Buy = Sell = 0;
Short = Cross(Close, MA(Close, 50)) AND Equity() >= 100000;
ApplyStop( stopTypeLoss, stopModePercent, 10, True );
ApplyStop( stopTypeProfit, stopModePercent, 3, True );
printf("Equity %g", Equity());
Reading the manual saves hundreds of hours and dozens of questions that are answered already.
Equity is an IN-LINE BACKTESTER-IN-A-BOX. It performs single-symbol backtest using OLD backtester (without scaling in/out) at the place when it is called.
You are calling Equity TWICE in your formula and it performs single symbol equity TWICE. First time WITHOUT ApplyStops (because first call is BEFORE ApplyStop) and second time AFTER ApplyStops (because second call to Equity is AFTER ApplyStop). So you get TWO DIFFERENT backtest results and TWO different equities. This way you are confusing yourself and don't understand what you are doing.
To get better understanding of what is happening in your code and how functions work, use advice given here: How do I debug my formula?