Why are the current MA prices not matching the chart? Using AB Feedback Centre

Hi guys,

Could you please give me a sanity check here? I don't see what's wrong with this simple code. The attachment shows a plot of the RTY futures current contract with the 9 wma (colorGold) and the 20 ema (colorTurquoise) plotted on a 1 min chart connected to IB.

Look at the Interpretation debug output. Why aren't the current Refs for the moving averages not matching up with the current moving numbers you see in the Y-Axis of the price chart?

This is from the latest beta, 6.29.0 32 bit, but I can't believe this is a bug...must be some really dumb mistake on my part (thanks for telling me what it is!)

SteveMoving%20Average%20Mismatch

Do you see the purple vertical line ? It is called SelectValue.
Click last candle

2 Likes

@SteveH Numbers that you see in the Y-axis area, always refer to the last visible bar's values. On the other hand, readings in the Title, by default refer to the selected bar's values (if some bar has been selected, if not - these are also last visible bar's values). So using default Plot() function, you can see both readings at the same time.

If you want to see only last bar's readings in the Interpretation window (no matter which bar you select) you can use LastValue(wma9) and LastValue(ema20)

Compare :

https://www.amibroker.com/guide/afl/lastvalue.html

and:

https://www.amibroker.com/guide/afl/selectedvalue.html

1 Like

My intention is to use those moving averages in an AFL which is not related to a plot but rather just custom drawing using the Gfx routines. The MyPrice.afl shown in the pic is just for debug purposes to post here.

Wow, so I have to use LastValue(wma9) and LastValue(ema20) in my AFL because Ref() will be based off of the selected value (i.e. priece at vertical line in that pic) if the vertical bar is there but based off of last value if it's not.

I just read the docs for Ref(), SelectedValue() and LastValue() and this relationship is not mentioned.

I tell ya, I've been coding mainly in C# with NT7 so long that my bias was a price reference for something like a Close series always has the 0th item as the most recent value. I'm just now getting serious about building some real-time trading tools with Amibroker now that the GUI additions over the past several years have matured (even though I've owned and upgraded Amibroker since 2003).

Thanks for the quick replies!

No, Ref() function is not based on selected value (Ref() itself returns array of numbers but not just single number). But the thing is that string functions (such as printf, WriteIf, StrFormat, ) where you insert arrays (such as Ref() function returning array of numbers) as one of their function's arguments then it is not returned an array of strings but it is returned a single value representing current selected value (in charts). And if there isn't any array element selected then selected value == last value (being output by those string functions).

1 Like

On a separate note, I submitted a request for Tomasz to consider passing mouse wheel info to AFL's. It would be nice for easily scrolling custom grids (using Gfx routines) without having to (always) resort to the up/down arrow and paging keys.

Also, if the user is in a custom drawing window (which doesn't even plot prices) the option to disable the default behavior of the horizontal and scroll bars (other Plot panels get these events currently) would be nice. Same issue here with the paging and arrow keys.

If I'm building up a completely custom set of drawing GUI controls and Gfx routines and there happens to be a Plot panel above or below it, then when I'm in that custom pane, at times I wouldn't want the Plot pane to get the scrolling events from either the keyboard or mouse (if mouse wheel move events do get added...I hope).

Going on my historical experience with suggestions, I suspect that the mouse wheel events are a "maybe yes" and the other stuff is a "definite no".

I got an "immediate yes" from Tomasz one time...I'm one who suggested colorRGB().

Well @SteveH frankly I thought, that you were a beginner, because your initial question seemed rather basic :wink:

Where? Why haven't you reported it to the Feedback centre as a suggestion, so that other users could back you up? I'm very surprised, that so many users write about new features they would like to have and only few of them decide to make such suggestions and/or upvote other users' suggestions in the Feedback Centre. I would surely support it.

It is worth mentioning, that:

Some of my codes are also based solely on GFX functions and GUI buttons (an example) and I'm very interested in expanding AmiBroker's capabilities in this area. I've suggested implementing many new functionalities and some of them have been already introduced (or marked as Put on hold which might be a good sign). For example until now if you wanted to use 100% of chart window's area (no plots, no grids, no title, no divider between Y axis and chart area etc.) in your Gfx codes (more info here), the only way to do this was using GfxSetOverlayMode(2). This was working well, but you weren't able to use GfxSetZOrder() at the same time - which is very useful in case of complex codes. Thanks to the changes implemented in 6.29 that is no longer the case. That is just one of the latest examples showing, that reporting suggestions to the Feedback Centre may pay off...

3 Likes