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); }
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); }