Hong Kong China
Posts: 1 since Jun 2020
Thanks Given: 0
Thanks Received: 0
|
Dear all, am new to MC.
I am trying to build a test strategy that look at 1H MACD and 5H MACD.
I have Data#1 as 1H and Data#2 as 5H and I am trying to use the BarsOfData(2) to access the 5H prices and feed it to the MACD function. Bu
However, I do not seem to be able to replicate the same MACD value as the MACD plot on the 5H if I set this indicator to run on data#1 (through the indicator properties, though the code reference to barsOfData(2).
and I will get the same correct result if I set this indicator to run on data#2 through the indicator properties.
Obviously, I need it to run on data#1 on the indicator properties as I will add code pieces to reference to the 1H MACD as well. But I got stuck with getting the right 5H MACD through the BarsOfData(2). Or is it a complete incorrect way of implementing multi time frame indicator/strategy? Appreciate any help/pointers. a quick example would be fantastic!
Thanks a lot!
Leung
---------------------------------------------------------
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator{
public class Debug2 : IndicatorObject {
public Debug2(object _ctx):base(_ctx)
{
MACDLength = 9;
MACDslowLength = 26;
MACDfastLength = 12;
}
private IPlotObject DebugI;
//private IPlotObject DebugI2;
// Tech Function
//DMI
//private DirMovement m_dirmovement1;
//MACD
private Function.MACDBarsOfData m_macd1;
private Function.XAverageBarsOfData m_xaverage1;
private VariableSeries<Double> m_mymacd;
private VariableSeries<Double> m_macddiff;
//Var
public ISeries<Double> price { get; set; }
[Input]
public int MACDLength { get; set; }
[Input]
public int MACDfastLength { get; set; }
[Input]
public int MACDslowLength { get; set; }
private double lastpx;
private string Last5HBar;
protected override void Create() {
// create variable objects, function objects, plot objects etc.
m_macd1 = new Function.MACDBarsOfData(this);
m_xaverage1 = new Function.XAverageBarsOfData(this);
m_mymacd = new VariableSeries<Double>(this);
m_macddiff = new VariableSeries<Double>(this);
DebugI =
AddPlot(new PlotAttributes("Signal", 0, Color.Silver,
Color.Empty, 0, 0, true));
}
protected override void StartCalc() {
var B1 = Bars;
var B2 = BarsOfData(2);
if (B2.Status == EBarState.Close)
{
m_macd1.Price =B1.Close;
m_macd1.FastLength = MACDfastLength;
m_macd1.SlowLength = MACDslowLength;
m_xaverage1.Price = m_mymacd;
m_xaverage1.Length = MACDLength;
m_mymacd.DefaultValue = 0;
m_macddiff.DefaultValue = 0;
}
// assign inputs
}
protected override void CalcBar(){
// indicator logic
double power = 0;
if (BarsOfData(2).Status == EBarState.Close)
{
m_mymacd.Value = m_macd1[0];
var m_macdavg = m_xaverage1[0];
m_macddiff.Value = m_mymacd.Value - m_macdavg;
}
//else
DebugI.Set(0,m_mymacd.Value);//,pl_col);
}
}
}
|