Deleting Composites

Hello, I've created a composit with the AddToComposite-method.
Is it possible to remove this composite inside AFL?

See Category Remove Symbol.

Unfortunately your question does not provide all necessary details to give you proper answer. Please follow this advice: How to ask a good question

Describe the GOAL. Show your own effort and show the formula.

Chances are you don't really need to "remove" composite. If you want to recreate or create a new composite in place of old one, you just run another AddToComposite with SAME name because by default it removes old content automatically as new composite is created.

So DESCRIBE GOAL, WHY do you need to remove it. And WHY from AFL?

Removal of symbols from AFL is possible via OLE interface, but as I wrote, your question is lacking background info.

1 Like

Hello,

thanks for your answer. I will explain the problem:
I am using composite to share information from AFL-Code zu a custom backtester.

Inside the AFL-code a price for an initial stop (for risk- and moneymanagement) is calculated and set as a composite:
AddToComposite(initialStopLine_value, "~initialStopLine" + Name(), "X", atcFlagDeleteValues | atcFlagEnableInBacktest);

The custom backtester uses this information to calculate the corresponding position size:

SetCustomBacktestProc("");
if( Status("action") == actionPortfolio ) {
bo = GetBacktesterObject();
bo.PreProcess();

for (i = 0; i < BarCount; i++) {
	for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i)) {
		if (sig.IsEntry()) {
			initialStopLineForeign = Foreign("~initialStopLine"+sig.Symbol, "X");
			initialStopLine = initialStopLineForeign[i];

			if (sig.IsLong()) {
				risikoSpanne = sig.Price - initialStopLine;
			} else {
				risikoSpanne = initialStopLine - sig.Price;
			}
			basisRisiko = risikoProzent/100 * bo.Equity;
			numberOfShares = basisRisiko / risikoSpanne;
			sig.PosSize = int(numberOfShares * sig.Price);
		}
	}
	bo.ProcessTradeSignals(i);
}

bo.PostProcess();

}

After backtest these composites still exist. E.g. "~initialStopLineAAPL". There in none need to keep them and I wantet to remove these composites inside the AFL code after the execution of the custom backtester.

Regards
Detlev

Don't use ATC (AddToComposite) and Foreign but use Static variables.

StaticVarSet("~initialStopLine"+Name(), initialStopLine_value);

And then in CBT

initialStopLineForeign = StaticVarGet("~initialStopLine"+sig.Symbol);

Thank you.
But according to the documentation ( AFL Function Reference - STATICVARSET (amibroker.com)) for static vars there is a limitation:
"static array variables store only as many bars as there are currently in use by given chart"

But I need to store all bars.

You misinterpret.
This refers to charting with QuickAFL enabled.

Simply do as it was written and use static vars.
If you would have read knowledge base articles you would know how to pass variables from 1st phase to 2nd phase.

2 Likes

Also you should read below for risk based position sizing without CBT.

Yes, I know. But with CBT I have more control and can log information about the backtest process.
Thank you very much for your help!

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.