Hello,
I was trying to google it and was reading about muticharts .net programming, but couldn't figure it out. API seems very unclear. How do I access other timeframes in code? How do I access other studies from a study? I want to use daily ATR in intraday indicator.
Thanks!
Using daily ATR inside intraday study
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Using daily ATR inside intraday study
Hello ignl,
You can find this information in MultiCharts .NET FAQ and MultiCharts .NET Programming guide.
MultiCharts .Net is oriented to experienced programmers. In case you have any questions regarding C# coding we recommend referencing MSDN for information. Interfaces and classes available in MultiCharts .Net are described in MC .Net help file (PowerLanguage .Net Editor->Help tab-> PowerLanguage .Net Help). You can also find the code examples in the source code of the prebuilt MultiCharts studies (PowerLanguage .Net Editor->File tab->Open).
MultiCharts .NET Programming guide that contains important and useful information not only for beginners but for experienced MC .Net users as well. This is the recommended "Getting started for programming in MultiCharts .Net": https://www.multicharts.com/downloads/M ... e-v1.0.pdf
Wiki format: https://www.multicharts.com/trading-sof ... ming_Giude
MultiCharts .NET FAQ:
viewtopic.php?f=19&t=45848
You can find this information in MultiCharts .NET FAQ and MultiCharts .NET Programming guide.
MultiCharts .Net is oriented to experienced programmers. In case you have any questions regarding C# coding we recommend referencing MSDN for information. Interfaces and classes available in MultiCharts .Net are described in MC .Net help file (PowerLanguage .Net Editor->Help tab-> PowerLanguage .Net Help). You can also find the code examples in the source code of the prebuilt MultiCharts studies (PowerLanguage .Net Editor->File tab->Open).
MultiCharts .NET Programming guide that contains important and useful information not only for beginners but for experienced MC .Net users as well. This is the recommended "Getting started for programming in MultiCharts .Net": https://www.multicharts.com/downloads/M ... e-v1.0.pdf
Wiki format: https://www.multicharts.com/trading-sof ... ming_Giude
MultiCharts .NET FAQ:
viewtopic.php?f=19&t=45848
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Using daily ATR inside intraday study
You can do that with the DataLoader, see this part of the manual: 4.7.4 Receiving the data for any symbol and any resolution. DataLoader.How do I access other timeframes in code?
See this example from Henry: How to access objects of one study from the another one.How do I access other studies from a study?
Re: Using daily ATR inside intraday study
Thanks, I took a look at it. So I have some follow up question. Lets say I want to create something simple, like pivot range indicator. I want to use data of yesterday's daily bar as values for formula and want pivot range to start immediately after daily session is closed and not from midnight like in default indicator. I know there is example without loading other data for that, but it's introduction to my other indicators so I would like to do it this way.You can do that with the DataLoader, see this part of the manual:How do I access other timeframes in code?
See this example from Henry: .How do I access other studies from a study?
So that's what I did so far:
Code: Select all
using System;
using System.Drawing;
using System.Collections.Generic;
namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class Pivot_Range : IndicatorObject
{
private VariableObject<Double> m_pp_differential;
private VariableObject<Double> m_pp_high;
private VariableObject<Double> m_pp;
private VariableObject<Double> m_pp_low;
private VariableObject<Double> yesterdayHigh;
private VariableObject<Double> yesterdayLow;
private VariableObject<Double> yesterdayClose;
private IPlotObject Plot1;
private IPlotObject Plot2;
private IPlotObject Plot3;
private List<Bar> dailyBars = new List<Bar>();
public Pivot_Range(object ctx) :
base(ctx){
}
protected override void Create(){
m_pp_differential = new VariableObject<Double>(this);
m_pp_high = new VariableObject<Double>(this);
m_pp = new VariableObject<Double>(this);
m_pp_low = new VariableObject<Double>(this);
yesterdayHigh = new VariableObject<Double>(this);
yesterdayLow = new VariableObject<Double>(this);
yesterdayClose = new VariableObject<Double>(this);
Plot1 =
AddPlot(new PlotAttributes("PP high", EPlotShapes.LeftTick, Color.Gray,
Color.Empty, 2, 0, true));
Plot2 =
AddPlot(new PlotAttributes("PP", EPlotShapes.LeftTick, Color.Gray,
Color.Empty, 2, 0, true));
Plot3 =
AddPlot(new PlotAttributes("PP low", EPlotShapes.LeftTick, Color.Gray,
Color.Empty, 2, 0, true));
}
protected override void StartCalc() {
Resolution dayResolution = new Resolution(EResolution.Day, 1);
InstrumentDataRequest request = Bars.Request;
request.Subscribe2RT = true;
DataRequest dataRequest = new DataRequest();
dataRequest.RequestType = DataRequestType.BarsBack;
dataRequest.Count = Bars.FullSymbolData.Count;
request.Range = dataRequest;
request.QuoteField = RequestQuoteField.Ask;
request.Resolution = dayResolution;
DataLoader.BeginLoadData(request, OnData, null);
}
public void OnData(IDataLoaderResult result) {
switch (result.Event) {
case DataLoadedEvent.History: {
dailyBars.AddRange(result.Data);
break;
}
case DataLoadedEvent.RTNewBar: {
if (result.RTData.HasValue)
dailyBars.Add(result.RTData.Value);
break;
}
}
}
protected override void CalcBar()
{
m_pp.Value = (((yesterdayHigh.Value + yesterdayLow.Value)
+ yesterdayClose.Value)
/((3)));
m_pp_differential.Value = m_pp.Value - (((yesterdayHigh.Value + yesterdayLow.Value))
/((2)));
m_pp_high.Value = m_pp.Value + m_pp_differential.Value;
m_pp_low.Value = m_pp.Value - m_pp_differential.Value;
Plot1.Set(0, m_pp_high.Value);
Plot2.Set(0, m_pp.Value);
Plot3.Set(0, m_pp_low.Value);
}
}
}
Best regards!
Re: Using daily ATR inside intraday study
No one knows? What I'm interested is about OnData method. It loads all historical data in one step, but how to load it one by one in sync with intraday data? I'm thinking about updating ohlc values in OnData method and then calculate and draw lines in main method. This is such a simple problem but I just can't figure out this API
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Using daily ATR inside intraday study
Hello ignl,
OnData method loads the specified interval in one go. If you want to load the bars one by one then you need to request them one by one.
In order to synchronize the bars on data series you need to write your own bar constructor or use the new class CustomInstrument that was added in MultiCharts 9.0: it allows accessing the data series loaded by the DataLoader with the help of IInstrument interface. The bars of such data series are tied to the bars of the main data series based on time.
The other simpler solution is referencing the additional data series from the code:
OnData method loads the specified interval in one go. If you want to load the bars one by one then you need to request them one by one.
In order to synchronize the bars on data series you need to write your own bar constructor or use the new class CustomInstrument that was added in MultiCharts 9.0: it allows accessing the data series loaded by the DataLoader with the help of IInstrument interface. The bars of such data series are tied to the bars of the main data series based on time.
The other simpler solution is referencing the additional data series from the code:
Code: Select all
BarsOfData(2).Close
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Using daily ATR inside intraday study
Please find a sample code attached.Henry,
Can you share an example of using the new Custom Loader added for 9.0.
- Attachments
-
- Test_CustomInstrument_v0.1.pln
- (1.2 KiB) Downloaded 869 times
Re: Using daily ATR inside intraday study
Hi again,Hello ignl,
OnData method loads the specified interval in one go. If you want to load the bars one by one then you need to request them one by one.
In order to synchronize the bars on data series you need to write your own bar constructor or use the new class CustomInstrument that was added in MultiCharts 9.0: it allows accessing the data series loaded by the DataLoader with the help of IInstrument interface. The bars of such data series are tied to the bars of the main data series based on time.
The other simpler solution is referencing the additional data series from the code:Code: Select all
BarsOfData(2).Close
OK I'm using Multicharts for TWS so it is not 9.0 version. If you could take a look at my indicator example how can I use your mentioned simpler solution there to access yesterdayHigh in CalcBar method?
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Using daily ATR inside intraday study
The easiest solution is adding 1 day data series to your chart and accessing it's values from the code.Hi again,
OK I'm using Multicharts for TWS so it is not 9.0 version. If you could take a look at my indicator example how can I use your mentioned simpler solution there to access yesterdayHigh in CalcBar method?