Using daily ATR inside intraday study

Questions about MultiCharts .NET and user contributed studies.
ignl
Posts: 4
Joined: 01 Aug 2014
Has thanked: 5 times

Using daily ATR inside intraday study

Postby ignl » 01 Aug 2014

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!

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Using daily ATR inside intraday study

Postby Henry MultiСharts » 01 Aug 2014

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

User avatar
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

Postby JoshM » 01 Aug 2014

How do I access other timeframes in code?
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 studies from a study?
See this example from Henry: How to access objects of one study from the another one.

ignl
Posts: 4
Joined: 01 Aug 2014
Has thanked: 5 times

Re: Using daily ATR inside intraday study

Postby ignl » 05 Aug 2014

How do I access other timeframes in code?
You can do that with the DataLoader, see this part of the manual:
How do I access other studies from a study?
See this example from Henry: .
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.
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);

}
}
}
I would like to ask if this is similar to what I should do and maybe you or someone else could help me how can I use daily data in my CalcBar() method to calculate yesterday's values? I'm a bit lost here :)

Best regards!

ignl
Posts: 4
Joined: 01 Aug 2014
Has thanked: 5 times

Re: Using daily ATR inside intraday study

Postby ignl » 06 Aug 2014

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 :(

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Using daily ATR inside intraday study

Postby Henry MultiСharts » 07 Aug 2014

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

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Using daily ATR inside intraday study

Postby davewolfs » 08 Aug 2014

Henry,

Can you share an example of using the new Custom Loader added for 9.0.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Using daily ATR inside intraday study

Postby Henry MultiСharts » 11 Aug 2014

Henry,

Can you share an example of using the new Custom Loader added for 9.0.
Please find a sample code attached.
Attachments
Test_CustomInstrument_v0.1.pln
(1.2 KiB) Downloaded 858 times

ignl
Posts: 4
Joined: 01 Aug 2014
Has thanked: 5 times

Re: Using daily ATR inside intraday study

Postby ignl » 13 Aug 2014

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
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?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Using daily ATR inside intraday study

Postby Henry MultiСharts » 13 Aug 2014

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?
The easiest solution is adding 1 day data series to your chart and accessing it's values from the code.


Return to “MultiCharts .NET”