Possible to use ParamField for multi timeframe?

Hello. I am trying to plot Hourly Moving Avg on 5 minute spread chart. Is it not possible to use ParamField function and then use TimeFrameSet?

Please guide on what's the correct way to code a common multi-tf EMA which can be applied on price chart or a spread chart. Please note: using PriceField with TimeFrameSet is not looking possible even on a normal price chart (not just spread chart)

Trying to explain the issue below:

Presented below are the charts and EMA codes used.

The one right below is showing the EMA incorrectly when using PriceField function. (code presented after the screenshot)

Common MA

P = ParamField( "Price field", -1 );

per = Param( "EMA Period", 20, 5, 500, 1 );

TimeFrameSet( inHourly );
m = Ref( EMA( P, per ), -1 );
TimeFrameRestore();

m = TimeFrameExpand( m, inHourly );

Plot( m, "EMA " + per, colorWhite, styleThick + styleNoRescale );

.
.
Now, the screenshot below is the accurate one, which is the result of directly using "Close".

Close MA

The code for which is

per = Param("EMA Period",20,5,500,1);

TimeFrameSet(inHourly);
m = Ref(EMA(C,per),-1);
TimeFrameRestore();
m = TimeFrameExpand(m, inHourly);

Plot(m,"EMA "+per,colorWhite,styleThick+styleNoRescale);

As you can see, the spread chart is using "Close" of the stock (I know why - as the spread is not a symbol). And, price chart is, of course, showing the EMA correctly.

But then how do I :
a.) Use ParamField with TimeFrameSet
b.) So that I can use it on spread charts and normal price charts

Thanks for your time. Your help is appreciated :slight_smile:

It is possible. You are not doing it correctly.
You have to put Paramfield within TimeFrameSet procedure!
It returns array.

per = Param( "EMA Period", 20, 5, 500, 1 );

TimeFrameSet( inHourly );
P = ParamField( "Price field", -1 );
m = Ref( EMA( P, per ), -1 );
TimeFrameRestore();

m = TimeFrameExpand( m, inHourly );

Plot( C, "Price", colorDefault, styleBar );

Plot( m, "EMA " + per, colorWhite, styleThick + styleNoRescale );

But it is still drawing it incorrectly...

Common MA still unsolved

per = Param( "EMA Period", 20, 5, 500, 1 );

TimeFrameSet( inHourly );
P = ParamField( "Price field", -1 );

m = Ref( EMA( P, per ), -1 );
TimeFrameRestore();

m = TimeFrameExpand( m, inHourly );

Plot( m, "EMA " + per, colorWhite, styleThick + styleNoRescale );```

No, it doesn't!

It plots same result as inserting e.g. C if Paramfield is set to Close!

8


It plots differently if being put outside of TimeFrameSet procedure!

8

You apparently have still old version applied.

POST YOUR ENTIRE CODE!
You have some other stuff in there as can be seen in your picture.

Open ParamField window and set to CLOSE there!

8

Default value of ParamFiled is set to -1 in your case. So it is used array of indicator that was overlayed first (your 5-min price plot).

In addition set to value 3 in code and apply. So Close is used immediately on new overlay next time.

per = Param( "EMA Period", 20, 5, 500, 1 );

TimeFrameSet( inHourly );
P = ParamField( "Price field", 3 );
m = Ref( EMA( P, per ), -1 );
TimeFrameRestore();

m = TimeFrameExpand( m, inHourly );

Plot( C, "Price", colorDefault, styleBar );

Plot( m, "EMA " + per, colorWhite, styleThick + styleNoRescale );
1 Like

I couldn't upload the video here. Please have a look at this.

Watch my video(s) carefully.

You have to apply THIS CLOSE (4th from top) and no other!

34

Not bottom one.
In your video you set bottom one (which calls array from indicator inserted first - as mentioned already! -).

In addition you once again use -1 in code.
Set to value 3 in code.

Do you listen?

per = Param( "EMA Period", 20, 5, 500, 1 );

TimeFrameSet( inHourly );
P = ParamField( "Price field", 3 );
m = Ref( EMA( P, per ), -1 );
TimeFrameRestore();

m = TimeFrameExpand( m, inHourly );

Plot( C, "Price", colorDefault, styleBar );

Plot( m, "EMA " + per, colorWhite, styleThick + styleNoRescale );

If I put 3 instead of -1 will it work on the spread chart? Do you listen?

What about you get upper code right FIRST?!

I guess you read books from end to start in addition.

So do you get it properly for standard price plot (your first chart pane) with the code I posted or not???
I expect some confirmation. Just demanding is no go.


As for spread chart you have to modify spread chart because if pricefield is set to value -1 then it refers to plotted array of first inserted indicator (if there is one)!

So modified Spread chart is like this... then it works with ParamField in TimeFrameSet if "...Spread chart... MTF" is selected in Param window's Pricefield. (Follow carefully!)

_SECTION_BEGIN("Spread Chart (MODIFIED FOR PARAMFIELD AND MTF)");
// Original code by AMIBROKER.COM
// Modified for Multitimeframe and ParamField overlay (fxshrat@gmail.com)
// https://forum.amibroker.com/t/possible-to-use-paramfield-for-multi-timeframe/30773/10
GraphXSpace = Param( "GraphXSpace", 0, -50, 100, 1 );

_N( Symbol2 = ParamStr( "Symbol2", Name() ) );
Mode = ParamToggle( "Mode", "Difference (Symbol1-Symbol2)|Ratio (Symbol1/Symbol2)" );

Color = ParamColor( "Color", colorDefault );
Style = ParamStyle( "Style", styleLine, maskPrice );

// FOR PARAMFIELD CALL OF COMPRESSED MTF PLOT (START)
TimeFrameSet(inHourly);
C1 = C;
H1 = H;
L1 = L;
O1 = O;
V1 = V;
OI1 = OI;
RestorePriceArrays();

SetForeign( Symbol2, True, True );
TimeFrameSet(inHourly);
C2 = C;
H2 = H;
L2 = L;
O2 = O;
V2 = V;
OI2 = OI;
RestorePriceArrays();
// FOR PARAMFIELD CALL OF COMPRESSED MTF PLOT (END)

// Just dummy line to prevent warning message
x = TimeFrameExpand(1, inHourly);

// FOR VISUAL PLOT OF SELECTED TIMEFRAME ARRAY(S)
SetForeign( Symbol2, True, True );
C3 = C;
H3 = H;
L3 = L;
O3 = O;
V3 = V;
OI3 = OI;
RestorePriceArrays();

if ( Mode ) {    
    PlotOHLC( O1 / O2, H1 / H2, L1 / L2, C1 / C2, "(" + Name() + " / " + Symbol2 + ") spread MTF", Color, styleNoDraw | styleOwnScale | styleNoTitle);
    PlotOHLC( O / O3, H / H3, L / L3, C / C3, "(" + Name() + " / " + Symbol2 + ") spread", Color, style );
} else {    
    PlotOHLC( O1 - O2, H1 - H2, L1 - L2, C1 - C2, "(" + Name() + " - " + Symbol2 + ") spread MTF", Color, styleNoDraw | styleOwnScale | styleNoTitle);
    PlotOHLC( O - O3, H - H3, L - L3, C - C3, "(" + Name() + " - " + Symbol2 + ") spread", Color, style );
}
_SECTION_END();
1 Like

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