Chart environment - Price scale, Visible Bars, and Chart Time Zone
Chart environment - Price scale, Visible Bars, and Chart Time Zone
02 Dec 2013, 15:55
I've searched the forums and I've checked the APIs but haven't been successful in finding a way to gather information about the chart on which the indicator resides. For example, it would be ideal to be able to access the following data points inside the indicator:
- Price scale - this would be very useful in determining vertical placement of arrow markers in overlaid indicators
- The difference in points between each hatch mark on the vertical scale.
- The min and max prices displayed on the vertical scale.
- Visible Bars - Index and/or Open DateTime of first and last bars visible in the chart. It would be very useful in determining scaling for non-overlaid indicators. (Even better would be the ability to place more than one indicator in the same indicator pane and cAlgo/cTrader automatically handle the scaling. That is how it works today in MT4.)
- Time Zone utilized by the chart. It seems that our options are to either explicitly define a Time Zone in the indicator or use the default UTC. A nice option to have would be to elect to use the Time Zone in use by the user's chart.
I would be grateful for any help in pointing me in the right direction.
Thanks!
Replies
bp2012
03 Dec 2013, 23:37
No problem. For the TimeZone request, it would apply to any indicator that makes use of a specific time. For example one that looks for triggers that take place during certain times such as the last 30 minutes of New York trading. Knowing the selected timezone for the chart on which the indicator is displayed is necessary.
The Price scale is needed when placing an arrow above or below a price bar. Vertical positioning is determined by price. I could simply apply an offset using a multiple of Symbol.PipSize. The trouble comes in when changing TimeFrames. On a one hour chart 5 pips might have the arrow look like it is sitting on the bar. Whereas on a 1M chart 5 pips might have the arrow off of the screen. Now imagine trying to place the arrow around a BollingerBand indicator. Being able to fine tune exactly where the arrow is displayed would be ideal. It would allow the arrow to be placed in relatively the same position regardless of the chart timeframe.
Visible bars are needed as a work around to being able to display two indicators in the same window pane. Having a separate pane for multiple indicators can take up valuable space. For example, I might want to display a MACD histogram and an oscillator like RSI in the same pane. That takes up a lot less space than having a separate window for the rsi. The problem is that scaling of the rsi might make the MACD too small to see. In Metatrader 4 I would simply throw both indicators into the same window. In cTrader I can't do that. As a workaround I can create a custom indicator that contains both the macd and rsi. Which leads to the problem of vertical scaling. I need to scale one or both of the indicators so that they display properly. Having the number of visible bars would allow me to grab the highs and lows of both indicators and manually scale as needed. I'll readily admit that it will be ugly. But as a workaround it would work.
Hope that helps! Please let me know if I can provide additional clarification.
@bp2012
Spotware
05 Dec 2013, 12:36
For example one that looks for triggers that take place during certain times such as the last 30 minutes of New York trading. Knowing the selected timezone for the chart on which the indicator is displayed is necessary.
You do not need selected chart timezone for this indicator. Just specify NY time zone for the indicator and all timestamps will be present in this timezone, so you can easily check that time is between 16:30 and 17:00 NY:
[Indicator(IsOverlay = false, TimeZone = TimeZones.EasternStandardTime)] public class NYTimeIndicator : Indicator { [Output("Main")] public IndicatorDataSeries Result { get; set; } public override void Calculate(int index) { var time = MarketSeries.OpenTime[index].TimeOfDay; if (time >= new TimeSpan(16, 30, 0) && time < new TimeSpan(17, 0, 0)) Result[index] = 1; else Result[index] = 0; } }
The Price scale is needed when placing an arrow above or below a price bar. Vertical positioning is determined by price. I could simply apply an offset using a multiple of Symbol.PipSize. The trouble comes in when changing TimeFrames. On a one hour chart 5 pips might have the arrow look like it is sitting on the bar. Whereas on a 1M chart 5 pips might have the arrow off of the screen. Now imagine trying to place the arrow around a BollingerBand indicator. Being able to fine tune exactly where the arrow is displayed would be ideal. It would allow the arrow to be placed in relatively the same position regardless of the chart timeframe.
So you want to draw an arrow let's say 5 pixels above the bar. You are right, this is impossible now. But if we implement access to the chart scale (this is not easy for us right now), we will have to run your code every time the chart is scrolled or updated, which is too frequent. So, we recommend to use text for such drawings:
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)] public class Arrows : Indicator { public override void Calculate(int index) { if (MarketSeries.High[index - 1] > MarketSeries.High[index] && MarketSeries.High[index - 1] > MarketSeries.High[index - 2]) { ChartObjects.DrawText("arrow" + index, "▼", index - 1, MarketSeries.High[index - 1], VerticalAlignment.Top); } } }
But in the future we are going to implement a special method to draw arrows and other common shapes.
Visible bars are needed as a work around to being able to display two indicators in the same window pane. Having a separate pane for multiple indicators can take up valuable space.
The example is rather clear. To be honest, we prefer to provide proper solution here, not API workarounds. But we will also consider implementing your suggestions.
Please let us know what you think about it.
@Spotware
bp2012
08 Dec 2013, 23:23
"You do not need selected chart timezone for this indicator. Just specify NY time zone for the indicator and all timestamps will be present in this timezone, so you can easily check that time is between 16:30 and 17:00 NY:"
Thank you for this! I had an incorrect perspective about how the timezone translation works in cTrader. In MT4 any timezone translation has to be done by hand. I see that cTrader handles all of the translation for us behind the scenes. I experimented by calling the drawline method that takes a date in the parameter list. Then I changed to different timezones in my sample indicator and in the cTrader chart. Everything worked flawlessly. This is fantastic! I'm impressed with work done for us behind the scenes in this area. Dealing with TimeZone issues (daylight savings time, etc) in MT4 makes me cringe.
"So you want to draw an arrow let's say 5 pixels above the bar. You are right, this is impossible now. But if we implement access to the chart scale (this is not easy for us right now), we will have to run your code every time the chart is scrolled or updated, which is too frequent. So, we recommend to use text for such drawings:"
That is almost exactly how I do it today, except that I add a vertical offset based on the chart timeframe. The offset is smaller for shorter timeframes and larger for longer timeframe. To be honest it is just a little extra overhead in my coding and not a very big deal. It's not exact, but it is close enough.
"The example is rather clear. To be honest, we prefer to provide proper solution here, not API workarounds. But we will also consider implementing your suggestions."
I'm with you. I'd rather that Spotware provide a solution rather than have to scale each of the consolidated indicators myself ;) Any API workaround would be messy and I'm sure that it would not perform as well as something the cAlgo/cTrader team could put together.
It's always challenging to develop features that appeal to a broad audience so I'd expect that indicator developers would like to be able to choose the scaling methodology when adding multiple indicators to a single window pane. For example, fixed scaling would take the highest and lowest displayed values out of all the indicators for scaling. This is useful when the indicators all have relatively the same magnitude and differences between the values are important. Independent scaling would be scaling each indicator separately (just as if you were to overlay indicator windows over each other). This is useful when indicators have different orders of magnitude and direction, slope, and other behaviors are most important than differences in indicator values. That's my 2 cents for what it's worth.
Keep up the great work. This product just keeps getting better and better. Now, if you could only get a US broker to see the light....
@bp2012
Spotware
03 Dec 2013, 12:22
Could you give us several examples of indicators that will use such features?
@Spotware