Пример #1
0
        public List<SQLiteKit> CalTime(String path, int sec, int scope)
        {
            TickBase tickBase = new TickBase(path);
            TickBaseHandle handle = new TickBaseHandle();
            GraphBase graphBase = new GraphBase(System.DateTime.Now, 100);
            FutureTick tick;
            TickGraph graph = new TickGraph();
            TickGraph average = new TickGraph();
            TickGraph[] graph_a = new TickGraph[50];
            TickGraph[] average_a = new TickGraph[50];
            
            int lastHandle = 0;
            int lastSec = 0;
            int lastPrice = 0;
            int dotPV = 0;
            graphBase.CreateTable("TXF_K");
            graphBase.CreateTable("TXF_A");
            for (int i = 1; i <= 50; i++)
            {
                String table = String.Format("TXF_K{0}", i);
                graphBase.CreateTable(table);
                graph_a[i - 1] = new TickGraph();

                table = String.Format("TXF_A{0}", i);
                graphBase.CreateTable(table);
                average_a[i - 1] = new TickGraph();
            }

            do
            {
                tick = tickBase.GetFutureTick("TXF", ref handle);
                
                if (tick == null)
                {
                    break;
                }

                if (graph.type == TICK_GRAPH.TICK_GRAPH_NONE)
                {
                    lastSec = tick.seqsec;
                    lastPrice = tick.price;
                    dotPV = 0;
                    graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                    graph.value[TickGraph.VALUE_A] = tick.price;
                    graph.value[TickGraph.VALUE_B] = tick.price;
                    graph.value[TickGraph.VALUE_C] = tick.price;
                    graph.value[TickGraph.VALUE_D] = tick.price;
                    graph.value[TickGraph.VALUE_E] = handle.index;

                    average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                    average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                    average.value[TickGraph.VALUE_C] = tick.quanty;
                }
                else
                {

                    if (/*tick.price - graph.value[TickGraph.VALUE_D] > scope 
                        || graph.value[TickGraph.VALUE_C] - tick.price > scope
                        || */tick.seqsec - lastSec >= sec || lastHandle != handle.index)
                    //if (Math.Abs(dotPV) > scope)
                    {
                        lastSec = tick.seqsec;
                        lastHandle = handle.index;
                        average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];
                        graphBase.AddNewItem("TXF_A", average);

                        graph.value[TickGraph.VALUE_K] = dotPV;
                        graphBase.AddNewItem("TXF_K", graph);

                        graph = new TickGraph();
                        graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                        graph.value[TickGraph.VALUE_A] = tick.price;
                        graph.value[TickGraph.VALUE_B] = tick.price;
                        graph.value[TickGraph.VALUE_C] = tick.price;
                        graph.value[TickGraph.VALUE_D] = tick.price;
                        graph.value[TickGraph.VALUE_E] = handle.index;

                        average = new TickGraph();
                        average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                        average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                        average.value[TickGraph.VALUE_C] = tick.quanty;

                        for (int i = 1; i <= 50; i++)
                        {
                            graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                            graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);
                            String table = String.Format("TXF_K{0}", i);
                            graphBase.AddNewItem(table, graph_a[i - 1]);

                            average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                            average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_A, i);
                            table = String.Format("TXF_A{0}", i);
                            graphBase.AddNewItem(table, average_a[i - 1]);

                        }

                        dotPV = 0;
                        lastPrice = tick.price;
                    }
                    else
                    {
                        graph.value[TickGraph.VALUE_B] = tick.price;
                        if (tick.price > graph.value[TickGraph.VALUE_C]) graph.value[TickGraph.VALUE_C] = tick.price;
                        if (tick.price < graph.value[TickGraph.VALUE_D]) graph.value[TickGraph.VALUE_D] = tick.price;

                        average.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                        average.value[TickGraph.VALUE_C] += tick.quanty;
                        if (tick.price >= lastPrice)
                        {
                            dotPV += (tick.price - lastPrice) * (tick.price - lastPrice) * tick.quanty;
                        }
                        else
                        {
                            dotPV -= (tick.price - lastPrice) * (tick.price - lastPrice) * tick.quanty;
                        }
                        lastPrice = tick.price;


                    }

                }
            } while (true);

            return tickBase.GetFiles();
        }
Пример #2
0
        public void CalSimple(String path, int main, int slowAmount, int fastAmount)
        {
            int end = 0;
            TickBase tickBase = new TickBase(path);
            TickBaseHandle handle = new TickBaseHandle();
            GraphBase graphBase = new GraphBase(System.DateTime.Now, 100);
            FutureTick tick;
            TickGraph graph = new TickGraph();
            TickGraph average = new TickGraph();
            
            TickGraph[] graph_a = new TickGraph[50];
            TickGraph[] average_a = new TickGraph[50];

            TickGraph nowAverage = null;
            TickGraph nowGraph = null;

            TickGraph lastAverage = null;
            TickGraph lastGraph = null;
            double preDiff = 0;
            double nowDiff = 0;
            int cond = 0;

            int type = (int)TRADE_TYPE.TRADE_NONE;
            double lastMain = -1;
            double fastMain = -1;
            double lastPrice = -1;
            double lastSlowAmount = -1;
            double lastFastAmount = -1;
            double maxDiff = 0;

            graphBase.CreateTable("TXF_K");
            graphBase.CreateTable("TXF_A");
            for (int i = 1; i <= 50; i++)
            {
                String table = String.Format("TXF_K{0}", i);
                graphBase.CreateTable(table);
                graph_a[i - 1] = new TickGraph();

                table = String.Format("TXF_A{0}", i);
                graphBase.CreateTable(table);
                average_a[i - 1] = new TickGraph();
            }

            do
            {
                tick = tickBase.GetFutureTick("TXF", ref handle);
                if (tick == null)
                {
                    average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];

                    nowGraph = graph;
                    nowAverage = average;
                    for (int i = 1; i <= 50; i++)
                    {
                        graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                        graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);
                        String table = String.Format("TXF_K{0}", i);
                        graphBase.AddNewItem(table, graph_a[i - 1]);

                        average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                        average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_A, i);
                        table = String.Format("TXF_A{0}", i);
                        graphBase.AddNewItem(table, average_a[i - 1]);

                    }

                    graphBase.AddNewItem("TXF_A", nowAverage);
                    graphBase.AddNewItem("TXF_K", nowGraph);

                    break;
                }
                if (graph.type == TICK_GRAPH.TICK_GRAPH_NONE)
                {
                    graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                    graph.value[TickGraph.VALUE_A] = tick.price;
                    graph.value[TickGraph.VALUE_B] = tick.price;
                    graph.value[TickGraph.VALUE_C] = tick.price;
                    graph.value[TickGraph.VALUE_D] = tick.price;
                    graph.value[TickGraph.VALUE_E] = handle.index;

                    average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                    average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                    average.value[TickGraph.VALUE_C] = tick.quanty;

                    lastPrice = tick.price;
                    lastSlowAmount = 0;
                    lastFastAmount = 0;
                }
                else
                {
                    /*if (fastAmount == -1)
                    {
                        if (tick.price < graph.value[TickGraph.VALUE_D] || graph.value[TickGraph.VALUE_C] < tick.price)
                        {

                            average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];
                            graphBase.AddNewItem("TXF_A", average);

                            graphBase.AddNewItem("TXF_K", graph);

                            graph = new TickGraph();
                            graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                            graph.value[TickGraph.VALUE_A] = tick.price;
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            graph.value[TickGraph.VALUE_C] = tick.price;
                            graph.value[TickGraph.VALUE_D] = tick.price;
                            graph.value[TickGraph.VALUE_E] = handle.index;

                            average = new TickGraph();
                            average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                            average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] = tick.quanty;

                            for (int i = 1; i <= 50; i++)
                            {
                                graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);
                                String table = String.Format("TXF_K{0}", i);
                                graphBase.AddNewItem(table, graph_a[i - 1]);

                                average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_A, i);
                                table = String.Format("TXF_A{0}", i);
                                graphBase.AddNewItem(table, average_a[i - 1]);

                            }

                            fastAmount = range;
                        }
                        else
                        {
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            average.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] += tick.quanty;
                        }

                    }
                    else*/
                    {
                        if (lastSlowAmount > slowAmount
                            || lastFastAmount > fastAmount
                            || preDiff * nowDiff < 0 
                            || (preDiff > 0 && tick.price < graph.value[TickGraph.VALUE_A]) 
                            || (preDiff < 0 && tick.price > graph.value[TickGraph.VALUE_A])
                            || tick.price > average_a[main - 1].value[TickGraph.VALUE_A] && average.value[TickGraph.VALUE_A] < average_a[main - 1].value[TickGraph.VALUE_A]
                            || tick.price < average_a[main - 1].value[TickGraph.VALUE_A] && average.value[TickGraph.VALUE_A] > average_a[main - 1].value[TickGraph.VALUE_A])
                        {
                            lastPrice = tick.price;
                            if (lastSlowAmount > slowAmount)
                            {
                                lastSlowAmount = 0;
                            }
                            lastFastAmount = 0;

                            average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];

                            if (nowAverage != null)
                            {
                                preDiff = average.value[TickGraph.VALUE_A] - nowAverage.value[TickGraph.VALUE_A];
                                cond = 1;
                            }

                            nowGraph = graph;
                            graph = new TickGraph();
                            graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                            graph.value[TickGraph.VALUE_A] = tick.price;
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            graph.value[TickGraph.VALUE_C] = tick.price;
                            graph.value[TickGraph.VALUE_D] = tick.price;
                            graph.value[TickGraph.VALUE_E] = handle.index;

                            nowAverage = average;
                            average = new TickGraph();
                            average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                            average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] = tick.quanty;


                            for (int i = 1; i <= 50; i++)
                            {
                                graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);
                                String table = String.Format("TXF_K{0}", i);
                                graphBase.AddNewItem(table, graph_a[i - 1]);

                                average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_A, i);
                                table = String.Format("TXF_A{0}", i);
                                graphBase.AddNewItem(table, average_a[i - 1]);

                            }

                            /********************/
#if false
                            if (lastMain == -1)
                            {
                                if (average_a[main - 1].value[TickGraph.VALUE_A] != 0)
                                {
                                    lastMain = average_a[main - 1].value[TickGraph.VALUE_A];
                                    maxDiff = average_a[main - 1].value[TickGraph.VALUE_A] - lastMain;
                                    fastMain = average_a[main - 1].value[TickGraph.VALUE_A];
                                }
                            }
                            else
                            {
                                

                                if (type == (int)TRADE_TYPE.TRADE_BUY_OPEN)
                                {
                                    if (maxDiff < average_a[main - 1].value[TickGraph.VALUE_A] - lastMain)
                                    {
                                        maxDiff = average_a[main - 1].value[TickGraph.VALUE_A] - lastMain;
                                        if (average_a[main - 1].value[TickGraph.VALUE_A] > fastMain + maxDiff)
                                        {
                                            fastMain = average_a[main - 1].value[TickGraph.VALUE_A];
                                        }
                                        else
                                        {
                                            fastMain += maxDiff;
                                        }
                                    }
                                    else
                                    {
                                        fastMain += maxDiff;

                                    }

                                    if (nowAverage.value[TickGraph.VALUE_A] < fastMain)
                                    {
                                        performance += AddSell(tick.price);
                                        //lastprice = tick.price;
                                        lastGraph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_SELL_OPEN;
                                        lastGraph.value[TickGraph.VALUE_I] = (long)tick.price;

                                        /*if (tick.price - lastprice < 0) bound--;
                                        else bound++;
                                        if (bound <= 0) bound = 1;
                                        if (bound > savg) bound = savg;*/

                                        lastGraph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                        Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, lastGraph.value[TickGraph.VALUE_J]);

                                        type = (int)TRADE_TYPE.TRADE_NONE;
                                    }


                                }
                                else if (type == (int)TRADE_TYPE.TRADE_SELL_OPEN)
                                {
                                    if (maxDiff > average_a[main - 1].value[TickGraph.VALUE_A] - lastMain)
                                    {
                                        maxDiff = average_a[main - 1].value[TickGraph.VALUE_A] - lastMain;
                                        if (average_a[main - 1].value[TickGraph.VALUE_A] < fastMain + maxDiff)
                                        {
                                            fastMain = average_a[main - 1].value[TickGraph.VALUE_A];
                                        }
                                        else
                                        {
                                            fastMain += maxDiff;
                                        }
                                    }
                                    else
                                    {
                                        fastMain += maxDiff;
                                    }


                                    if (nowAverage.value[TickGraph.VALUE_A] > fastMain)
                                    {
                                        performance += AddBuy(tick.price);
                                        //lastprice = tick.price;
                                        lastGraph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_BUY_OPEN;
                                        lastGraph.value[TickGraph.VALUE_I] = (long)tick.price;

                                        /*if (lastprice - tick.price < 0) bound--;
                                        else bound++;
                                        if (bound <= 0) bound = 1;
                                        if (bound > savg) bound = savg;*/

                                        lastGraph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                        Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Sell", performance, tick.price, lastGraph.value[TickGraph.VALUE_J]);

                                        type = (int)TRADE_TYPE.TRADE_NONE;
                                    }
                                }

                                if (type == (int)TRADE_TYPE.TRADE_NONE)
                                {
                                    if (nowAverage.value[TickGraph.VALUE_A] > average_a[main - 1].value[TickGraph.VALUE_A])
                                    {
                                        performance += AddBuy(tick.price);
                                        //lastPrice = tick.price;
                                        lastGraph.value[TickGraph.VALUE_F] = (long)TRADE_TYPE.TRADE_BUY_OPEN;
                                        lastGraph.value[TickGraph.VALUE_G] = (long)tick.price;

                                        lastGraph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                        type = (int)TRADE_TYPE.TRADE_BUY_OPEN;
                                        Console.WriteLine("performance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, lastGraph.value[TickGraph.VALUE_J]);
                                    }
                                    else if (nowAverage.value[TickGraph.VALUE_A] < average_a[main - 1].value[TickGraph.VALUE_A])
                                    {
                                        performance += AddSell(tick.price);
                                        //lastprice = tick.price;
                                        lastGraph.value[TickGraph.VALUE_F] = (long)TRADE_TYPE.TRADE_SELL_OPEN;
                                        lastGraph.value[TickGraph.VALUE_G] = (long)tick.price;

                                        lastGraph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                        type = (int)TRADE_TYPE.TRADE_SELL_OPEN;
                                        Console.WriteLine("performance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, lastGraph.value[TickGraph.VALUE_J]);
                                    }
                                    maxDiff = average_a[main - 1].value[TickGraph.VALUE_A] - lastMain;
                                    fastMain = average_a[main - 1].value[TickGraph.VALUE_A];
                                }

                                lastMain = average_a[main - 1].value[TickGraph.VALUE_A];
                            }
                            
#if false
                                    if (average.value[TickGraph.VALUE_A] <= average_a[main - 1].value[TickGraph.VALUE_A])
                                {
                                    if (type == (int)TRADE_TYPE.TRADE_BUY_OPEN)
                                    {
                                        performance += AddSell(tick.price);
                                        //lastprice = tick.price;
                                        graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_BUY_CLOSE;
                                        graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                        /*if (tick.price - lastprice < 0) bound--;
                                        else bound++;
                                        if (bound <= 0) bound = 1;
                                        if (bound > savg) bound = savg;*/

                                        graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                        Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);

                                        type = (int)TRADE_TYPE.TRADE_NONE;
                                    }
                                }
                                else if (average.value[TickGraph.VALUE_A] >= average_a[main - 1].value[TickGraph.VALUE_A])
                                {
                                    if (type == (int)TRADE_TYPE.TRADE_SELL_OPEN)
                                    {
                                        performance += AddBuy(tick.price);
                                        //lastprice = tick.price;
                                        graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_SELL_CLOSE;
                                        graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                        /*if (lastprice - tick.price < 0) bound--;
                                        else bound++;
                                        if (bound <= 0) bound = 1;
                                        if (bound > savg) bound = savg;*/

                                        graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                        Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Sell", performance, tick.price, graph.value[TickGraph.VALUE_J]);

                                        type = (int)TRADE_TYPE.TRADE_NONE;
                                    }
                                }

                                lastAverage = average_a[main - 1].value[TickGraph.VALUE_A];

                            }
#endif
#endif
                            /********************/

                            graphBase.AddNewItem("TXF_A", nowAverage);
                            graphBase.AddNewItem("TXF_K", nowGraph);
                        }
                        else
                        {
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            if (tick.price > graph.value[TickGraph.VALUE_C]) graph.value[TickGraph.VALUE_C] = tick.price;
                            if (tick.price < graph.value[TickGraph.VALUE_D]) graph.value[TickGraph.VALUE_D] = tick.price;

                            average.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] += tick.quanty;

                            if (lastPrice < tick.price)
                            {
                                lastSlowAmount += (tick.price - lastPrice) * tick.quanty;
                                lastFastAmount += (tick.price - lastPrice) * tick.quanty;
                            }
                            else
                            {
                                lastSlowAmount += (lastPrice - tick.price) * tick.quanty;
                                lastFastAmount += (lastPrice - tick.price) * tick.quanty;
                            }

                            if (nowAverage != null)
                            {
                                average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];
                                nowDiff = average.value[TickGraph.VALUE_A] - nowAverage.value[TickGraph.VALUE_A];
                            }
                        }


                        
                    }
                }
            } while (true);

        }
Пример #3
0
        public List<SQLiteKit> CalForce(String path, int scope, int stop)
        {
            TickBase tickBase = new TickBase(path);
            TickBaseHandle handle = new TickBaseHandle();
            GraphBase graphBase = new GraphBase(System.DateTime.Now, 100);
            FutureTick tick;
            TickGraph graph = new TickGraph();
            TickGraph average = new TickGraph();
            TickGraph[] graph_a = new TickGraph[50];
            TickGraph[] average_a = new TickGraph[50];

            int seq = 0;
            int make = 0;

            long lastSec = 0;
            long lastPrice = 0;
            long lastAvg = 0;
            long lastDirect = 0;

            long lastHigh = 0;
            long lastLow = 0;
            long lastIndex = 0;

            long td = 0;
            long direct = 0;
            long dotPV = 0;
            long posForce = 0;
            long nagForce = 0;
            Performance per = new Performance();
            graphBase.CreateTable("TXF_K");
            graphBase.CreateTable("TXF_A");
            for (int i = 1; i <= 50; i++)
            {
                String table = String.Format("TXF_K{0}", i);
                graphBase.CreateTable(table);
                graph_a[i - 1] = new TickGraph();

                table = String.Format("TXF_A{0}", i);
                graphBase.CreateTable(table);
                average_a[i - 1] = new TickGraph();
            }

            do
            {
                tick = tickBase.GetFutureTick("TXF", ref handle);
                if (tick == null)
                {
                    break;
                }

                if (tick.buy < 0 && tick.sell < 0)
                {
                    continue;
                }


                if (graph.type == TICK_GRAPH.TICK_GRAPH_NONE)
                {
                    lastSec = tick.seqsec;
                    lastPrice = tick.price;
                    dotPV = 0; 
                    graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                    graph.value[TickGraph.VALUE_A] = tick.price;
                    graph.value[TickGraph.VALUE_B] = tick.price;
                    graph.value[TickGraph.VALUE_C] = tick.price;
                    graph.value[TickGraph.VALUE_D] = tick.price;
                    graph.value[TickGraph.VALUE_E] = handle.index;
                    
                    average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                    average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                    average.value[TickGraph.VALUE_C] = tick.quanty;
                    average.value[TickGraph.VALUE_A] = tick.price;

                    lastAvg = -1;
                    lastDirect = 0;
                }
                else
                {

                    /*if (tick.price - graph.value[TickGraph.VALUE_D] > scope 
                        || graph.value[TickGraph.VALUE_C] - tick.price > scope
                        || tick.seqsec - lastSec >= sec)*/
                    //if (Math.Abs(dotPV) > Math.Abs(average.value[TickGraph.VALUE_A] - lastAvg) * scope
                    if (Math.Abs(dotPV) > scope
                    /*if (per.num == 0 && Math.Abs(dotPV) > scope
                        || per.num > 0 && Math.Abs(dotPV) > (scope / per.num)*/
                        /*|| direct > 0 && dotPV < -stop
                        || direct < 0 && dotPV > stop*/
                        || td == 0 && direct > 0 && average.value[TickGraph.VALUE_A] < lastAvg
                        || td > 0 && tick.price > td
                        || td == 0 && direct < 0 && average.value[TickGraph.VALUE_A] > lastAvg
                        || td < 0 && tick.price < -td
                        || direct > 0 && tick.price < lastLow
                        || direct < 0 && tick.price > lastHigh
                        || handle.last == 1)
                    {
                        
                       
                        td = 0;

                        if (lastAvg != -1)
                        {
                            if (direct > 0 && average.value[TickGraph.VALUE_A] < lastAvg)
                            {
                                td = lastHigh;
                            }
                            else if (direct < 0 && average.value[TickGraph.VALUE_A] > lastAvg)
                            {
                                td = -lastLow;
                            }

                            if (average.value[TickGraph.VALUE_A] > lastAvg)
                            {
                                direct = 1;
                            }
                            else if (average.value[TickGraph.VALUE_A] < lastAvg)
                            {
                                direct = -1;
                            }
                        }

                        average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];

                        /*if (dotPV > 0)
                        {
                            direct = 1;
                        }
                        else if (dotPV < 0)
                        {
                            direct = -1;
                        }*/


                        graph.value[TickGraph.VALUE_J] = direct;
                        graph.value[TickGraph.VALUE_K] = dotPV;

                        seq++;
                        if (handle.last == 1/* || average.value[TickGraph.VALUE_A] == lastAvg*/)
                        {
                            per = Reduce(tick.price, seq, -1);
                            graph.value[TickGraph.VALUE_F] = 0;
                            graph.value[TickGraph.VALUE_G] = per.price;
                            graph.value[TickGraph.VALUE_H] = per.perf;
                            graph.value[TickGraph.VALUE_I] = per.total;
                            Console.WriteLine("\tmake = {0} , Buy {1}", per.total, tick.price);
                        }
                        else if (direct == 1)
                        {
                            if (average.value[TickGraph.VALUE_A] > lastAvg)
                            {
                                per = AddBuy(tick.price, seq);
                                graph.value[TickGraph.VALUE_F] = 1;
                                graph.value[TickGraph.VALUE_G] = per.price;
                                graph.value[TickGraph.VALUE_H] = per.perf;
                                graph.value[TickGraph.VALUE_I] = per.total;
                                Console.WriteLine("\tmake = {0} , Buy {1}", per.total, tick.price);
                            } else if (dotPV < 0 || average.value[TickGraph.VALUE_A] < lastAvg)
                            {
                                per = AddSell(tick.price, seq);
                                graph.value[TickGraph.VALUE_F] = -1;
                                graph.value[TickGraph.VALUE_G] = per.price;
                                graph.value[TickGraph.VALUE_H] = per.perf;
                                graph.value[TickGraph.VALUE_I] = per.total;
                                Console.WriteLine("\tmake = {0} , Sell {1}", per.total, tick.price);
                            }
                            
                        }
                        else if (direct == -1)
                        {
                            if (average.value[TickGraph.VALUE_A] < lastAvg)
                            {
                                per = AddSell(tick.price, seq);
                                graph.value[TickGraph.VALUE_F] = -1;
                                graph.value[TickGraph.VALUE_G] = per.price;
                                graph.value[TickGraph.VALUE_H] = per.perf;
                                graph.value[TickGraph.VALUE_I] = per.total;
                                Console.WriteLine("\tmake = {0} , Sell {1}", per.total, tick.price);
                            }
                            else if (dotPV > 0 || average.value[TickGraph.VALUE_A] > lastAvg)
                            {
                                per = AddBuy(tick.price, seq);
                                graph.value[TickGraph.VALUE_F] = 1;
                                graph.value[TickGraph.VALUE_G] = per.price;
                                graph.value[TickGraph.VALUE_H] = per.perf;
                                graph.value[TickGraph.VALUE_I] = per.total;
                                Console.WriteLine("\tmake = {0} , Buy {1}", per.total, tick.price);
                            }
                        }


                        graph.value[TickGraph.VALUE_L] = posForce;
                        graph.value[TickGraph.VALUE_M] = nagForce;
                        graph.value[TickGraph.VALUE_N] = td;

                        dotPV = 0;
                        posForce = 0;
                        nagForce = 0;
                        lastSec = tick.seqsec;
                        lastIndex = handle.index;
                        lastPrice = tick.price;
                        lastAvg = average.value[TickGraph.VALUE_A];

                        lastHigh = graph.value[TickGraph.VALUE_C];
                        lastLow = graph.value[TickGraph.VALUE_D];

                        graphBase.AddNewItem("TXF_A", average);
                        seq = graphBase.AddNewItem("TXF_K", graph);


                        graph = new TickGraph();
                        graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                        graph.value[TickGraph.VALUE_A] = tick.price;
                        graph.value[TickGraph.VALUE_B] = tick.price;
                        graph.value[TickGraph.VALUE_C] = tick.price;
                        graph.value[TickGraph.VALUE_D] = tick.price;
                        graph.value[TickGraph.VALUE_E] = handle.index;

                        average = new TickGraph();
                        average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                        average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                        average.value[TickGraph.VALUE_C] = tick.quanty;
                        average.value[TickGraph.VALUE_A] = tick.price;

                        for (int i = 1; i <= 50; i++)
                        {
                            graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                            graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);
                            String table = String.Format("TXF_K{0}", i);
                            graphBase.AddNewItem(table, graph_a[i - 1]);

                            average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                            average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_A, i);
                            table = String.Format("TXF_A{0}", i);
                            graphBase.AddNewItem(table, average_a[i - 1]);

                        }
                    }
                    else
                    {
                        graph.value[TickGraph.VALUE_B] = tick.price;
                        if (tick.price > graph.value[TickGraph.VALUE_C]) graph.value[TickGraph.VALUE_C] = tick.price;
                        if (tick.price < graph.value[TickGraph.VALUE_D]) graph.value[TickGraph.VALUE_D] = tick.price;

                        average.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                        average.value[TickGraph.VALUE_C] += tick.quanty;
                        average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];
                        if (tick.price >= lastPrice)
                        {
                            long f = (tick.price - lastPrice) * (tick.price - lastPrice) * tick.quanty;
                            dotPV += f;
                            posForce += f;
                        }
                        else
                        {
                            long f = (tick.price - lastPrice) * (tick.price - lastPrice) * tick.quanty;
                            dotPV -= f;
                            nagForce += f;
                        }
                        lastPrice = tick.price;

                        
                    }
                    
                }
            } while (true);

            return tickBase.GetFiles();
        }
Пример #4
0
        public void CalAvk(String path, int range)
        {
            int bound = 1;
            int pretype = (int)TRADE_TYPE.TRADE_NONE;
            long lastprice = -1;
            int type = (int)TRADE_TYPE.TRADE_NONE;
            int step = range;

            TickBase tickBase = new TickBase(path);
            TickBaseHandle handle = new TickBaseHandle();
            GraphBase graphBase = new GraphBase(System.DateTime.Now, 100);

            FutureTick tick;
            TickGraph lastGraph;
            TickGraph graph = new TickGraph();
            TickGraph slowAverage;
            TickGraph fastAverage;
            TickGraph lastAverage;
            TickGraph temp = new TickGraph();
            TickGraph average = new TickGraph();
            TickGraph[] graph_a = new TickGraph[50];
            TickGraph[] average_a = new TickGraph[50];

            String table;
            graphBase.CreateTable("TXF_AK");
            
            do
            {
                tick = tickBase.GetFutureTick("TXF", ref handle);
                if (tick == null)
                {
                    break;
                }
                if (graph.type == TICK_GRAPH.TICK_GRAPH_NONE)
                {

                    temp.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                    temp.value[TickGraph.VALUE_C] = tick.quanty;
                    temp.value[TickGraph.VALUE_A] = temp.value[TickGraph.VALUE_B] / temp.value[TickGraph.VALUE_C];

                    graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                    graph.value[TickGraph.VALUE_A] = temp.value[TickGraph.VALUE_A];
                    graph.value[TickGraph.VALUE_B] = temp.value[TickGraph.VALUE_A];
                    graph.value[TickGraph.VALUE_C] = temp.value[TickGraph.VALUE_A];
                    graph.value[TickGraph.VALUE_D] = temp.value[TickGraph.VALUE_A];
                    graph.value[TickGraph.VALUE_E] = handle.index;

                }
                else
                {
                    lastGraph = null;
                    lastGraph = graphBase.GetLatestItem("TXF_AK");

                    temp.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                    temp.value[TickGraph.VALUE_C] += tick.quanty;
                    temp.value[TickGraph.VALUE_A] = temp.value[TickGraph.VALUE_B] / temp.value[TickGraph.VALUE_C];

                    if (step == -1)
                    {
                        if (temp.value[TickGraph.VALUE_A] <= graph.value[TickGraph.VALUE_D] || graph.value[TickGraph.VALUE_C] <= temp.value[TickGraph.VALUE_A])
                        {
                            graphBase.UpdateLatestItem("TXF_AK", graph);

                            //temp.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                            //temp.value[TickGraph.VALUE_C] = tick.quanty;
                            //temp.value[TickGraph.VALUE_A] = temp.value[TickGraph.VALUE_B] / temp.value[TickGraph.VALUE_C];

                            graph = new TickGraph();
                            graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                            graph.value[TickGraph.VALUE_A] = temp.value[TickGraph.VALUE_A];
                            graph.value[TickGraph.VALUE_B] = temp.value[TickGraph.VALUE_A];
                            graph.value[TickGraph.VALUE_C] = temp.value[TickGraph.VALUE_A];
                            graph.value[TickGraph.VALUE_D] = temp.value[TickGraph.VALUE_A];
                            graph.value[TickGraph.VALUE_E] = handle.index;

                            step = range;
                        }
                        else
                        {
                            graph.value[TickGraph.VALUE_B] = temp.value[TickGraph.VALUE_A];
                            if (temp.value[TickGraph.VALUE_A] > graph.value[TickGraph.VALUE_C]) graph.value[TickGraph.VALUE_C] = temp.value[TickGraph.VALUE_A];
                            if (temp.value[TickGraph.VALUE_A] < graph.value[TickGraph.VALUE_D]) graph.value[TickGraph.VALUE_D] = temp.value[TickGraph.VALUE_A];
                        }
                    }
                    else
                    {
                        if (lastGraph != null && lastGraph.value[TickGraph.VALUE_C] >= temp.value[TickGraph.VALUE_A] && temp.value[TickGraph.VALUE_A] >= lastGraph.value[TickGraph.VALUE_D] /*&& !(lastGraph.value[TickGraph.VALUE_F] != (long)TRADE_TYPE.TRADE_NONE && lastGraph.value[TickGraph.VALUE_H] != (long)TRADE_TYPE.TRADE_NONE)*/)
                        {
                            if (graph.value[TickGraph.VALUE_C] > lastGraph.value[TickGraph.VALUE_C]) lastGraph.value[TickGraph.VALUE_C] = graph.value[TickGraph.VALUE_C];
                            if (graph.value[TickGraph.VALUE_D] < lastGraph.value[TickGraph.VALUE_D]) lastGraph.value[TickGraph.VALUE_D] = graph.value[TickGraph.VALUE_D];
                            lastGraph.value[TickGraph.VALUE_B] = temp.value[TickGraph.VALUE_A];
                            lastGraph.value[TickGraph.VALUE_F] = graph.value[TickGraph.VALUE_F] != -1 ? graph.value[TickGraph.VALUE_F] : lastGraph.value[TickGraph.VALUE_F];
                            lastGraph.value[TickGraph.VALUE_G] = graph.value[TickGraph.VALUE_G] != -1 ? graph.value[TickGraph.VALUE_G] : lastGraph.value[TickGraph.VALUE_G];
                            lastGraph.value[TickGraph.VALUE_H] = graph.value[TickGraph.VALUE_H] != -1 ? graph.value[TickGraph.VALUE_H] : lastGraph.value[TickGraph.VALUE_H];
                            lastGraph.value[TickGraph.VALUE_I] = graph.value[TickGraph.VALUE_I] != -1 ? graph.value[TickGraph.VALUE_I] : lastGraph.value[TickGraph.VALUE_I];
                            lastGraph.value[TickGraph.VALUE_J] += graph.value[TickGraph.VALUE_J] != -1 ? graph.value[TickGraph.VALUE_J] : 0;

                            graph = lastGraph;


                            step = -1;
                        }
                        else
                        {
                            if (temp.value[TickGraph.VALUE_A] - graph.value[TickGraph.VALUE_D] > step || graph.value[TickGraph.VALUE_C] - temp.value[TickGraph.VALUE_A] > step)
                            {
                                graphBase.AddNewItem("TXF_AK", graph);

                                //temp.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                                //temp.value[TickGraph.VALUE_C] = tick.quanty;
                                //temp.value[TickGraph.VALUE_A] = temp.value[TickGraph.VALUE_B] / temp.value[TickGraph.VALUE_C];

                                graph = new TickGraph();
                                graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                                graph.value[TickGraph.VALUE_A] = temp.value[TickGraph.VALUE_A];
                                graph.value[TickGraph.VALUE_B] = temp.value[TickGraph.VALUE_A];
                                graph.value[TickGraph.VALUE_C] = temp.value[TickGraph.VALUE_A];
                                graph.value[TickGraph.VALUE_D] = temp.value[TickGraph.VALUE_A];
                                graph.value[TickGraph.VALUE_E] = handle.index;
                            }
                            else
                            {
                                graph.value[TickGraph.VALUE_B] = temp.value[TickGraph.VALUE_A];
                                if (temp.value[TickGraph.VALUE_A] > graph.value[TickGraph.VALUE_C]) graph.value[TickGraph.VALUE_C] = temp.value[TickGraph.VALUE_A];
                                if (temp.value[TickGraph.VALUE_A] < graph.value[TickGraph.VALUE_D]) graph.value[TickGraph.VALUE_D] = temp.value[TickGraph.VALUE_A];
                            }
                        }
                    }
                }
            } while (true);
        }
Пример #5
0
        public void CalTrade(String path, int range, int main, int favg, int savg, int maxloss, int maxgain)
        {
            int bound = 1;
            int pretype = (int)TRADE_TYPE.TRADE_NONE;
            long lastprice = -1;
            int type = (int)TRADE_TYPE.TRADE_NONE;
            int step = range;

            String slowAvg = String.Format("TXF_A{0}", savg);
            String fastAvg = String.Format("TXF_A{0}", favg);
            TickBase tickBase = new TickBase(path);

            TickBaseHandle handle = new TickBaseHandle();
            GraphBase graphBase = new GraphBase(System.DateTime.Now, 100);

            FutureTick tick;
            TickGraph lastGraph;
            TickGraph graph = new TickGraph();
            TickGraph slowAverage;
            TickGraph fastAverage;
            TickGraph lastAverage;
            TickGraph average = new TickGraph();
            TickGraph[] graph_a = new TickGraph[50];
            TickGraph[] average_a = new TickGraph[50];

            graphBase.CreateTable("TXF_K");
            graphBase.CreateTable("TXF_A");
            for (int i = 1; i <= 50; i++)
            {
                String table = String.Format("TXF_K{0}", i);
                graphBase.CreateTable(table);
                graph_a[i - 1] = new TickGraph();

                table = String.Format("TXF_A{0}", i);
                graphBase.CreateTable(table);
                average_a[i - 1] = new TickGraph();
            }

            do
            {
                tick = tickBase.GetFutureTick("TXF", ref handle);
                if (tick == null)
                {
                    break;
                }
                if (graph.type == TICK_GRAPH.TICK_GRAPH_NONE)
                {
                    graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                    graph.value[TickGraph.VALUE_A] = tick.price;
                    graph.value[TickGraph.VALUE_B] = tick.price;
                    graph.value[TickGraph.VALUE_C] = tick.price;
                    graph.value[TickGraph.VALUE_D] = tick.price;
                    graph.value[TickGraph.VALUE_E] = handle.index;

                    average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                    average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                    average.value[TickGraph.VALUE_C] = tick.quanty;
                }
                else
                {
                    lastGraph = null;
                    lastGraph = graphBase.GetLatestItem("TXF_K");
                    lastAverage = null;
                    lastAverage = graphBase.GetLatestItem("TXF_A");
                    slowAverage = null;
                    slowAverage = graphBase.GetLatestItem(slowAvg);
                    fastAverage = null;
                    fastAverage = graphBase.GetLatestItem(fastAvg);

                    if (step == -1)
                    {
                        if (tick.price <= graph.value[TickGraph.VALUE_D] || graph.value[TickGraph.VALUE_C] <= tick.price)
                        {
                            average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];

                            for (int i = 1; i <= 50; i++)
                            {
                                graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);
                                
                                average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                long m = graphBase.CalAverage("TXF_A", TickGraph.VALUE_C, i);
                                if (m != 0)
                                {
                                    average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_B, i) / m;
                                }
                                else
                                {
                                    average_a[i - 1].value[TickGraph.VALUE_A] = -1;
                                }
                            }

                            /********************/
                            if (average_a[main - 1].value[TickGraph.VALUE_A] != -1 && average_a[favg - 1].value[TickGraph.VALUE_A] != -1 && average_a[savg - 1].value[TickGraph.VALUE_A] != -1)
                            {
                                if (type == (int)TRADE_TYPE.TRADE_NONE)
                                {
                                    if (average_a[main - 1].value[TickGraph.VALUE_A] >= average_a[favg - 1].value[TickGraph.VALUE_A] && average_a[main - 1].value[TickGraph.VALUE_A] > average_a[savg - 1].value[TickGraph.VALUE_A])
                                    {
                                        if (graph.value[TickGraph.VALUE_F] == (long)TRADE_TYPE.TRADE_NONE)
                                        {
                                            performance += AddBuy(tick.price);
                                            lastprice = tick.price;
                                            graph.value[TickGraph.VALUE_F] = (long)TRADE_TYPE.TRADE_BUY_OPEN;
                                            graph.value[TickGraph.VALUE_G] = (long)tick.price;

                                            graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                            type = (int)TRADE_TYPE.TRADE_BUY_OPEN;
                                            Console.WriteLine("performance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                        }
                                    }
                                    else if (average_a[main - 1].value[TickGraph.VALUE_A] <= average_a[favg - 1].value[TickGraph.VALUE_A] && average_a[main - 1].value[TickGraph.VALUE_A] < average_a[savg - 1].value[TickGraph.VALUE_A])
                                    {
                                        if (graph.value[TickGraph.VALUE_F] == (long)TRADE_TYPE.TRADE_NONE)
                                        {
                                            performance += AddSell(tick.price);
                                            lastprice = tick.price;
                                            graph.value[TickGraph.VALUE_F] = (long)TRADE_TYPE.TRADE_SELL_OPEN;
                                            graph.value[TickGraph.VALUE_G] = (long)tick.price;

                                            graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                            type = (int)TRADE_TYPE.TRADE_SELL_OPEN;
                                            Console.WriteLine("performance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                        }
                                    }
                                }
                                else
                                {
                                    if (type == (int)TRADE_TYPE.TRADE_BUY_OPEN)
                                    {
                                        if (average_a[main - 1].value[TickGraph.VALUE_A] < average_a[favg - 1].value[TickGraph.VALUE_A])
                                        {

                                            if (pretype == (int)TRADE_TYPE.TRADE_NONE)
                                            {
                                                performance += AddSell(tick.price);
                                                lastprice = tick.price;
                                                graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_SELL_OPEN;
                                                graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                                /*if (tick.price - lastprice < 0) bound--;
                                                else bound++;
                                                if (bound <= 0) bound = 1;
                                                if (bound > savg) bound = savg;*/

                                                graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                                Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                            }
                                            type = (int)TRADE_TYPE.TRADE_NONE;
                                            pretype = (int)TRADE_TYPE.TRADE_NONE;
                                        }

                                    }
                                    else if (type == (int)TRADE_TYPE.TRADE_SELL_OPEN)
                                    {
                                        if (average_a[main - 1].value[TickGraph.VALUE_A] > average_a[favg - 1].value[TickGraph.VALUE_A])
                                        {

                                            if (pretype == (int)TRADE_TYPE.TRADE_NONE)
                                            {
                                                performance += AddBuy(tick.price);
                                                lastprice = tick.price;
                                                graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_BUY_OPEN;
                                                graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                                /*if (lastprice - tick.price < 0) bound--;
                                                else bound++;
                                                if (bound <= 0) bound = 1;
                                                if (bound > savg) bound = savg;*/

                                                graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                                Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Sell", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                            }
                                            type = (int)TRADE_TYPE.TRADE_NONE;
                                            pretype = (int)TRADE_TYPE.TRADE_NONE;
                                        }
                                    }
                                }
                            }
                            /********************/


                            graphBase.UpdateLatestItem("TXF_A", average);
                            graphBase.UpdateLatestItem("TXF_K", graph);

                            for (int i = 1; i <= 50; i++)
                            {
                                String table = String.Format("TXF_K{0}", i);
                                graphBase.UpdateLatestItem(table, graph_a[i - 1]);
                                table = String.Format("TXF_A{0}", i);
                                graphBase.UpdateLatestItem(table, average_a[i - 1]);
                            }

                            graph = new TickGraph();
                            graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                            graph.value[TickGraph.VALUE_A] = tick.price;
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            graph.value[TickGraph.VALUE_C] = tick.price;
                            graph.value[TickGraph.VALUE_D] = tick.price;
                            graph.value[TickGraph.VALUE_E] = handle.index;

                            average = new TickGraph();
                            average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                            average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] = tick.quanty;

                            step = range;
                        }
                        else
                        {
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            average.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] += tick.quanty;


                            average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];

                            for (int i = 1; i <= 50; i++)
                            {
                                graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);

                                average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                long m = graphBase.CalAverage("TXF_A", TickGraph.VALUE_C, i);
                                if (m != 0)
                                {
                                    average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_B, i) / m;
                                }
                                else
                                {
                                    average_a[i - 1].value[TickGraph.VALUE_A] = -1;
                                }
                            }

                            /**********************/
#if true
                            if (average_a[main - 1].value[TickGraph.VALUE_A] != -1 && average_a[favg - 1].value[TickGraph.VALUE_A] != -1 && average_a[savg - 1].value[TickGraph.VALUE_A] != -1)
                            {
                                if (type != (int)TRADE_TYPE.TRADE_NONE && pretype != (int)TRADE_TYPE.TRADE_PRE)
                                {
                                    if (type == (int)TRADE_TYPE.TRADE_BUY_OPEN)
                                    {
                                        if (average_a[main - 1].value[TickGraph.VALUE_A] < average_a[favg - 1].value[TickGraph.VALUE_A])
                                        /*if (tick.price < average_a[bound - 1].value[TickGraph.VALUE_A]
                                            || tick.price - lastprice <= maxloss
                                            || tick.price - lastprice >= maxgain)*/
                                        //if (lastAverage.value[TickGraph.VALUE_A] >= average.value[TickGraph.VALUE_A])
                                        {
                                            performance += AddSell(tick.price);
                                            graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_SELL_OPEN;
                                            graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                            if (tick.price - lastprice < 0) bound--;
                                            else bound++;
                                            if (bound <= 0) bound = 1;
                                            if (bound > savg) bound = savg;

                                            graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                            pretype = (int)TRADE_TYPE.TRADE_PRE;
                                            Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                        }

                                    }
                                    else if (type == (int)TRADE_TYPE.TRADE_SELL_OPEN)
                                    {
                                        if (average_a[main - 1].value[TickGraph.VALUE_A] > average_a[favg - 1].value[TickGraph.VALUE_A])
                                        /*if (tick.price > average_a[bound - 1].value[TickGraph.VALUE_A]
                                            || lastprice - tick.price <= maxloss
                                            || lastprice - tick.price >= maxgain)*/
                                        //if (lastAverage.value[TickGraph.VALUE_A] <= average.value[TickGraph.VALUE_A])
                                        {
                                            performance += AddBuy(tick.price);
                                            graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_BUY_OPEN;
                                            graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                            if (lastprice - tick.price < 0) bound--;
                                            else bound++;
                                            if (bound <= 0) bound = 1;
                                            if (bound > savg) bound = savg;

                                            graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                            pretype = (int)TRADE_TYPE.TRADE_PRE;
                                            Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Sell", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                        }
                                    }
                                }
                            }
#endif
                            /********************/
                        }

                    }
                    else
                    {
                        if (lastGraph != null && lastGraph.value[TickGraph.VALUE_C] >= tick.price && tick.price >= lastGraph.value[TickGraph.VALUE_D] /*&& !(lastGraph.value[TickGraph.VALUE_F] != (long)TRADE_TYPE.TRADE_NONE && lastGraph.value[TickGraph.VALUE_H] != (long)TRADE_TYPE.TRADE_NONE)*/)
                        {
                            if (graph.value[TickGraph.VALUE_C] > lastGraph.value[TickGraph.VALUE_C]) lastGraph.value[TickGraph.VALUE_C] = graph.value[TickGraph.VALUE_C];
                            if (graph.value[TickGraph.VALUE_D] < lastGraph.value[TickGraph.VALUE_D]) lastGraph.value[TickGraph.VALUE_D] = graph.value[TickGraph.VALUE_D];
                            lastGraph.value[TickGraph.VALUE_B] = tick.price;
                            lastGraph.value[TickGraph.VALUE_F] = graph.value[TickGraph.VALUE_F] != -1 ? graph.value[TickGraph.VALUE_F] : lastGraph.value[TickGraph.VALUE_F];
                            lastGraph.value[TickGraph.VALUE_G] = graph.value[TickGraph.VALUE_G] != -1 ? graph.value[TickGraph.VALUE_G] : lastGraph.value[TickGraph.VALUE_G];
                            lastGraph.value[TickGraph.VALUE_H] = graph.value[TickGraph.VALUE_H] != -1 ? graph.value[TickGraph.VALUE_H] : lastGraph.value[TickGraph.VALUE_H];
                            lastGraph.value[TickGraph.VALUE_I] = graph.value[TickGraph.VALUE_I] != -1 ? graph.value[TickGraph.VALUE_I] : lastGraph.value[TickGraph.VALUE_I];
                            lastGraph.value[TickGraph.VALUE_J] += graph.value[TickGraph.VALUE_J] != -1 ? graph.value[TickGraph.VALUE_J] : 0;

                            graph = lastGraph;


                            lastAverage = graphBase.GetLatestItem("TXF_A");
                            lastAverage.value[TickGraph.VALUE_B] += average.value[TickGraph.VALUE_B];
                            lastAverage.value[TickGraph.VALUE_C] += average.value[TickGraph.VALUE_C];
                            lastAverage.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                            lastAverage.value[TickGraph.VALUE_C] += tick.quanty;
                            average = lastAverage;

                            step = -1;
                        }
                        else
                        {
                            if (tick.price - graph.value[TickGraph.VALUE_D] > step || graph.value[TickGraph.VALUE_C] - tick.price > step)
                            {

                                average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];

                                for (int i = 1; i <= 50; i++)
                                {
                                    graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                    graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);

                                    average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                    long m = graphBase.CalAverage("TXF_A", TickGraph.VALUE_C, i);
                                    if (m != 0)
                                    {
                                        average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_B, i) / m;
                                    }
                                    else
                                    {
                                        average_a[i - 1].value[TickGraph.VALUE_A] = -1;
                                    }
                                }

                                graphBase.AddNewItem("TXF_A", average);
                                graphBase.AddNewItem("TXF_K", graph);
                                graph = new TickGraph();
                                /********************/
                                if (average_a[main - 1].value[TickGraph.VALUE_A] != -1 && average_a[favg - 1].value[TickGraph.VALUE_A] != -1 && average_a[savg - 1].value[TickGraph.VALUE_A] != -1)
                                {
                                    if (type == (int)TRADE_TYPE.TRADE_NONE)
                                    {
                                        if (average_a[main - 1].value[TickGraph.VALUE_A] >= average_a[favg - 1].value[TickGraph.VALUE_A] && average_a[main - 1].value[TickGraph.VALUE_A] > average_a[savg - 1].value[TickGraph.VALUE_A])
                                        {
                                            if (graph.value[TickGraph.VALUE_F] == (long)TRADE_TYPE.TRADE_NONE)
                                            {
                                                performance += AddBuy(tick.price);
                                                lastprice = tick.price;
                                                graph.value[TickGraph.VALUE_F] = (long)TRADE_TYPE.TRADE_BUY_OPEN;
                                                graph.value[TickGraph.VALUE_G] = (long)tick.price;

                                                graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                                type = (int)TRADE_TYPE.TRADE_BUY_OPEN;
                                                Console.WriteLine("performance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                            }
                                        }
                                        else if (average_a[main - 1].value[TickGraph.VALUE_A] <= average_a[favg - 1].value[TickGraph.VALUE_A] && average_a[main - 1].value[TickGraph.VALUE_A] < average_a[savg - 1].value[TickGraph.VALUE_A])
                                        {
                                            if (graph.value[TickGraph.VALUE_F] == (long)TRADE_TYPE.TRADE_NONE)
                                            {
                                                performance += AddSell(tick.price);
                                                lastprice = tick.price;
                                                graph.value[TickGraph.VALUE_F] = (long)TRADE_TYPE.TRADE_SELL_OPEN;
                                                graph.value[TickGraph.VALUE_G] = (long)tick.price;

                                                graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                                type = (int)TRADE_TYPE.TRADE_SELL_OPEN;
                                                Console.WriteLine("performance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (type == (int)TRADE_TYPE.TRADE_BUY_OPEN)
                                        {
                                            if (average_a[main - 1].value[TickGraph.VALUE_A] < average_a[favg - 1].value[TickGraph.VALUE_A])
                                            {

                                                if (pretype == (int)TRADE_TYPE.TRADE_NONE)
                                                {
                                                    performance += AddSell(tick.price);
                                                    lastprice = tick.price;
                                                    graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_SELL_OPEN;
                                                    graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                                    /*if (tick.price - lastprice < 0) bound--;
                                                    else bound++;
                                                    if (bound <= 0) bound = 1;
                                                    if (bound > savg) bound = savg;*/

                                                    graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                                    Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                                }
                                                type = (int)TRADE_TYPE.TRADE_NONE;
                                                pretype = (int)TRADE_TYPE.TRADE_NONE;
                                            }

                                        }
                                        else if (type == (int)TRADE_TYPE.TRADE_SELL_OPEN)
                                        {
                                            if (average_a[main - 1].value[TickGraph.VALUE_A] > average_a[favg - 1].value[TickGraph.VALUE_A])
                                            {

                                                if (pretype == (int)TRADE_TYPE.TRADE_NONE)
                                                {
                                                    performance += AddBuy(tick.price);
                                                    lastprice = tick.price;
                                                    graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_BUY_OPEN;
                                                    graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                                    /*if (lastprice - tick.price < 0) bound--;
                                                    else bound++;
                                                    if (bound <= 0) bound = 1;
                                                    if (bound > savg) bound = savg;*/

                                                    graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                                    Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Sell", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                                }
                                                type = (int)TRADE_TYPE.TRADE_NONE;
                                                pretype = (int)TRADE_TYPE.TRADE_NONE;
                                            }
                                        }
                                    }
                                }
                                /********************/

                                graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                                graph.value[TickGraph.VALUE_A] = tick.price;
                                graph.value[TickGraph.VALUE_B] = tick.price;
                                graph.value[TickGraph.VALUE_C] = tick.price;
                                graph.value[TickGraph.VALUE_D] = tick.price;
                                graph.value[TickGraph.VALUE_E] = handle.index;

                                average = new TickGraph();
                                average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                                average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                                average.value[TickGraph.VALUE_C] = tick.quanty;

                                for (int i = 1; i <= 50; i++)
                                {
                                    String table = String.Format("TXF_K{0}", i);
                                    graphBase.AddNewItem(table, graph_a[i - 1]);
                                    table = String.Format("TXF_A{0}", i);
                                    graphBase.AddNewItem(table, average_a[i - 1]);
                                }
                            }
                            else
                            {
                                graph.value[TickGraph.VALUE_B] = tick.price;
                                if (tick.price > graph.value[TickGraph.VALUE_C]) graph.value[TickGraph.VALUE_C] = tick.price;
                                if (tick.price < graph.value[TickGraph.VALUE_D]) graph.value[TickGraph.VALUE_D] = tick.price;

                                average.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                                average.value[TickGraph.VALUE_C] += tick.quanty;

                                average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];

                                for (int i = 1; i <= 50; i++)
                                {
                                    graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                    graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);

                                    average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                    long m = graphBase.CalAverage("TXF_A", TickGraph.VALUE_C, i);
                                    if (m != 0)
                                    {
                                        average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_B, i) / m;
                                    }
                                    else
                                    {
                                        average_a[i - 1].value[TickGraph.VALUE_A] = -1;
                                    }
                                }

                                /**********************/
#if true
                                if (average_a[main - 1].value[TickGraph.VALUE_A] != -1 && average_a[favg - 1].value[TickGraph.VALUE_A] != -1 && average_a[savg - 1].value[TickGraph.VALUE_A] != -1)
                                {
                                    if (type != (int)TRADE_TYPE.TRADE_NONE && pretype != (int)TRADE_TYPE.TRADE_PRE)
                                    {
                                        if (type == (int)TRADE_TYPE.TRADE_BUY_OPEN)
                                        {
                                            if (average_a[main - 1].value[TickGraph.VALUE_A] < average_a[favg - 1].value[TickGraph.VALUE_A])
                                            /*if (tick.price < average_a[bound - 1].value[TickGraph.VALUE_A]
                                                || tick.price - lastprice <= maxloss
                                                || tick.price - lastprice >= maxgain)*/
                                            //if (lastAverage.value[TickGraph.VALUE_A] >= average.value[TickGraph.VALUE_A])
                                            {
                                                performance += AddSell(tick.price);
                                                graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_SELL_OPEN;
                                                graph.value[TickGraph.VALUE_I] = (long)tick.price;
                                                
                                                if (tick.price - lastprice < 0) bound--;
                                                else bound++;
                                                if (bound <= 0) bound = 1;
                                                if (bound > savg) bound = savg;

                                                graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                                pretype = (int)TRADE_TYPE.TRADE_PRE;
                                                Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Buy", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                            }

                                        }
                                        else if (type == (int)TRADE_TYPE.TRADE_SELL_OPEN)
                                        {
                                            if (average_a[main - 1].value[TickGraph.VALUE_A] > average_a[favg - 1].value[TickGraph.VALUE_A])
                                            /*if (tick.price > average_a[bound - 1].value[TickGraph.VALUE_A]
                                                || lastprice - tick.price <= maxloss
                                                || lastprice - tick.price >= maxgain)*/
                                            //if (lastAverage.value[TickGraph.VALUE_A] <= average.value[TickGraph.VALUE_A])
                                            {
                                                performance += AddBuy(tick.price);
                                                graph.value[TickGraph.VALUE_H] = (long)TRADE_TYPE.TRADE_BUY_OPEN;
                                                graph.value[TickGraph.VALUE_I] = (long)tick.price;

                                                if (lastprice - tick.price < 0) bound--;
                                                else bound++;
                                                if (bound <= 0) bound = 1;
                                                if (bound > savg) bound = savg;

                                                graph.value[TickGraph.VALUE_J] = (long)new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber();
                                                pretype = (int)TRADE_TYPE.TRADE_PRE;
                                                Console.WriteLine("\tperformance = {0}, price = {1}, line = {2} - Sell", performance, tick.price, graph.value[TickGraph.VALUE_J]);
                                            }
                                        }
                                    }
                                }
#endif
                                /********************/
                            }
                        }
                    }
                }
            } while (true);
        }
Пример #6
0
        public void CalNormal(String path, int range)
        {
            TickBase tickBase = new TickBase(path);
            TickBaseHandle handle = new TickBaseHandle();
            GraphBase graphBase = new GraphBase(System.DateTime.Now, 100);
            int step = range;
            FutureTick tick;
            TickGraph graph = new TickGraph();
            TickGraph average = new TickGraph();
            TickGraph[] graph_a = new TickGraph[50];
            TickGraph[] average_a = new TickGraph[50];

            graphBase.CreateTable("TXF_K");
            graphBase.CreateTable("TXF_A");
            for (int i = 1; i <= 50; i++)
            {
                String table = String.Format("TXF_K{0}", i);
                graphBase.CreateTable(table);
                graph_a[i - 1] = new TickGraph();

                table = String.Format("TXF_A{0}", i);
                graphBase.CreateTable(table);
                average_a[i - 1] = new TickGraph();
            }

            do
            {
                tick = tickBase.GetFutureTick("TXF", ref handle);
                if (tick == null)
                {
                    break;
                }
                if (graph.type == TICK_GRAPH.TICK_GRAPH_NONE)
                {
                    graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                    graph.value[TickGraph.VALUE_A] = tick.price;
                    graph.value[TickGraph.VALUE_B] = tick.price;
                    graph.value[TickGraph.VALUE_C] = tick.price;
                    graph.value[TickGraph.VALUE_D] = tick.price;
                    graph.value[TickGraph.VALUE_E] = handle.index;

                    average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                    average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                    average.value[TickGraph.VALUE_C] = tick.quanty;
                }
                else
                {
                    if (step == -1)
                    {
                        if (tick.price < graph.value[TickGraph.VALUE_D] || graph.value[TickGraph.VALUE_C] < tick.price)
                        {

                            average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];
                            graphBase.AddNewItem("TXF_A", average);

                            graphBase.AddNewItem("TXF_K", graph);

                            graph = new TickGraph();
                            graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                            graph.value[TickGraph.VALUE_A] = tick.price;
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            graph.value[TickGraph.VALUE_C] = tick.price;
                            graph.value[TickGraph.VALUE_D] = tick.price;
                            graph.value[TickGraph.VALUE_E] = handle.index;

                            average = new TickGraph();
                            average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                            average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] = tick.quanty;

                            for (int i = 1; i <= 50; i++)
                            {
                                graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);
                                String table = String.Format("TXF_K{0}", i);
                                graphBase.AddNewItem(table, graph_a[i - 1]);

                                average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_A, i);
                                table = String.Format("TXF_A{0}", i);
                                graphBase.AddNewItem(table, average_a[i - 1]);

                            }

                            step = range;
                        }
                        else
                        {
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            average.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] += tick.quanty;
                        }

                    }
                    else
                    {
                        if (tick.price - graph.value[TickGraph.VALUE_D] > step || graph.value[TickGraph.VALUE_C] - tick.price > step)
                        {

                            average.value[TickGraph.VALUE_A] = average.value[TickGraph.VALUE_B] / average.value[TickGraph.VALUE_C];
                            graphBase.AddNewItem("TXF_A", average);

                            graphBase.AddNewItem("TXF_K", graph);

                            graph = new TickGraph();
                            graph.type = TICK_GRAPH.TICK_GRAPH_KBAR;
                            graph.value[TickGraph.VALUE_A] = tick.price;
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            graph.value[TickGraph.VALUE_C] = tick.price;
                            graph.value[TickGraph.VALUE_D] = tick.price;
                            graph.value[TickGraph.VALUE_E] = handle.index;

                            average = new TickGraph();
                            average.type = TICK_GRAPH.TICK_GRAPH_LINE;
                            average.value[TickGraph.VALUE_B] = tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] = tick.quanty;

                            for (int i = 1; i <= 50; i++)
                            {
                                graph_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                graph_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_K", TickGraph.VALUE_C, i);
                                String table = String.Format("TXF_K{0}", i);
                                graphBase.AddNewItem(table, graph_a[i - 1]);

                                average_a[i - 1].type = TICK_GRAPH.TICK_GRAPH_LINE;
                                average_a[i - 1].value[TickGraph.VALUE_A] = graphBase.CalAverage("TXF_A", TickGraph.VALUE_A, i);
                                table = String.Format("TXF_A{0}", i);
                                graphBase.AddNewItem(table, average_a[i - 1]);

                            }
                        }
                        else
                        {
                            graph.value[TickGraph.VALUE_B] = tick.price;
                            if (tick.price > graph.value[TickGraph.VALUE_C]) graph.value[TickGraph.VALUE_C] = tick.price;
                            if (tick.price < graph.value[TickGraph.VALUE_D]) graph.value[TickGraph.VALUE_D] = tick.price;

                            average.value[TickGraph.VALUE_B] += tick.price * tick.quanty;
                            average.value[TickGraph.VALUE_C] += tick.quanty;
                        }
                    }
                }
            } while (true);
        }
Пример #7
0
        public FutureTick GetFutureTick(String tablename, ref TickBaseHandle handle)
        {
            FutureTick tick = new FutureTick();
            SQLiteKit kit;
            SQLiteDataReader reader;

            do {
                if (handle.index < mFiles.Count)
                {
                    kit = mFiles[handle.index];

                    if (handle.initial == 0)
                    {
                        String cmd = "SELECT STRIKE_MONTH FROM " + tablename + " WHERE SN=1;";
                        kit.Cmd(cmd);
                        reader = kit.GetReader();
                        if (reader != null)
                        {
                            handle.month = (int)reader.GetInt32(0);
                            reader.Close();
                        }

                        cmd = "SELECT * FROM " + tablename + " WHERE STRIKE_MONTH=" + System.Convert.ToString(handle.month) + " ORDER BY SN;";
                        kit.Cmd(cmd);
                        handle.initial = 1;
                    }

                    reader = kit.GetReader();

                    if (reader != null && handle.last != 1)
                    {
                        tick.type = (int)reader.GetInt32(3);
                        tick.time = (int)reader.GetInt32(6);

                        tick.second = tick.time % 100;
                        tick.minute = (tick.time % 10000) / 100;
                        tick.hour = tick.time / 10000;

                        tick.seqsec = tick.hour * 3600 + tick.minute * 60 + tick.second;

                        tick.buy = (int)reader.GetInt32(7) / 100;
                        tick.sell = (int)reader.GetInt32(8) / 100;
                        tick.price = (int)reader.GetInt32(9) / 100;
                        tick.quanty = (int)reader.GetInt32(10);
                        if (tick.seqsec > 49490)
                        {
                            handle.last = 1;
                        }
                        return tick;
                    }
                    else
                    {
                        handle.last = 0;
                        handle.index++;
                        handle.initial = 0;
                    }
                } else return null;
            } while (true);
        }