public static void refreshMiddle(WavePoint rhs) { foreach(var lhs in get().nodes) { if(lhs != rhs) { if(lhs.prev == rhs.prev && lhs.next == rhs.next) { WavePoint start = lhs.prev; WavePoint end = lhs.next; start.next = lhs; lhs.next = rhs; rhs.prev = lhs; end.prev = rhs; return; } } } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> public override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); if (currentBar < 2) { return; } ZigZag zigzag = (ZigZag)_dependents[0]; int cutoffBar = Math.Max(0, currentBar - _maxCycleLookback); int searchBar = currentBar - 1; List <WavePoint> points = new List <WavePoint>(); List <double> currentSeries = null; int pointBeingSearchFor = 0; // Point 0 being the last point most recent in time. double trendDirection = 0.0; // Start searching for the point that either made a high-high or low-low cycle. for (int i = searchBar; i >= cutoffBar; i--) { if (pointBeingSearchFor == 0) { if (zigzag.ZigZagLows[i] > 0.0) { trendDirection = Order.OrderType.Long; points.Add(new WavePoint() { Bar = i, Price = zigzag.Value[i] }); currentSeries = zigzag.ZigZagHighs; ++pointBeingSearchFor; } else if (zigzag.ZigZagHighs[i] > 0.0) { trendDirection = Order.OrderType.Short; points.Add(new WavePoint() { Bar = i, Price = zigzag.Value[i] }); currentSeries = zigzag.ZigZagLows; ++pointBeingSearchFor; } } // Each time we find a zigzag point, save the price and move to the next one for searching. else if (currentSeries != null && currentSeries[i] > 0.0) { // Calculate the retracement in percentage from the previous point. WavePoint previousPoint = points[points.Count - 1]; double retracement = UtilityMethods.PercentChange(zigzag.Value[i], previousPoint.Price); previousPoint.Retracement = retracement; points.Add(new WavePoint() { Bar = i, Price = zigzag.Value[i], Retracement = 0.0 }); currentSeries = currentSeries == zigzag.ZigZagHighs ? zigzag.ZigZagLows : zigzag.ZigZagHighs; ++pointBeingSearchFor; } } // Did we get all the points needed to wave information about the waves. if (pointBeingSearchFor >= MinRequiredPoints) { Waves[currentBar] = new WaveData() { Points = points, TrendDirection = trendDirection }; } else { Waves[currentBar] = null; } }
void Refresh() { if (next == gameObject) { Debug.Log("Error"); next = null; } if (prev == gameObject) { Debug.Log("Error2"); prev = null; } switch (type()) { case Node.Type.Start: RefreshStart(); break; case Node.Type.Middle: RefreshMiddle(); break; case Node.Type.End: RefreshEnd(); break; case Node.Type.Lost: RefreshLost(); break; } }
public static void setStart(WavePoint node) { get().start = node; }
public static void setEnd(WavePoint node) { get().end = node; }
public static void addNode(WavePoint node) { if (!get().nodes.Contains(node)) { get().nodes.Add(node); } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> public override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); if (currentBar > 1) { ZigZag zigzag = (ZigZag)_dependents[0]; int cutoffBar = Math.Max(0, currentBar - _maxBarsForWave); int searchBar = currentBar - 2; WavePoint[] points = new WavePoint[6]; WavePointWithLabel[] labels = new WavePointWithLabel[6]; List <double> currentSeries = null; int waveEndpointBeingSearchFor = 4; double trendDirection = 0.0; double fifthWaveDirection = 0.0; // 1 is bull, -1 bear, 0 not in a 5th wave // We have an endpoint on the 4th wave, so lets check and see if we // have all the previous waves by searching for the endpoints. for (int i = searchBar; i >= cutoffBar && waveEndpointBeingSearchFor >= 0; i--) { // See if we've just recently had the end of the 4th wave. For bull // waves this will start with a low and for bear will start with a high. // Need to check the past 3rd bar since that is the lag of the zigzag indicator. // For every zig there is a zag meaning if we found a low, the previous point will // be a high. This makes it easier to search back for the patterns. if (waveEndpointBeingSearchFor == 4) { if (zigzag.ZigZagLows[i] > 0.0) { trendDirection = Order.OrderType.Long; points[waveEndpointBeingSearchFor] = new WavePoint() { Bar = i, Price = zigzag.Value[i] }; labels[waveEndpointBeingSearchFor] = new WavePointWithLabel() { Bar = i, Price = zigzag.Value[i], Label = waveEndpointBeingSearchFor.ToString() }; currentSeries = zigzag.ZigZagHighs; --waveEndpointBeingSearchFor; } else if (zigzag.ZigZagHighs[i] > 0.0) { trendDirection = Order.OrderType.Short; points[waveEndpointBeingSearchFor] = new WavePoint() { Bar = i, Price = zigzag.Value[i] }; labels[waveEndpointBeingSearchFor] = new WavePointWithLabel() { Bar = i, Price = zigzag.Value[i], Label = waveEndpointBeingSearchFor.ToString() }; currentSeries = zigzag.ZigZagLows; --waveEndpointBeingSearchFor; } } // Each time we find a wave endpoint, save the price and move to the next one for searching. else if (currentSeries != null && currentSeries[i] > 0.0) { points[waveEndpointBeingSearchFor] = new WavePoint() { Bar = i, Price = zigzag.Value[i] }; labels[waveEndpointBeingSearchFor] = new WavePointWithLabel() { Bar = i, Price = zigzag.Value[i], Label = waveEndpointBeingSearchFor.ToString() }; currentSeries = currentSeries == zigzag.ZigZagHighs ? zigzag.ZigZagLows : zigzag.ZigZagHighs; --waveEndpointBeingSearchFor; } } // Did we get all the points needed to search for the 5 wave trend pattern? if (waveEndpointBeingSearchFor < 0) { // Trend pattern guidelines. // 1. Wave-2 cannot trade beyond the beginning of Wave-1 // 2. Wave-3 cannot be the shortest in price of Waves 1,3, and 5 (but we haven't found // this wave yet so we won't check for that. // 3. Wave-4 cannot make a daily close into the closing range of Wave-1 bool isValidTrend = true; // Guideline 1. if (UtilityMethods.ComparePrices(points[0].Price, points[2].Price, trendDirection) < 0.0) { isValidTrend = false; } // Guideline 2. double wave1PriceLength = Math.Abs(points[1].Price - points[0].Price); double wave3PriceLength = Math.Abs(points[3].Price - points[2].Price); if (wave3PriceLength < wave1PriceLength) { isValidTrend = false; } // Guideline 3. double point1Open = Data.Open[points[1].Bar]; double point1Close = Data.Close[points[1].Bar]; double wave1maxClosingRange = trendDirection > 0.0 ? Math.Max(point1Open, point1Close) : Math.Min(point1Open, point1Close); if (UtilityMethods.ComparePrices(wave1maxClosingRange, Data.Close[points[4].Bar], trendDirection) < 0.0) { isValidTrend = false; } // All the conditions are met up to the 5th wave, so we'll assume this next one is a 5th wave. if (isValidTrend) { fifthWaveDirection = trendDirection; } } // We're in a 5th wave, so lets label it to see on the chart. Also, the next point we'll label // as the 5th point and then save that we aren't in the 5th wave. if (fifthWaveDirection != 0.0) { // Label the 5th wave from the 4th point to now. int fourthWaveBar = points[4].Bar + 1; for (int j = fourthWaveBar; j <= currentBar; j++) { FifthWaveValue[j] = fifthWaveDirection > 0.0 ? Data.Low[j] : Data.High[j]; FifthWaveDirection[j] = fifthWaveDirection; } // See if we can label the 5th point. List <double> zigzagSeries = fifthWaveDirection > 0.0 ? zigzag.ZigZagHighs : zigzag.ZigZagLows; if (zigzagSeries[searchBar] > 0.0) { labels[5] = new WavePointWithLabel() { Price = zigzag.Value[searchBar], Label = "5" }; } // Label all the points regardless if we have a 5th point or not. for (int j = 0; j < 6; j++) { if (labels[j] != null) { WaveLabels[labels[j].Bar] = labels[j]; } } // Reset searching for the next bar. fifthWaveDirection = 0.0; } } }
/** Set the initial body of water. */ public void InitializeWater(float Left, float Width, float Top, float Bottom) { //Calculate the number of edges and nodes we have int edgecount = Mathf.RoundToInt(Width) * 5; int nodecount = edgecount + 1; // 1 extra at the end. // Render line body of water. Body = gameObject.AddComponent <LineRenderer>(); Body.material = mat; Body.material.renderQueue = 1000; Body.positionCount = nodecount; Body.startWidth = 0.1f; // Initialize variables. wavePoints = new WavePoint[nodecount]; meshobjects = new GameObject[edgecount]; meshes = new Mesh[edgecount]; colliders = new GameObject[edgecount]; baseheight = Top; bottom = Bottom; left = Left; // Set line points. for (int i = 0; i < nodecount; i++) { wavePoints[i] = new WavePoint(); wavePoints[i].x = Left + Width * i / edgecount; wavePoints[i].y = Top; wavePoints[i].acceleration = 0; wavePoints[i].velocity = 0; Body.SetPosition(i, new Vector3(wavePoints[i].x, wavePoints[i].y, z)); } // TODO: Review COMP 371 // Set the meshes. for (int i = 0; i < edgecount; i++) { meshes[i] = new Mesh(); // Set the corners of the mesh (trapezoid) Vector3[] Vertices = new Vector3[4]; Vertices[0] = new Vector3(wavePoints[i].x, wavePoints[i].y, z); // Top left Vertices[1] = new Vector3(wavePoints[i + 1].x, wavePoints[i + 1].y, z); // Top right Vertices[2] = new Vector3(wavePoints[i].x, bottom, z); // Bottom left Vertices[3] = new Vector3(wavePoints[i + 1].x, bottom, z); // Bottom right // Set coords for textures. Vector2[] UVs = new Vector2[4]; UVs[0] = new Vector2(0, 1); UVs[1] = new Vector2(1, 1); UVs[2] = new Vector2(0, 0); UVs[3] = new Vector2(1, 0); //Set where the triangles should be (2 triangles, so 6 points) int[] tris = new int[6] { 0, 1, 3, 3, 2, 0 }; //Add all this data to the mesh. meshes[i].vertices = Vertices; meshes[i].uv = UVs; meshes[i].triangles = tris; //Create a holder for the mesh, set it to be the manager's child (to render) meshobjects[i] = Instantiate(watermesh, Vector3.zero, Quaternion.identity) as GameObject; meshobjects[i].GetComponent <MeshFilter>().mesh = meshes[i]; meshobjects[i].transform.parent = transform; //Create our colliders, set them be our child colliders[i] = new GameObject(); colliders[i].name = "Trigger"; colliders[i].AddComponent <BoxCollider2D>(); colliders[i].transform.parent = transform; //Set the position and scale to the correct dimensions colliders[i].transform.position = new Vector3(Left + Width * (i + 0.5f) / edgecount, Top - 0.5f, 0); colliders[i].transform.localScale = new Vector3(Width / edgecount, 1, 1); //Add a WaterDetector and make sure they're triggers colliders[i].GetComponent <BoxCollider2D>().isTrigger = true; colliders[i].AddComponent <WaterDetector>(); } }