Array populated with CalcBar

Questions about MultiCharts .NET and user contributed studies.
csswowsers
Posts: 6
Joined: 04 Dec 2013

Array populated with CalcBar

Postby csswowsers » 21 Apr 2014

My understanding is that the CalcBar() routine is run once per bar. In trying to keep an array of the x bar high/low, I notice that the first time CalcBar() is run, all the values of the array are populated. I had started using VariableSeries but was getting the values were being overridden by previous values.

Code: Select all

//public VariableSeries<Double> m_NBHigh;
public double[] m_NBHigh;
//public VariableSeries<Double> m_NBLow;
public double[] m_NBLow;
protected override void Create() {
// create variable objects, function objects, order objects etc.
//m_NBHigh = new VariableSeries<Double>(this);
m_NBHigh = new double[1000000];
//m_NBLow = new VariableSeries<Double>(this);
m_NBLow = new double[1000000];
}
protected override void CalcBar(){
// strategy logic

if ((NBars + NOffset) >= 15) xInit.Value = Convert.ToInt32(NBars + NOffset + 2);
if (Bars.CurrentBar >= xInit.Value && Bars.CurrentBar <= Bars.FullSymbolData.Count)
{
int xk = Convert.ToInt32(Bars.CurrentBar - NBars - NOffset + 1);
//int xj = xk - Bars.CurrentBar;
m_NBHigh[Bars.CurrentBar] = Bars.FullSymbolData.High[xk] * 10000;
m_NBLow[Bars.CurrentBar] = Bars.FullSymbolData.Low[xk] * 10000;
//int l = Bars.CurrentBar;
for (int l = xk; l <= Bars.CurrentBar-NOffset; l++)
{
if (Bars.FullSymbolData.High[l] * 10000 > m_NBHigh[Bars.CurrentBar])
m_NBHigh[Bars.CurrentBar] = Bars.FullSymbolData.High[l] * 10000;
if (Bars.FullSymbolData.Low[l] * 10000 < m_NBLow[Bars.CurrentBar])
m_NBLow[Bars.CurrentBar] = Bars.FullSymbolData.Low[l] * 10000;
}
}
}

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

Re: Array populated with CalcBar

Postby Henry MultiСharts » 22 Apr 2014

My understanding is that the CalcBar() routine is run once per bar. In trying to keep an array of the x bar high/low, I notice that the first time CalcBar() is run, all the values of the array are populated. I had started using VariableSeries but was getting the values were being overridden by previous values.
Hello csswowsers,

That is correct and expected behavior. Please describe your final goal and what exactly you are unable to do.

csswowsers
Posts: 6
Joined: 04 Dec 2013

Re: Array populated with CalcBar

Postby csswowsers » 23 Apr 2014

I was able to edit the New_High_for_Day/New_Low_for_Day indicators to get what I want. However, when trying to close out a position on a reversal, I am not getting the expected behavior with OrderExit.FromEntry(buy_order) or OrderExit.FromEntry(sell_order);
I send a buy with
buy_order.Send(price,lots);
and a sell with
sell_order.Send(price,lots);
My expectation is that the OrderExit.FromEntry will close out the position

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

Re: Array populated with CalcBar

Postby Henry MultiСharts » 23 Apr 2014

csswowsers, please send me (support@multicharts.com) the following information for further investigation:
- workspace you are using;
- in PowerLanguage .NET editor->File->Export->export the study you are having problem with. Send me the study export file.


Return to “MultiCharts .NET”