I am using wxFreeChart library in my project. However I am unable to change the colour and line type in XY data series. In the documentation nor in the samples there is no example of such functionality. Also there are not straightforward functions allowsing to do this. Does anyone has experience with this library to say if it is even possible?
Yes, it is possible to set both the serie colour and the pen type for XY line charts.
These attributes are set via the XYLineRenderer class. The documentation does cover this but you have to click on the "List all members" to see them. The current documentation is available under XYLineRenderer Members.
For simple changes, you can access the XYLineRenderer using the XYDataset::GetRenderer() method. This returns an XYRenderer* which you will need to cast to a XYLineRenderer* in order to set the pen type. Of course you can create the XYLineRenderer* first and pass it to the XYDataset::SetRenderer method instead.
Here is an example:
// Set the colour and pen of the first series.
static_cast<XYLineRenderer*>(dataset->GetRenderer())
->SetSeriePen(0, new wxPen(*wxRED, 5, wxPENSTYLE_SHORT_DASH));
// Set the colour and pen of the second series.
static_cast<XYLineRenderer*>(dataset->GetRenderer())
->SetSeriePen(1, new wxPen(*wxBLUE, 1, wxPENSTYLE_DOT_DASH));
SetSeriePen is only available to XYLineRenderer for obvious reasons, but you can set the colour of any renderer with Renderer::SetSerieColour(size_t serie, wxColour *color).
Note: I am not that happy with the way wxFreeChart takes pointers in these functions. This project is not actively maintained, but I would like at some point to fork it and update the API to be more consistent with modern versions of C++ and wxWidgets.
Related
I am trying to understand how to set the gap for Gurobi.Optimizer, because it solves too long when the default gap threshold is used (10e-4).
I couldn't find it anywhere (they might be referred to as attributes or parameters).
PS: Also, I am trying to find the right tutorial or instructions on how to use the solver in JuMP. I checked here https://juliahub.com/docs/Gurobi/do9v6/0.7.7, but they don't reveal the meanings of different attributes and inputs. Please, send me one in case somebody knows.
Best,
A.
You can set the MIP gap via the MIPGap parameter:
using JuMP, Gurobi
model = Model(Gurobi.Optimizer)
set_optimizer_attribute(model, "MIPGap", 0.1)
You can read more about JuMP here: https://github.com/jump-dev/Gurobi.jl
Currently, I'm using this code. How can I change the hlines to red if it's a resistance and blue if it's a support?
mplfinance.plot(df,
type = 'candlestick',
style = 'binance',
hlines=dict(hlines= support_resistance,linestyle='-', linewidths = (1,1)),
volume = True)
I'm getting results like this:
hlines=dict(hlines= support_resistance,linestyle='-',linewidths = (1,1),colors=('b','r')
See for example cell "In [6]" in this tutorial: https://github.com/matplotlib/mplfinance/blob/master/examples/using_lines.ipynb
You may need to include as many colors as you have support_resistance lines. So for example, maybe something like: colors=['b','r','b','r','r','r']
Regarding handling support resistance colors dynamically (per your comment) it is not appropriate for mplfinance to provide algorithms for determining support or resistance, only to provide tools to make it easier for you to visualize them.
Also, each user may have their own specific way of determining support or resistance.
Presumably as you are building the support_resistance list, at the point in your code where you are adding a specific price to that list, you probably know whether that price represents support or resistance. At the same point in your code you should add a color ('b' or 'r') to the colors list. That way you dynamic build two lists: support_resistance, and colors which end up being the same length.
Based on the suggestion from Daniel, I made a list of colors as follows and it worked. support_resistance variable here consists of both support and resistance levels.
colors = []
for lvl in support_resistance:
if lvl > df['Close'][-1]:
colors.append('r')
else:
colors.append('b')
I am a novice at using TradingView's Pinescript and having a hard time finding an easy to understand example of a script. I am used to Java/C++ and Pinescript is very different. I am trying to build a script that will scan a stock chart and look for gaps of over 5%. Here is psuedocode for what I am trying to create:
if(difference between open of current day and previous day close > 5%) {
plot a green circle or red circle, depending on if gap was up or down
}
Thank you in advance!
You're best bet would be to go through their tutorial
There's some odds choices in this language if you have any programming background so it's probably a good idea to read it all (it's not that much). E.g.
open is the current bars open price, but open[1] is the previous bar open price (so should be read as open[current_index-1])
you can't use the plot calls inside function bodies
as for you question (not tested, but should be close enough to give the right idea):
study(title='gap detector', overlay=true)
//plotshape(<condition>, <options>) // condition must be true to plot something
is_percentage_increase = if (close-close[1])/close[1] > 0.05
true
plotshape(is_percentage_increase, style=shape.circle, color=green)
Pine scripting is easy to use; Initially it was bit hard to understand, Once started using it it becomes so useful to strategize the logic.
In your case you can use conditional operator as well to detect this.This will work in Version 2 .The version 3 is bit differrent
//version =2
study(title ="Experementing the code ",overlay =true ,shorttitle ="testing") //overlay=false to get this down of the chart as seperate layout
plotchar( (close-close[1])/close[1] >0.05 ? 1:na ,char =' ',text ="plot\nTest",textcolor=red,size.huge)
Instead of if the condition you can use ?: operator to do this job.
Please make sure plotchar(.....) coming in the same line, not in separate line.
Pine has lot of cool features to use and helped me to derive my own strategy. The tutorial is really good.
Note if you don't put char='' above it will print STAR as the default character. And in the character even if you put char='testtest' it will print the only t .
Say I have a fluid model, with initial pressures, temperatures, valve settings, etc.
Is there a way to run a State Graph simulation where each of the states contains new component parameter settings for the model, i.e. some parameters of some selected components are changed during one state, and are changed again during the next state?
For example, during State1 let's set the values for the following component parameters:
source.pressure = 1
source.temperature = 1
valve1.opening = 1
Until State1 switches to State2 where the parameters are:
source.pressure = 0.5
source.temperature = 0.5
valve1.opening = 0.5
Thanks for your time :-)
Short answer: No. For that use-case you should use discrete variables (and change them using a when-clause).
Long answer: As of version 3.3, Modelica has a new feature, called State Machines (see chapter 17 of the specification). In theory, it should do what you require, but it might still be buggy since it is quite new.
What you are attempting to do is called "variable structure modeling" (although only changing parameters is hardly "variable structure" and can be implemented using discrete variables instead, as my short answer suggests). Long before StateMachines where introduced to Modelica, this was (and remains) an active area of research. You could also use an external tool to achieve your goal, e.g. DysMo
So I'm developing a minesweeper flags game and the multiplayer version is all set up, but the single player version is still under developement. It's important to refer that I'm using a DataGridView, and I'm applying r = tab1.CurrentCell.RowIndex + 1 and c = tab1.CurrentCell.ColumnIndex + 1 to see where the player clicks. What I want to do is to make the AI click any random cell when it's turn comes, but how do I do this. Any thoughts?
Best regards, joao.
Have you looked at this article:
Creating an Artificial Intelligence to play Minesweeper
In this article there is a discussion of using information Array, hypothetical array and hidden array as below:
Let us call the array holding the information our AI possesses the information array, and the array holding hypothetical situations the hypothetical array. The array storing the positions of mines is, of course, not immediately accessible to our program... we'll call that the hidden array.
You might need to do as below:
Have an information array which has info about your mines using the Layout
Have an array which provides the location about player selection
Based on 1) and 2) select a position to choose