Plot MA of foreign symbol's Highs

What is wrong with the code below.

It only shows the foreign price chart but not the MA of highs.

It’s for an index health check. I look at the moving average of the monthly highs rather than the MA of the closing price.

_SECTION_BEGIN("Price");
Ticker = ParamStr("Symbol", "SPY" );
PlotForeign( Ticker, Ticker, ParamColor("Color", colorCycle ), ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("MA OF HIGHS");
Ticker = ParamStr("Symbol", "SPY" );
P = ParamField("Price field", -1);
Periods = Param("Periods", 4, 2, 40, 1 );
TickerHigh = Foreign("Ticker", "P", True);
Plot( MA( TickerHigh, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); 
_SECTION_END();

Thanks in advance.

1 Like

Your 2nd argument of Foreign() function is wrong, see documentation https://www.amibroker.com/guide/afl/foreign.html

You can not use “P”.

Instead of using paramfied you may do this

P = ParamList("Price field", "O|H|L|C|V|I");

You’ve solved it @fxshrat, thank you.

This is the working foreign MA with variable OHLC parameters.

_SECTION_BEGIN("MA OF HIGHS");
Ticker = ParamStr("Symbol", "XNT" );
P = ParamList("Price field", "O|H|L|C|V|I");
Periods = Param("Periods", 4, 2, 40, 1 );
TickerHigh = Foreign(Ticker, P, True);
Plot( MA( TickerHigh, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); 
_SECTION_END();