MC 跨周期 画线
using System; using System.Drawing; using PowerLanguage.Function; using System.Collections; namespace PowerLanguage.Indicator { //[SameAsSymbol(true)] public class Mov_Avg_1_Line : IndicatorObject { //1小时 24 1小时 120 private IPlotObject h1_24; private IPlotObject h1_120; private IPlotObject h4_120; private IPlotObject d1_10; ArrayList h1_list = null ; ArrayList h4_list = null ; ArrayList d1_list = null ; public Mov_Avg_1_Line(object ctx) : base(ctx){ } protected override void Create(){ h1_list = new ArrayList(); h4_list = new ArrayList(); d1_list = new ArrayList(); h1_24 = AddPlot(new PlotAttributes("Avg", 0, Color.Yellow, Color.Empty, 0, 0, true)); h1_120 = AddPlot(new PlotAttributes("Avg", 0, Color.Cyan, Color.Empty, 0, 0, true)); h4_120 = AddPlot(new PlotAttributes("Avg", 0, Color.Red, Color.Empty, 0, 0, true)); d1_10 = AddPlot(new PlotAttributes("Avg", 0, Color.Red, Color.Empty, 0, 0, true)); } protected override void StartCalc(){ h1_list.Clear(); h4_list.Clear(); d1_list.Clear(); } int lasthavecal = 0 ; protected override void CalcBar(){ DateTime dt = Bars.Time[0]; int currentbars = dt.Day*10000+ dt.Hour*100 + dt.Minute ; if(lasthavecal == currentbars) return ; lasthavecal = currentbars ; cal_h1(); cal_h4(); cal_d1(); } private void cal_h1(){ DateTime dt = Bars.Time[0]; DateTime lastdt = Bars.Time[1]; int currentx = dt.Day*100+ dt.Hour; int lastx = lastdt.Day*100+ lastdt.Hour; if(currentx != lastx) h1_list.Add(Bars.Close[1]); Double value_h1 = MyAvg.Avg(h1_list,24); if(value_h1 > 0 ) h1_24.Set(value_h1); Double value_h1_120 = MyAvg.Avg(h1_list,120); if(value_h1_120 > 0 ){ h1_120.Set(value_h1_120); } } private void cal_h4(){ DateTime dt = Bars.Time[0]; DateTime lastdt = Bars.Time[1]; int currentx = dt.Day*100+ dt.Hour; int lastx = lastdt.Day*100+ lastdt.Hour; if(currentx != lastx && (dt.Hour==0 || dt.Hour==4 || dt.Hour==8 || dt.Hour==12 || dt.Hour==16 || dt.Hour==20)) h4_list.Add(Bars.Close[1]); Double value_h4_120 = MyAvg.Avg(h4_list,120); if(value_h4_120 > 0 ){ h4_120.Set(value_h4_120); } } int current_d1 = 0 ; private void cal_d1(){ DateTime dt = Bars.Time[0]; DateTime lastdt = Bars.Time[1]; int currentx = dt.Day; int lastx = lastdt.Day; if(current_d1 != dt.Day) { d1_list.Add(Bars.Close[0]); current_d1 = dt.Day; }else{ //干掉 最后一条 d1_list.RemoveAt(d1_list.Count-1); d1_list.Add(Bars.Close[0]); List //Output.WriteLine(" currend1= "+current_d1+" day=>"+dt.Day); Double value_d1_10 = MyAvg.Avg(d1_list,10); if(value_d1_10 > 0 ){ d1_10.Set(value_d1_10); } } } }