Basket of 2 instruments, use second as a helper for entries on the first

Hi, in terms of exploration, I've got following code:

Buy = Short = Cover = Sell = Test = 0;

if(Name() == "HelperTicker") {
Test = Close < 20;

if(Name() == "MainTicker") {
Sell = 1;
Buy = Foreign("HelperTicker", "Test");

SetOption("HoldMinBars", 3);

AddColumn(Buy, "Buy");
AddColumn(Sell, "Sell");
AddColumn(Test, "Test");

Filter = Buy OR Sell OR Test;

As you can see, the idea is to trigger a long position on MainTicker every time Close of HelperTicker is under 20, and rely on "Foreign" function to do that.
Still, it doesn't work - anything wrong that can be spotted on the above? What happens, is Buy for MainTicker never gets set to 1, although Test column for HelperTicker is almost always 1.


Your code is wrong.
First there is no "Test" price field (in Foreign call)
Second, you are assigning PRICE to boolean (Buy variable). You should assign Boolean.

Correct code is just

Buy = Foreign("HelperTicker", "C" ) < 20;
Sell = 0;

Just these two lines. You don't need anything else.

And as long as you only trade "MainTicker" you should run your backtest on that single ticker. Whenever formula references other tickers does not matter.

More on that subject in KB: AmiBroker Knowledge Base » Broad market timing in system formulas

1 Like

understand the above won't create an array (Test), rather than a simple boolean variable?

How would I create an array (thought something like "test = Close" does it) in one ticker's execution thread, that I could access in another ticker's execution thread?

Objective is to do some more complex computations within "GOOG" bars time-series and use the output (in form of array of values, one per bar) in "FB" ticker to issue orders.

Your above example is great as long as you rely on HelperTicker's O,H,L,C,V arrays alone (or simple derivatives).

Just Read the KB article. You can have as complex calculation as you can imagine. It does not matter. The method is the same. Read the KB. General pattern i

// ANY complex calculations you want (done on GOOG)
varA = ... whatever
varB = ...whatever

// here you are back with FB data
Buy = ... any condition based on whatever you wish including varA and varB calculated

This is essentially what KB article explains. So just read it.

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