MC 在1分钟图拿出5分钟,15分钟,30分钟,1小时的K线

using System;
using System.Drawing;
using System.Linq;
using System.Collections;
 
 
namespace PowerLanguage
{
    namespace Function
    {
        public class OtherFrame
        {
 
 
            DateTime d;double o=0; double h=0; double l=0;double c=0;
 
 
            ArrayList listm5 = null;
            ArrayList listm15 = null;
            ArrayList listm30=null;
            ArrayList listh1 = null;
            public OtherFrame()
            {
 
                listm5 = new ArrayList();
                listm15 = new ArrayList();
 
                listm30 = new ArrayList();
                listh1 = new ArrayList();
 
            }
 
 
 
 
            public void setBarsData(DateTime d, double o, double h, double l, double c)
            {
                this.c = c;
                this.o = o;
                this.h = h;
                this.l = l;
                this.d = d;
                calM30();
                calH1();
                calM15();
                calm5();
            }
 
            public ArrayList getm5list()
            {
                return listm5;
 
 
            }
            public ArrayList getm15list()
            {
 
                    return listm15;
 
 
            }
 
            public ArrayList getm30list()
            {
                return listm30;
 
 
            }
 
            public ArrayList getH1list()
            {
 
                return listh1;
 
 
            }
 
 
 
 
 
 
 
            int lasthour = -1;
 
            double temp_open_h1 = 0;
            double temp_high_h1 = 0;
            double temp_low_h1 = 0;
 
 
 
            ///小时线的算法
            void calH1()
            {
 
 
 
                if (lasthour != d.Hour && d.Minute > 0)
                {
 
                    temp_high_h1 = h;
                    temp_low_h1 = l;
 
 
                    temp_open_h1 = o;
                    OLHC olhc = new OLHC();
                    olhc.close = c;
                    olhc.open = temp_open_h1;
                    olhc.high = temp_high_h1;
                    olhc.low = temp_low_h1;
 
                    if (listh1.Count == 0) listh1.Add(olhc);
                    else listh1.Insert(0, olhc);
 
 
                    lasthour = d.Hour;
                }
                else
                {
 
                    if (temp_high_h1 == 0 || h > temp_high_h1) temp_high_h1 = h;
                    if (temp_low_h1 == 0 || l < temp_low_h1) temp_low_h1 = l;
                    if (listh1.Count > 0)
                    {
 
                        OLHC olhc = (OLHC)listh1[0];
                        olhc.close = c;
                        olhc.high = temp_high_h1;
                        olhc.low = temp_low_h1;
                        listh1[0] = olhc;
 
                    }
 
 
 
 
 
                }
 
            }
 
 
 
 
 
 
 
 
 
 
            int last30min = -1;
 
            double temp_open_m30 = 0;
            double temp_high_m30 = 0;
            double temp_low_m30 = 0;
 
            void calM30()
            {
 
 
                int willlast = 0;
                if (d.Minute >= 1 && d.Minute <= 30) willlast = 0;
                if (d.Minute >= 31 || d.Minute == 0) willlast = 30;
 
 
 
 
                if (willlast != last30min)
                {
                    temp_high_m30 = h;
                    temp_low_m30 = l;
 
 
                    temp_open_m30 = o;
                    OLHC olhc = new OLHC();
                    olhc.close = c;
                    olhc.open = temp_open_m30;
                    olhc.high = temp_high_m30;
                    olhc.low = temp_low_m30;
                    if (listm30.Count == 0) listm30.Add(olhc);
                    else listm30.Insert(0, olhc);
 
 
 
                    last30min = willlast;
 
 
                }
                else
                {
                    if (temp_high_m30 == 0 || h > temp_high_m30) temp_high_m30 = h;
                    if (temp_low_m30 == 0 || l < temp_low_m30) temp_low_m30 = l;
                    if (listm30.Count > 0)
                    {
 
                        OLHC olhc = (OLHC)listm30[0];
                        olhc.close = c;
                        olhc.high = temp_high_m30;
                        olhc.low = temp_low_m30;
                        listm30[0] = olhc;
 
                    }
 
 
 
 
 
                }
 
 
 
            }
 
            //---------------------------------------------
 
            int last15min = -1;
 
            double temp_open_m15 = 0;
            double temp_high_m15 = 0;
            double temp_low_m15 = 0;
            void calM15()
            {
 
 
 
                int willlast = 0;
                if (d.Minute >= 1 && d.Minute <= 15){ willlast = 0;}
                if (d.Minute >= 16 && d.Minute <= 30) willlast = 15;
                if (d.Minute >= 31 && d.Minute <= 45) willlast = 30;
                if (d.Minute >= 46 || d.Minute == 0) willlast = 45;
 
 
 
 
                //HTTP.write("C:\mc\e.xxx",d+"   "+ last15min +"   "+willlast+" "+"
");
 
                if (willlast != last15min)
                {
                    temp_high_m15 = h;
                    temp_low_m15 = l;
 
 
                    temp_open_m15 = o;
                    OLHC olhc = new OLHC();
                    olhc.close = c;
                    olhc.open = temp_open_m15;
                    olhc.high = temp_high_m15;
                    olhc.low = temp_low_m15;
                    if (listm15.Count == 0) listm15.Add(olhc);
                    else listm15.Insert(0, olhc);
 
 
 
                    last15min = willlast;
 
 
                }
                else
                {
                    if (temp_high_m15 == 0 || h > temp_high_m15) temp_high_m15 = h;
                    if (temp_low_m15 == 0 || l < temp_low_m15) temp_low_m15 = l;
                    if (listm15.Count > 0)
                    {
 
                        OLHC olhc = (OLHC)listm15[0];
                        olhc.close = c;
                        olhc.high = temp_high_m15;
                        olhc.low = temp_low_m15;
                        listm15[0] = olhc;
 
                    }
 
 
 
 
 
                }
 
 
 
            }
 
//--------------------------------
 
            int last5min = -1;
 
            double temp_open_m5 = 0;
            double temp_high_m5 = 0;
            double temp_low_m5 = 0;
            void calm5()
            {
 
 
                int willlast = 0;
                if (d.Minute >= 1 && d.Minute <= 5) willlast = 0;
                if (d.Minute >= 6 && d.Minute <= 10) willlast = 15;
                if (d.Minute >= 11 && d.Minute <= 15) willlast = 30;
                if (d.Minute >= 16 && d.Minute <= 20) willlast = 0;
                if (d.Minute >= 21 && d.Minute <= 25) willlast = 15;
                if (d.Minute >= 26 && d.Minute <= 30) willlast = 30;
                if (d.Minute >= 31 && d.Minute <= 35) willlast = 15;
                if (d.Minute >= 36 && d.Minute <= 40) willlast = 30;
                if (d.Minute >= 41 && d.Minute <= 45) willlast = 0;
                if (d.Minute >= 46 && d.Minute <= 50) willlast = 15;
                if (d.Minute >= 51 && d.Minute <= 55) willlast = 30;
                if (d.Minute >= 56 || d.Minute == 0) willlast = 45;
 
 
 
                if (willlast != last5min)
                {
                    temp_high_m5 = h;
                    temp_low_m5 = l;
 
 
                    temp_open_m5 = o;
                    OLHC olhc = new OLHC();
                    olhc.close = c;
                    olhc.open = temp_open_m5;
                    olhc.high = temp_high_m5;
                    olhc.low = temp_low_m5;
                    if (listm5.Count == 0) listm5.Add(olhc);
                    else listm5.Insert(0, olhc);
 
 
 
                    last5min = willlast;
 
 
                }
                else
                {
                    if (temp_high_m5 == 0 || h > temp_high_m5) temp_high_m5 = h;
                    if (temp_low_m5 == 0 || l < temp_low_m5) temp_low_m5 = l;
                    if (listm5.Count > 0)
                    {
 
                        OLHC olhc = (OLHC)listm5[0];
                        olhc.close = c;
                        olhc.high = temp_high_m5;
                        olhc.low = temp_low_m5;
                        listm5[0] = olhc;
 
                    }
 
 
 
 
 
                }
 
 
 
            }
 
            //--------------------------------
 
 
 
 
        }
    }
}
原文地址:https://www.cnblogs.com/aliblogs/p/5493805.html