One symbol exit(Sell) trigger entry(Buy) for two symbols

image
When one symbol1 exits(Sell) it trigger entry of symbol2(Buy) & symbol3(Buy). Exit of symbol2 trigger entry of symbol4 & symbol5.

Trying to implement option multileg strategy. Or entering in one stock based on its exit entering other stock.

How to implement it in amibroker for backtesting.

Begin by writing some code. Test it. Post it here if further assistance is needed.
Please follow this advice: How to ask a good question

Used the help of this topic for two symbols, Buying a given asset instead of cash for empty positions - #2 by durga [by Tomasz]
Further written code for third symbol

`Symbol1 = "Sym A";
Symbol2 = "IEF";

// symbol1 generates buy / sell rules
SetForeign( Symbol1 );
Buy = ... your normal buy rules
Sell = ... your normal sell rules
RestorePriceArrays();

n = Name();

if( n == Symbol2 )
{
// for IEF use REVERSE rules
tmp = Buy;
Buy = Sell;
Sell = tmp;
Symbol3 = writeif(sell, symbol4, writeif(Buy, symbol5, ""));
}
if( n == Symbol3 )
{
// for IEF use REVERSE rules
tmp = Buy;
Buy = Sell;
Sell = tmp;
}
`
Implemented formula using above method, for two symbol results were ok. But when included the third symbol in AFL for Backtest in a watchlist, then it is not giving results for third symbol

When posting the formula, please make sure that you use Code Tags (using </> code button) as explained here: How to use this site.

Using code button

Code tags are required so formulas can be properly displayed and copied without errors.

Used the help of this topic for two symbols, Buying a given asset instead of cash for empty positions - #2 by durga [by Tomasz]
Further written code for third symbol

Symbol1 = "Sym A";
Symbol2 = "IEF";

// symbol1 generates buy / sell rules
SetForeign( Symbol1 );
Buy = ... your normal buy rules
Sell = ... your normal sell rules
RestorePriceArrays();

n = Name();

if( n == Symbol2 )
{
// for IEF use REVERSE rules
tmp = Buy;
Buy = Sell;
Sell = tmp;
Symbol3 = writeif(sell, symbol4, writeif(Buy, symbol5, ""));
}
if( n == Symbol3 )
{
// for IEF use REVERSE rules
tmp = Buy;
Buy = Sell;
Sell = tmp;
}

Implemented formula using above method, for two symbol results were ok. But when included the third symbol in AFL for Backtest in a watchlist, then it is not giving results for third symbol

your test formula does not work. buy and sell are not defined. symbol3 is unknown.

Symbol1 = "ASIANPAINT-I";
Symbol2 = "BHARTIARTL-I";
Symbol3 = "DIVISLAB-I";
Symbol4 = "HCLTECH-I";
Symbol5 = "ICICIBANK-I";

// symbol1 generates buy / sell rules
SetForeign( Symbol1 );
Buy = C > MA(C, 50);
Sell = C < MA(C, 50);
RestorePriceArrays();

n = Name();

if( n == Symbol2 )
{
// for symbol2 use REVERSE rules
tmp = Buy;
Buy = Sell;
Sell = tmp;
Symbol3 = writeif(Sell, symbol4, writeif(Buy, symbol5, ""));
}
if( n == Symbol3 )
{
// for symbol3 use REVERSE rules
tmp = Buy;
Buy = Sell;
Sell = tmp;
}

Third symbol (n==symbol3) does not give results if backtest is done on a watchlist of 5 symbols.

This idea was taken from this topic for two symbols, Buying a given asset instead of cash for empty positions - #2 by durga [by Tomasz]

How one symbol exit(sell) trigger entry(buy) for other symbol, if used in a continuous basis.

where is your entry for symbol1? What happens when you exit symbol4?

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