How create static trendline object on chart by MQL4? - mql4

I want a down trend line whenever the highest candle in the previous 500 bars is higher than latest 5 candles highest bar. However the trend line is created the first time but does not update.
int highestCandle=iHighest(Symbol(),0,MODE_HIGH,500,0);
if(High[highestCandle]>High[5])
{
ObjectCreate(0,"HT",OBJ_TREND,0,Time[highestCandle],High[highestCandle],Time[0],High[0]);
ObjectSetInteger(0,"HT",OBJPROP_COLOR,clrBlue); ObjectSetInteger(0,"HT",OBJPROP_STYLE,STYLE_SOLID); ObjectSetInteger(0,"HT",OBJPROP_RAY,true);
}
I do not want to delete this object and recreate on every new tick, I would just like it to be updated on the chart.

Because you have already created your object, trying to create it again will not move the coordinates. You need to use ObjectMove. Try the following code:
int highestCandle=iHighest(Symbol(),0,MODE_HIGH,500,0);
if(High[highestCandle]>High[5])
{
ObjectCreate(0,"HT",OBJ_TREND,0,Time[highestCandle],High[highestCandle],Time[0],High[0]);
ObjectSetInteger(0,"HT",OBJPROP_COLOR,clrBlue);
ObjectSetInteger(0,"HT",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"HT",OBJPROP_RAY,true);
ObjectMove("HT",0,Time[highestCandle],High[highestCandle]);
ObjectMove("HT",1,Time[0],High[0]);
}

Related

Changinx Bar Charts X position on Highcharts

We have a request from customer and we need to trick the highcharts bar view.
The problem is our series contain timestamp vs value but business wise this value is corresponding to previous timestamp to that value's timestamp. So we would like to show the bars in between of these timestamps.
So is there an easy way to do this in highcharts w/o playing with the points in the series.
See images below;
Current Highchart Behaviour
Requested Chart Behaviour
You can use xAxis.tickPositioner in order to move ticks and xAxis.labels.formatter to change labels values.
Live example: https://jsfiddle.net/h9zjmqap/
Output:

Candlestick shows two colors (up trend & down trend)

This is an angular2 app (2.4.8), webpack using highcharts.
I am updating the chart with minute bars from the database. I make timed calls to the database, then with the array returned (it maybe just 1 row, it maybe more, depending if data is keeping up). Below, 'x' is the array returned.
for (let i of x) {
let point = [new Date(i.DateTime).valueOf(), i.OpeningPrice,
i.HighPrice, i.LowPrice, i.ClosingPrice];
this.chart.get('sA0').addPoint(point, true);
}
The problem of a single bar indicating both up and down trend, as seen in my screenshot, the one bar has green on top & red below.

Highcharts :: Need to split y-axis from primary body of chart. Can I display this axis separately from the Highchart?

I have a situation where I need to remove all margins from a highchart and remove the x/y axis so it fills a series of columns in a table completely.
I did that, no problem. Chart goes to the extremes as needed.
What I need now is that pesky yaxis I already removed...but displayed in a table cell outside of the existing highcharts object.
It would seem easy, as though I could just set the overflow property of yaxis to 'visible' and play with the offset...which would work however this would only work if I wanted to re-position the axis within the boundaries of the highchart object. I want him in a different cell entirely.
Is there anyone who has had experience in this situation? Is it going to require me to have a secondary highchart with only a y-axis?
Best answer gets a green check.
EDIT :: I now have dispersed each 'day' into their own column (more bars coming per day [scheduled,actual,etc...]). In order to keep the scales lined up, I manipulate the yAxis:max property and set them all to a derived value.
In the open column (currently w/ text Hourly Trends) is where I would put an additional highchart module with no series data but with the same min/max/tickInterval.
The next big leap will be to see the data is alive and changes w/ schedule. May have to start another thread for that one, no?
Create a new HC object with no data but only the yAxis (making sure it is the right scale, etc). Perhaps add the same series of data to it but hide the series? Add it to the location you want. This seems kludge and not very good practice. Each business use is different but why would you want this?
EDIT based on comment of business rules:
Why not come at this from a different direction and have the individual chart elements (the bars/points/etc) be a single point chart. This way you have one chart per column. You can then set up the yAxis to be text and not worry about the position. If we could see an example of the page layout and the desired result that would help.

Getting the selected range of the navigator

I have a HighStock chart that renders data for the previous 24hrs, from that data I first want to show only the last 2hrs and allow the users to drag it back if they want to see more.
Is it possible to get the min and max values of the section a user selected?
I tried getExtremes, but this gives me the complete 24hrs.
If I understand you correctly, you want to know what are the minimum and maximum datetimes of the currently visible points (that is, the range the user specified in the navigator or in the range selector). If that is the case, just get the min and max values of the xAxis in question.
The result of the getExtremes() function looks something like this:
Object {
dataMax: 1374169422743,
dataMin: 1374169326060,
max: 1374169381963.2844,
min: 1374169379331.4294,
userMax: 1374169381963.2844,
userMin: 1374169379331.4294
}
From what I can tell, the min/max set will match the userMin/userMax set and will also match what you get directly from the xAxis in question. I'm not sure which is the better source
You neet to use setExtremes() http://api.highcharts.com/highstock#Axis.setExtremes() function which allows to degine this range.

Highcharts - Updating a chart's option after initial render

Is it possible to update a chart's option (marginRight for example) and call redraw() to have that new value reflected in the chart? Or does a new instance of the chart need to be created for these types of changes?
I think it may be the latter because it sounds like only data or axis values can be altered after the chart is created. I see the documentation for redraw states:
Redraw the chart after changes have been done to the data or axis extremes
And the new dynamic feature in 3.0 states:
Through a full API you can add, remove and modify series and points or modify axes at any time after chart creation.
Thank you in advance.
Update
My reason for wanting to do this was I had a vertical layout and right-aligned legend that was overlapping my chart. I just realized Highcharts automatically sets the correct marginRight to accommodate for this if one isn't explicitly specified.
Unfortunately you cannot modify margin parameter dynamically, so you need to destroy old chart and create new instance.
This feature is one of our target in the nearest future.
Say you got a chart initialized like this:
chart = new Highcharts.Chart({
...
You can change trivial attributes, like its title, like this:
chart.setTitle({text: "New title"});
And you can refresh the dataset it's using with a new one, like this:
chart.series[0].setData(newChartData, true);
Where newChartData will contain the array with new data you wish to display

Resources