How to look back a certain number of days for an indicator and how to only calculate logic upto the last complete bar (i.e. not the current bar) - trading

I'm relatively new to Pine and was having trouble with a couple of things.
So I've got a indicator that I want to look back for the last 5 full days of activity, however not each stock trades in the premarket/afterhours so I want to be able to look back say 5 days and then calculate the number of bars on the time frame (i.e. for a 5 min or hourly resolution). That way I can calculate the number of bars present on the current ticker for that time frame and adjust my indicator length (instead of just having a constant figure of 80 bars or whatever).
The second thing I want to do is only have the indicator update on the completion of a full bar (for example the hourly resolution). So I want it to only calculate up to x-1 bars. Right now I'm finding that it's updating on each new tick. ( I was able to figure this one out, just changed it from i= 0 to length -1 to i=1 to length).
Any help is greatly appreciated.
Thanks,
A

Related

How can I write an mt4 indicator that draws a rectangle and horizontal lines over first 6 hours of hourly candles

I am a quite new to mql4 coding. I would like to know how I write an indicator that does the following, based on the image below:
Draw a rectangle over the current day hour chart that covers the highest and lowest price points of the first 6 hours (candles)
Draw two horizontal lines along the highest and lowest points found 1.
Please note that 1. and 2. should be based strictly on the hourly period and shouldn't vary with the selected period.
I believe I'm suppose to be using ObjectCreate() with OBJ_RECTANGLE and OBJ_HLINE but the whole concept is quite new to me. I would really appreciate some assistance.

MQL4 max bars in chart

I'm trying to limit resources consumed by MT4 and go to options to set max bars in chart to something smaller like 500. My custom indicator calculates values from a 10 and 20 EMA.
Now the indicator does not even want to attach to the chart!
Even if I increase the number I cannot get my CI to attach to the chart again.
Please can you let me know what the minimum number should be for max bars in chart and why a simple CI as set out above will not attach to the chart?
Lastly, could you please help me also by stating what the default value for max bars in chart normally is? I thought it is 999999 but cannot remember.
Thanks so much for your effort.
In order to use your resources efficiently, ask your indicator to compute only last bars, prev_calculated should be used and go only since that value to the end of the chart(to the current bar). You can also make your indicator sleeping if number of bars is same, and let it run only when new bar appears (rates_total>prev_calculated) if that can be accepted for your task

Highcharts: Show x axis for missing data but ignoring certain area

I want to use the Highcharts StockChart library to make a chart. Here's more info on the chart I need to create:
The type of the chart is datetime
The data is being updated on every minute (it's data from stocks), so the chart is being constantly updated.
The data of the chart is from 9:00am to 11:40am and then from 12:35pm to 3:00pm (there's a lunch break).
The data is being shown with bars in an interval of 5 minutes (data is received for every 5 minutes except for the lunch break).
The bars will start to be drawn from left to right as the data is received.
The bars width needs to be the same size regardless of how many data is being shown on the chart.
The labels of x axis of the chart need to be always the same and on the same position (from 9:00am to 3:00pm every hour) even when there's missing data (a line must be drawn on the x axis).
So, I'm using the max property set to that day at 3:00pm on the x axis of the chart. With this, I can:
Have the bars width to be the same
Have the x axis be drawn regardless of the missing data on the same interval (until 3pm).
Everything works ok until the lunch break (11:40am). However, when receiving data for 12:35pm (after lunch break), the chart will ignore the max property and the last line of the x axis that is drawn is until 1pm (this line needs to be drawn until 3pm). I assume that this is because until 11:40am all the data for 5 minutes is present, so the chart understands the interval on which the data needs to be drawn and also can draw the x axis lines on the same interval. But as soon as there's a gap on the data, the chart doesn't know anymore if data will keep coming in an interval of 5 minutes, so will just take into consideration all the data that has received until now, ignoring the max property.
I have tried different options in order to solve the issue:
I used ordinal property set to false. With this, I can solve the issue of the missing x axis labels until 3pm, but the issue is that the lunch break will have a gap on the chart. I need to merge the lunch break and having the x axis labels drawn until 3pm.
I tried to use the tickInterval property and was able to set the interval of the x axis but only for the data that is being drawn. However, the x axis label it still until 1pm and needs to be until 3pm.
I tried to use the breaks property for the lunch break while using the ordinal property set to false but didn't work. Also, the chart needs to be merged on the lunch break; using this property will create a gap on purpose, so this property won't help me to fix this issue.
So, I noticed that the interval is being changed correctly where there's data, but the lines are not being drawn where there's no data on the x axis (only until 1pm and not until 3pm). And if I use the ordinal property, it will show all the x axis lines for the missing data, but need to hide the gap for the lunch break.
Any help with this is appreciated =)
UPDATE:
I noticed that when there's still no data, if using v1.3.1 of highcharts (the one I'm currently using), the x axis lines are being drawn correctly until 3pm, but if using the latest version this doesn't happen. It seems that the max property is being ignored for the latest version.
Including the links of jsfiddle for my code on the comments (since stackoverflow doesn't allow me to post many links because don't have enough reputation).
I was able to achieve what I wanted. In the end what I did was to create null data to fill this gap for the lunch break. Also, I created null data for the remaining data until 3pm, that way the x axis lines were drawn properly: https://jsfiddle.net/K4Cj6/201/:
[1504528800000,null,null,null,null]
Thanks anyway guys =)

Changing the viewport to only show certain intevals of ios-charts linechart

I'm using the ios-charts library and I have a LineChart View that has x values that are dates from every weekday of this year. On the y-axis I have values between 0 and 25.
I would like to zoom in on different intervals on the LineChart View.
For example only show Data for week X one time and later change to show data for three months, etc etc.
I did not find anything in the documentation on how to do this. I used the "zoom" function with out any success.
(Example : Zoom and show the last 20 days on the x axis or zoom and show the last three months)
Has someone does this before?
It's a tough question and very advanced control. I guess you need to read carefully about the code, focusing on moveViewToX, and the logic and functions in ChartTransformer. Combining some tricks and calculations, you may find a way to fine-grainedly controll what you want to display.
Also, there is a property:
/// the maximum number of entried to which values will be drawn
internal var _maxVisibleValueCount = 100
may also help you.

Scrollable Line Chart

Am trying to use the ios-charts library based off the MPAndroidCharts; however am having some trouble getting a scrollable graph to work.
By scrollable I mean that I try to show only a portion of the data of the line and that you can scroll horizontally to see more results. E.g I have 30 results and I only show 10 at a time and then scroll horizontally to see more.
Have come up with an approximation by using the method
[self.containerView setVisibleXRangeWithMinXRange:24.0f maxXRange:24.0f];
However this seems to make the scrolling kind of jittery as it keeps on redrawing.
Am looking for an ios-charts example and clarification on methods to see whether I am on the right track or not.
Similar to your question:
https://github.com/danielgindi/ios-charts/issues/267
Quote:
I was able to achieve this after playing with it a bit. It is actually pretty straight forward.
chart.data = data; // This is the MAIN reason, data for the chart has to be set first before the next 2 steps otherwise they will just get ignored like nothing has been set.
// set the max x data point to 10, which is what i wanted showing only 10 data points for the line or bar chart, from 100 data points.
[chart setVisibleXRangeMaximum:10];
// move the chart view to 90 index of X, which is the last 10 entries I want to see. and it works as expected.
[chart moveViewToX:90];
Other helpful ones:
https://github.com/danielgindi/ios-charts/issues/226
https://github.com/danielgindi/ios-charts/issues/258

Resources