public override void getInfo(RowData r) { if (r.isTrade == 1) { AddToArr(r); Algo(r); } }
public RowData(RowData r) { this.datetime = r.datetime; this.ask1 = r.ask1; this.bid1 = r.bid1; this.askV = r.askV; this.bidV = r.bidV; this.dir = r.dir; this.isTrade = r.isTrade; }
/*public RowData() { this.datetime =new DateTime (); this.ask1 = 0; this.bid1 = 0; this.askV = 0; this.bidV = 0; this.dir = 0; this.isTrade = 0; } */ public void ToChange(RowData other) { this.datetime = other.datetime; this.datetime = other.datetime; this.ask1 = other.ask1; this.bid1 = other.bid1; this.askV = other.askV; this.bidV = other.bidV; this.dir = other.dir; this.isTrade = other.isTrade; }
public void Algo(RowData r) { if (deals[deals.Length - 1].ask1 != 0) { double max = deals[1].ask1; double min = deals[1].ask1; for (int i = 1; i < deals.Length; i++) { if (max == deals[i - 1].ask1) { if (deals[i].ask1 > max) { max = deals[i].ask1; } else { max = 0; this.counterMax++; } } if (deals[i - 1].ask1 == min) { if (deals[i].ask1 < min) { min = deals[i].ask1; } else { min = 0; this.counterMin++; } } } if (max != 0 && getPVol() != 1 && this.counterMax <= this.paramArr[1]) { this.buy(r, 1); } if (min != 0 && getPVol() != -1 && this.counterMin <= this.paramArr[1]) { this.sell(r, 1); } } }
private void AddToArr(RowData r) { int i; for (i = 0; i < deals.Length; i++) { if (deals[i].ask1 == 0) { deals[i] = r; return; } } deals[0] = default(RowData); for (i = 1; i < deals.Length; i++) { deals[i - 1] = deals[i]; deals[0] = default(RowData); } deals[i - 1] = r; }
public abstract void getInfo(RowData r); // gets RowData from main (in each strategy works as it wants) public virtual void mustClosePos(RowData r) { if (this.logInfo[this.logInfo.Count() - 1].getFirst().dir == 1) sell(r, 1); if (this.logInfo[this.logInfo.Count() - 1].getFirst().dir == -1) buy(r, 1); } // closes last position if open at end
} // checks if can proceed after config buy/sell - won't proceed if tries to do same thing again public abstract void getInfo(RowData r); // gets RowData from main (in each strategy works as it wants)
} //makes sell public bool canProceed(RowData r) { if (logInfo.Count() > 0 && !logInfo[logInfo.Count() - 1].getPosEnd()) { if (this.logInfo[this.logInfo.Count() - 1].getDir() == r.dir) { ProgramMain.creatErrorInfoLogTxt(this.name + " : tried to do same action twice"); return false; } } return true; } // checks if can proceed after config buy/sell - won't proceed if tries to do same thing again
} //makes buy public bool sell(RowData r , int vol) { r.dir = -1; if (canProceed(r)) { this.sum += r.bid1; this.pvol -= vol; insertPosLogInfo(r); return true; } return false; } //makes sell
} // decides values for config after buy/sell public bool buy(RowData r , int vol) { r.dir = 1; if (canProceed(r)) { this.sum -= r.ask1; this.pvol += vol; insertPosLogInfo(r); return true; } return false; } //makes buy
} // edits info for final log public void insertPosLogInfo(RowData r) { if(logInfo.Count() > 0 && !logInfo[logInfo.Count() - 1].getPosEnd()) { double posSum = 0; if (logInfo[logInfo.Count() - 1].getDir() == 1) posSum -= logInfo[logInfo.Count() - 1].getFirst().ask1; if (logInfo[logInfo.Count() - 1].getDir() == -1) posSum += logInfo[logInfo.Count() - 1].getFirst().bid1; if (r.dir == 1) posSum -= r.ask1; if (r.dir == -1) posSum += r.bid1; logInfo[logInfo.Count() - 1].setEndRowData(r); logInfo[logInfo.Count() - 1].setPosEndBool(true); logInfo[logInfo.Count() - 1].setProfit(posSum); logInfo[logInfo.Count() - 1].setTotalSum(this.sum); } else { logInfo.Add(new saveData (r)); } } // decides values for config after buy/sell
} // clear queue for manager public static void setQueue(RowData r) { if (ProgramMain.rowDataToSave.Count < number) { ProgramMain.rowDataToSave.Enqueue(new RowData(r)); } else { ProgramMain.rowDataToSave.Enqueue(new RowData(r)); row.ToChange((ProgramMain.rowDataToSave.Dequeue())); } ProgramMain.toGetPointer = ProgramMain.rowDataToSave.ToArray(); } // set queue according to paramaters
public static double helpMaxsum(Stack<RowData> back, RowData r)//send back reverse { RowData prev = null; if (back.Count != 0) { foreach (RowData rev in back) { if (r.dir == 1)//buy { if (rev.ask1 > r.ask1) { if (prev == null) return rev.ask1; return prev.ask1; } prev = rev; } else { if (rev.bid1 > r.bid1) { if (prev == null) return rev.bid1; return prev.bid1; } prev = rev; } } } else { if (r.dir == 1) return r.ask1; return r.bid1; } return 0; }
} // constractor public void setEndRowData(RowData r) { this.rEnd = new RowData(r); posEnd = true; } // set RowData at exit
public saveData(RowData r) { this.rFirst = new RowData(r); this.posEnd = false; this.dirAtEnter = r.dir; } // constractor
/* public override void getInfo(RowData r) { Random random = new Random(); int x = random.Next(Convert.ToInt32(paramArr[0]), 30); if (x == 21 || x == 14 || x == 9) { if (this.getPVol() == 1) { this.sell(r, 1); } else { this.buy(r, 1); } } } */ // random method public override void getInfo(RowData r) { if (this.getList().Count() != 0) { if (this.getList()[this.getList().Count() - 1].getPosEnd()) { if (r.ask1 < prevRowData.ask1) { buy(r, 1); this.rAtEnter = this.getList()[this.getList().Count() - 1].getFirst(); } if (r.bid1 > prevRowData.bid1) { sell(r, 1); this.rAtEnter = this.getList()[this.getList().Count() - 1].getFirst(); } } else { if (this.rAtEnter.dir == 1) { if (r.bid1 / this.rAtEnter.bid1 > this.paramArr[1]) { sell(r, 1); } if (this.rAtEnter.bid1 / r.bid1 > this.paramArr[0]) { sell(r, 1); } } if (this.rAtEnter.dir == -1) { if (this.rAtEnter.ask1 / r.ask1 > this.paramArr[1]) { buy(r, 1); } if (r.ask1 / this.rAtEnter.ask1 > this.paramArr[0]) { buy(r, 1); } } } } if (this.getList().Count == 0) { if (r.ask1 < prevRowData.ask1) { buy(r, 1); this.rAtEnter = this.getList()[this.getList().Count() - 1].getFirst(); } if (r.bid1 > prevRowData.bid1) { sell(r, 1); this.rAtEnter = this.getList()[this.getList().Count() - 1].getFirst(); } } }