Different pad and align behaviour for setforign

Hi, I ran in to an issue with setforign. I use a for loop to go through all the Tickers.
`if ( Status("stocknum") == 0 )
{
for ( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
{

	SetForeign ( Symbol );
}

}`
I have PadAndAlign turned on.
On the wery first ticker in my watchlist the PadAndAlign fills the dataholes with previous O,H,L,C values but on all the other Tickers it fills the data holes with previous Close values on O,H,L,C.

From the documentaion I understand that I can not use setforign on "current ticker" and make it fill the data holes with previus close values.

So my question is, how can I PadAndAlign current ticker with previous Close values instead of getting previous O,H,L,C values. At this point current ticker is calculated differently than all the other Tickers that I reference with SetForign.

What document states that?

See SetForeign.

Unfortunately your question isn't clear enough to give you an answer.

Describe the GOAL What do you REALLY want to achieve, the FINAL GOAL, not the step you are blocked on.

Please follow this advice: How to ask a good question

Alignment needs to be done to something, you can't align same symbol to itself because it is pointess and there are no "holes" with respect to itself.
"Holes" are data points that are MISSING as compared to reference symbol.

1 Like

Hi, according to Foreign i can only set other then current. This is also how the system behaves. I cant aligign to self and that is why previous O,H,C,L is used instead of Previous Close value on all of the quotes (O,H,L,C) when PadAndAlign is set.

Hi and thanks for your quick reply!
My goal is that I whant to run through all the tickers in my Watch list and get the ADX value from each ticker. All this ADX values are grouped and from that I belive that I can find a trend in the market. (for instance, if 6 out of 10 tickers have an adx > 60 do trades

To enhance the performance I only make this rating on the first ticker.

if ( Status("stocknum") == 0 )
{
  for ( n = 0; ( Symbol = StrExtract( List, n ) ) != ""; n++ )
    {
	SetForeign ( Symbol );

        nrPosAdx=StaticVarGet ("nrPosAdx");
	nrTotAdx=StaticVarGet ("nrTotAdx");

        valDataAdx = Adx( adxVal );
	nrPosAdx += IIf(IsTrue(valDataAdx) && valDataAdx >60, 1,0);  
	nrTotAdx += IIf(IsTrue(valDataAdx), 1,0);
		
		StaticVarSet (  "nrPosAdx", nrPosAdx);
		StaticVarSet (  "nrTotAdx", nrTotAdx);
    }
}

//Here is the actual code that makes trades on the above "trend"

This works perfect and as expected for all other tickers then Status("stocknum") == 0. Data holes are filled with previous data Close price. (I have created a fictive ticker called AllWeekDays that holds a value for all mon-fri). But for Status("stocknum") == 0 (first and current ticker) the set forign doesn't work as expected. In fact it probebly doesnt setForign at all at this point becourse setForign(Name()) doesnt make any sence. But the problem remains, current ticker is padded towards my fictive Ticker but missing dates are filled with previous O,H,L,C values instead of only Close values. I would like to find a solution where I can fill the current ticker with C values instead so that the order of the Tickers in my Watch List doesnt change my result.

I hope that my question is clear and that there is some workaround for this. Maybe add my fictive ticker in to the Watch list and some how make that ticker the first Ticker that passes through and then some how remove that ticker from the rest of the calculation?? But hopefully there is an easier way.

No, just don't "enhance" anything. All ideas to "enhance" anything are just bad. What you are doing is complete nonsense because it will DECREASE performance as it effectively runs in single thread instead of many threads.

SetForeign in a loop is SUPER BAD for performance
It is the WORST thing you can do.

DO NOT DO THAT !

In fact newest version 6.40 will issue a WARNING if you are doing such bad coding.

Calculate ADX normally for every symbol alone. Read about composites and StaticVarAdd and use the code from the MANUAL (see example)

http://www.amibroker.com/f?staticvaradd

if( status("stocknum") == 0 )
{
     // remove any earlier composite values
   StaticVarRemove("~nrPosAdx");
}

StaticVarAdd( "~nrPosAdx", ADX() > 60 ); 
Buy = 0;

http://www.amibroker.com/guide/a_composites.html

Alternative way (SINGLE LINE of code!)

AddToComposite( ADX() > 60, "~AdxAbove60", "X"); 

Also, you are mixing up padding with foreign. What you want is padding (not foreign). While Foreign also does padding to "current" symbol, you don't really want foreign but padding, because SetForeign is no-action if specified symbol is the same as current one. Padding is done via "Pad and align to reference symbol" setting. Read the manual
http://www.amibroker.com/guide/w_settings.html

1 Like

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