public BuyLowStrategy(int PreviousDaysN, int RunsPerDay, string symbol) { this.previousDaysN = PreviousDaysN; this.runsPerDay = RunsPerDay; // Initializing the fields isDownReady = true; isUpReady = true; isReady = true; turnAround = false; orderSignal = 0; firstDay = true; // Initializing the previous days runs and the thresholds dailyDownwardRuns = WarmUp(symbol, FieldName.downwardRuns); dailyUpwardRuns = WarmUp(symbol, FieldName.upwardRuns); downwardRunsThreshold = dailyDownwardRuns.Average(); upwardRunsThreshold = dailyUpwardRuns.Average(); }
private myCoord getCorner() { const float eps = 0.00006f; //epsilon value, dictates precision for the variance myCoord sample = new myCoord(); //sample data we get after each time span Queue<float> xQueue = new Queue<float>(10); //queues for the x, y, z values Queue<float> yQueue = new Queue<float>(10); //we get data every 0.2 seconds, and stop when we detect that the Queue<float> zQueue = new Queue<float>(10); //hand has stayed still for 2 seconds, hence analyse the last 10 values System.DateTime t1 = System.DateTime.Now; //current time System.TimeSpan span = new System.TimeSpan(0, 0, 0, 0, 200); //time span of 0.2 seconds between each sampling of the position System.DateTime t3 = new System.DateTime(); //time at which we have to get the new sample //fill the queues with the initial 10 samples while (xQueue.Count < 10) { t3 = t1.Add(span); //when we get the next round of data xQueue.Enqueue(xCoord); yQueue.Enqueue(yCoord); zQueue.Enqueue(zCoord); //get current round of data //wait until next round while (t1 < t3) { t1 = System.DateTime.Now; } } //compute the initial variances of position data float xVar = Variance(xQueue); float yVar = Variance(yQueue); float zVar = Variance(zQueue); //while the variances are to high, meaning the hand isn't still, keep tracking the hand while ((xVar > eps | yVar > eps | zVar > eps) || (xQueue.Average() == 0 && yQueue.Average() == 0 && zQueue.Average() == 0)) { t3 = t1.Add(span); //when we get next round of data xQueue.Dequeue(); yQueue.Dequeue(); zQueue.Dequeue(); //discard old data xQueue.Enqueue(xCoord); yQueue.Enqueue(yCoord); zQueue.Enqueue(zCoord); //get current round xVar = Variance(xQueue); yVar = Variance(yQueue); zVar = Variance(zQueue); //compute new variance //wait until next round while (t1 < t3) { t1 = System.DateTime.Now; } } //when the hand hasn't moved return it's position, averaging over the last 10 positions sample.X = xQueue.Average(); sample.Y = yQueue.Average(); sample.Z = zQueue.Average(); Console.Beep(); //give an audio confirmation to the user return sample; }