How to select Highvalues of the candlestick with data source - activex

I always see the code as datasource="series0".
If series(0) is a candlestick and I want to use Highvalues or Closevalues of the candlestick, how so I select that data? Something like datasource="series0.Highvalues"? (It's worth noting that I use teechart2011 Eval and VB6).
If series(1) is the financial function ExpMovAvg, how to define the width of the ExpMovAvg line with code?
Similarly how do I use the Closevalues in Series(0) for this function? Not merely datasource="series0". Thanks !

I always see the code as datasource="series0", if series(0) is a candlestick and I want to use Highvalues or Closevalues of the candlestick,how to select that data? datasource="series0.Highvalues"? (I use teechart2011 Eval and VB6)
Here you have a simple example in VB6. You can assign any of the 4 ValueLists in the Candle series (Open, Close, High, Low) to the be used by the function with the MandatoryValueList.ValueSource property:
TChart1.AddSeries scCandle
TChart1.Series(0).FillSampleValues
TChart1.AddSeries scLine
TChart1.Series(1).SetFunction tfExpMovAvg
TChart1.Series(1).DataSource = TChart1.Series(0)
TChart1.Series(1).MandatoryValueList.ValueSource = "Close" '"Open" "High" "Low"
if series(1) is the financial function ExpMovAvg, how to define the
width of the ExpMovAvg line with code?
You can set the series' Pen.Width property as follows:
TChart1.Series(1).Pen.Width = 2
Similarly how to use the Closevalues in Series(0) for this function?
not merely datasource="series0", thanks !
This is the same above, isn't it?

Related

Format Altair choropleth map legend scale and tooltip

I am trying to make the tool tip 'Percentage' be an actual percent and not a decimal. Even when I include alt.Tooltip('Percentage:Q',format='.2%'), it doesn't seem to work.
Also, I am trying to make the legend scale from 0-100% instead of 40-70%.
Any help would be appreciated!
import altair as alt
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url, 'states')
variable_list = ['Percentage', 'State Name', 'state_id']
alt.Chart(states).mark_geoshape().encode(
color=alt.Color('Percentage:Q', title='Positive NFB', legend=alt.Legend(format=".0%"), scale=alt.Scale(scheme='yellowgreen')),
tooltip=['State Name:N', 'Percentage:Q', alt.Tooltip('Percentage:Q',format='.2%')]).properties(title="Percentage of People in Households with Positive NFB"
).transform_lookup(
lookup='id',
from_=alt.LookupData(states_positive_NFB, 'state_id', variable_list)
).properties(
width=500,
height=300
).project(
type='albersUsa'
)
Current map:
To change the domain of the color scale, you can pass the domain argument to alt.Scale(): e.g.
alt.Scale(scheme='yellowgreen', domain=[0, 1])
To make the tooltip format appear, you can remove the duplicated tooltip encoding, as the first one appears to be taking precedence. That is, rather than
tooltip=['State Name:N', 'Percentage:Q', alt.Tooltip('Percentage:Q',format='.2%')]
you should use
tooltip=['State Name:N', alt.Tooltip('Percentage:Q', format='.2%')]

How to order variables in Maxima?

I want to give variables a specific order in an equation in Maxima. This is display purposes only.
For example:
(%i1) E=(h*c)/%lambda;
c h
(%o1) E = -------
%lambda
I want the h and c variables to be in that order when displayed. I looked at ratvars() and ordergreat() but they don't appear to be relevant here.
Thanks for your help.
It appears that declare(<var>, mainvar) was what I was looking for. When mainvar attribute is declared for a variable it "succeeds all other constants and variables".
I was trying this using the STACK plugin for Moodle. I needed to remove the mainvar keyword from the forbidden list in the file casstring.class.php.
Actually, I think ordergreat() is the function you need, maybe you did a sorting before that needed unorder() first ro reset things.
Try
unorder()$ ordergreat (h, c)$ E=(h*c)/%lambda;
and
unorder()$ ordergreat (c, h)$ E=(h*c)/%lambda;

Remove legend bar in R using Image.Plot

This is the test code im using
x_coord <- c(1,2,3,4)
y_coord <- c(1,2,3,4)
value <- c(12,15,19,30)
foo <- data.frame(x_coord, y_coord, value)
library(MBA)
foo=foo[ order(foo[,1], foo[,2],foo[,3]), ]
mba.int <- mba.surf(foo, 300, 300, extend=T)$xyz.est
library(fields)
fields::image.plot(mba.int,legend.only = FALSE, axes=FALSE)
The axes part deletes the axis, but when i try to remove the legend bar, the vertical bar indicating the color measurements, it will not go away.
i have tried smallplot = 1, but that gives me an error but it gets rid of the vertical legend,
Anyone have any idea of how to get rid of the legend without any errors produced ?
If you don't want the color legend, just use the built-in image function instead. The function you are using is designed specifically for adding a legend easily.
If you want to keep the same color scheme as the fields image.plot function:
image(<your data>, ..., col = tim.colors())
Using this creates the exact same image without a legend.
The image and image.plot functions actually have quite different plotting functionality.
One problem (at least for me, trying to plot regional climate model data) with using the built-in image is that it cannot handle irregular grids. The image.plot function uses the poly.image function internally to create the plot. Both are included in the fields package. The good thing is that the poly.image function also can be used on its own, for example like this:
library("fields")
# create an example of an irregular 3x3 grid by adding random perturbations up to ±0.6
x <- matrix(rep(1:3,each=3) + 0.6*runif(9), ncol=3)
y <- matrix(rep(7:9,times=3) + 0.6*runif(9), ncol=3)
# 9 values, from 1 to 9
z <- matrix(1:9,nrow=3)
# Please avoid the default rainbow colours, see e.g.
# https://www.climate-lab-book.ac.uk/2014/end-of-the-rainbow/
# Other examples of colour schemes: https://colorbrewer2.org/
col <- colorRampPalette(c("#2c7bb6","#abd9e9","#ffffbf","#fdae61","#d7191c"))(9)
par(mfrow=c(1,3), mar=c(4,4,4,1), oma=c(0,0,0,0))
image(x=7:9,y=1:3,z,col=col, main="image()\n Only regular grid. Also note transposition.")
image.plot(x,y,z,col=col, main="image.plot()\n Always with colorbar.")
poly.image(x,y,z,col=col, main="poly.image()\n Does not include colorbar.")

matlab indexing into nameless matrix [duplicate]

For example, if I want to read the middle value from magic(5), I can do so like this:
M = magic(5);
value = M(3,3);
to get value == 13. I'd like to be able to do something like one of these:
value = magic(5)(3,3);
value = (magic(5))(3,3);
to dispense with the intermediate variable. However, MATLAB complains about Unbalanced or unexpected parenthesis or bracket on the first parenthesis before the 3.
Is it possible to read values from an array/matrix without first assigning it to a variable?
It actually is possible to do what you want, but you have to use the functional form of the indexing operator. When you perform an indexing operation using (), you are actually making a call to the subsref function. So, even though you can't do this:
value = magic(5)(3, 3);
You can do this:
value = subsref(magic(5), struct('type', '()', 'subs', {{3, 3}}));
Ugly, but possible. ;)
In general, you just have to change the indexing step to a function call so you don't have two sets of parentheses immediately following one another. Another way to do this would be to define your own anonymous function to do the subscripted indexing. For example:
subindex = #(A, r, c) A(r, c); % An anonymous function for 2-D indexing
value = subindex(magic(5), 3, 3); % Use the function to index the matrix
However, when all is said and done the temporary local variable solution is much more readable, and definitely what I would suggest.
There was just good blog post on Loren on the Art of Matlab a couple days ago with a couple gems that might help. In particular, using helper functions like:
paren = #(x, varargin) x(varargin{:});
curly = #(x, varargin) x{varargin{:}};
where paren() can be used like
paren(magic(5), 3, 3);
would return
ans = 16
I would also surmise that this will be faster than gnovice's answer, but I haven't checked (Use the profiler!!!). That being said, you also have to include these function definitions somewhere. I personally have made them independent functions in my path, because they are super useful.
These functions and others are now available in the Functional Programming Constructs add-on which is available through the MATLAB Add-On Explorer or on the File Exchange.
How do you feel about using undocumented features:
>> builtin('_paren', magic(5), 3, 3) %# M(3,3)
ans =
13
or for cell arrays:
>> builtin('_brace', num2cell(magic(5)), 3, 3) %# C{3,3}
ans =
13
Just like magic :)
UPDATE:
Bad news, the above hack doesn't work anymore in R2015b! That's fine, it was undocumented functionality and we cannot rely on it as a supported feature :)
For those wondering where to find this type of thing, look in the folder fullfile(matlabroot,'bin','registry'). There's a bunch of XML files there that list all kinds of goodies. Be warned that calling some of these functions directly can easily crash your MATLAB session.
At least in MATLAB 2013a you can use getfield like:
a=rand(5);
getfield(a,{1,2}) % etc
to get the element at (1,2)
unfortunately syntax like magic(5)(3,3) is not supported by matlab. you need to use temporary intermediate variables. you can free up the memory after use, e.g.
tmp = magic(3);
myVar = tmp(3,3);
clear tmp
Note that if you compare running times with the standard way (asign the result and then access entries), they are exactly the same.
subs=#(M,i,j) M(i,j);
>> for nit=1:10;tic;subs(magic(100),1:10,1:10);tlap(nit)=toc;end;mean(tlap)
ans =
0.0103
>> for nit=1:10,tic;M=magic(100); M(1:10,1:10);tlap(nit)=toc;end;mean(tlap)
ans =
0.0101
To my opinion, the bottom line is : MATLAB does not have pointers, you have to live with it.
It could be more simple if you make a new function:
function [ element ] = getElem( matrix, index1, index2 )
element = matrix(index1, index2);
end
and then use it:
value = getElem(magic(5), 3, 3);
Your initial notation is the most concise way to do this:
M = magic(5); %create
value = M(3,3); % extract useful data
clear M; %free memory
If you are doing this in a loop you can just reassign M every time and ignore the clear statement as well.
To complement Amro's answer, you can use feval instead of builtin. There is no difference, really, unless you try to overload the operator function:
BUILTIN(...) is the same as FEVAL(...) except that it will call the
original built-in version of the function even if an overloaded one
exists (for this to work, you must never overload
BUILTIN).
>> feval('_paren', magic(5), 3, 3) % M(3,3)
ans =
13
>> feval('_brace', num2cell(magic(5)), 3, 3) % C{3,3}
ans =
13
What's interesting is that feval seems to be just a tiny bit quicker than builtin (by ~3.5%), at least in Matlab 2013b, which is weird given that feval needs to check if the function is overloaded, unlike builtin:
>> tic; for i=1:1e6, feval('_paren', magic(5), 3, 3); end; toc;
Elapsed time is 49.904117 seconds.
>> tic; for i=1:1e6, builtin('_paren', magic(5), 3, 3); end; toc;
Elapsed time is 51.485339 seconds.

Custom Array Functions in Open Office Calc

Could someone please tell me how to write a custom function in Open Office Basic to be used in Open Office Calc and that returns an array of values. An example of one such built-in function is MINVERSE. I need to write a custom function that populates a range of cells in much the same way.
Help would be much appreciated.
Yay, I just figured it out: all you do is return an array from your macro, BUT you also have to press Ctrl+Shift+Enter when typing in the cell formula to call your function (which is also the case when working with other arrays in calc). Here's an example:
Function MakeArray
Dim ret(2,2)
ret(0,0) = 1
ret(1,0) = 2
ret(0,1) = 3
ret(1,1) = 4
MakeArray = ret
End Function
FWIW, damjan's MakeArray function returns a Variant containing an array, I think. (The type returned by MakeArray is unspecified, so it defaults to Variant. A Variant is a container with a descriptive header, apparently cast as needed by the interpreter.)
Almost, but not quite, the same thing as returning an array. According to http://www.cpearson.com/excel/passingandreturningarrays.htm, Microsoft did not introduce the ability to return an array until 2000. His example [ LoadNumbers(Low As Long, High As Long) As Long()] does not compile in OO, flagging a syntax error on the parens following Long. It appears that OO's Basic emulates the pre-2k VBA.

Resources