Trading with condition on stock and index

I have formula:

//index
SetForeign("index(full)"); 
Plot( MA(Close,2), "ma 2", colorRed,styledots ); 
RestorePriceArrays(); 

//stock
//Buy=stock condition AND index condition

My "stock" have holes and holes are removed also on "index", so MA() on "index" have another values. Why? Do I have to check "Pad and align" in Analysis to get properly values?

image

Below is an excerpt from the Comments section in the Foreign() documentation. SetForeign() behaves the same way.

AFL Function Reference - FOREIGN

Foreign function synchronizes the data file
you are referencing with the currently selected symbol.

Synchronization makes sure that EACH bar of FOREIGN data
matches exactly with each bar of currently selected symbol.

I understood it as "array MA() calculated on foreign symbol is taken and matched to current selected array" but not "foreign OHLC is taken and new MA() is calculation on this matched array".

The phrase "EACH bar of FOREIGN data" is definitely referring to the OHLC data, so your original understanding was incorrect.

1 Like

It is a strange solution, becouse when I want to use real calculation for Index I have to use "Pad and align...", but all holes of a stock are filled by its previous close, so all calculation on stock are disturbed.

It is not "strange" by any measure. If there is a non-trading day for particular stock what price is for that day? The LAST KNOWN. It is pretty much common sense that the "last known" price is the one that is current in any given time. Now if you mix data from different symbols you obviously want the data in sync, otherwise you would end up in chaos.

So, no it is not strange. The same technique (syncing) is done in so many areas of engineering including audio, video, automotive, radio, digital signal processing, music and pretty much everything else.

While you can have any opinion on any matter, watch out for Dunning–Kruger effect - Wikipedia

Let's figure out that 3 days are missing. Your tech fills it with the previous "Close" and hypothetically can trigger a buy signal that you cannot actually make (e.g. symbol is suspended for those 3 days or there was just no one willing to buy). Of course, the signal will cause you to be the first to buy, but that signal will be created by hypothetical OHLC values.
I would like to be able to match real index values (e.g. moving average) to such a symbol "with holes". Of course this is possible by using "Pad and align", but as I wrote, I would to like use it without "stretching" the second symbol and filling in.
Of course, this is just a backtest and some conclusions should be drawn by own.

You could just write a little utility to run against the full set of Index price data, calculate the MA, and save it as a static variable or write it to the database using AddToComposite(). Then when you run your strategy code, you will retrieve the index MA values you saved in the utility. The result will be what you were originally expecting as per your first post.

2 Likes

It was only example, my code is much more complex, but of course nothing is impossible.

As @mradtke wrote you, ANY indicator of ANY complexity can be stored in static variable and you can get what you wanted originally. This is essentially "holding and padding" indicator values instead of padding prices. With AmiBroker you can do both.

2 Likes

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