Example #1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // used to set values for bars less than the period
            int tmpPeriod = Math.Min(CurrentBar, Period);

            double average = Close[0];

            switch (averageType)
            {
            case BollingerBandwidth_MATypes.EMA:
                average = EMA(tmpPeriod)[0];
                break;

            case BollingerBandwidth_MATypes.SMA:
                average = SMA(tmpPeriod)[0];
                break;
            }

            double stdDevValue = StdDev(tmpPeriod)[0];
            double upperValue  = average + numStdDev * stdDevValue;
            double lowerValue  = average - numStdDev * stdDevValue;

            Bandwidth.Set((upperValue - lowerValue) / average * 100);
            Bulge.Set(MAX(Bandwidth, bulgeLength)[0]);
            Squeeze.Set(MIN(Bandwidth, squeezeLength)[0]);
        }
Example #2
0
        private void AddHatching(IList <Entity> en)
        {
            var hatch = new Hatch();

            using (var tr = CADProxy.Database.TransactionManager.StartTransaction())
            {
                var p1 = new Polyline();
                p1.AddVertexAt(0, new Point2d(0, -1.5), 0, 0, 0);
                p1.AddVertexAt(0, new Point2d(0, 1.5), 0, 0, 0);
                p1.AddVertexAt(0, new Point2d(1.5, 0), Bulge.GetBulge(new Point2d(0, 0), new Point2d(0, 1.5), new Point2d(1.5, 0)), 0, 0);
                p1.AddVertexAt(0, new Point2d(-1.5, 0), 0, 0, 0);
                p1.AddVertexAt(0, new Point2d(0, -1.5), Bulge.GetBulge(new Point2d(0, 0), new Point2d(-1.5, 0), new Point2d(0, -1.5)), 0, 0);
                p1.Closed = true;
                BlockTable       bt  = tr.GetObject(CADProxy.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = tr.GetObject(CADProxy.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                var bdId             = btr.AppendEntity(p1);
                tr.AddNewlyCreatedDBObject(p1, true);
                ObjectIdCollection ObjIds = new ObjectIdCollection
                {
                    bdId
                };

                hatch.SetDatabaseDefaults();
                hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                hatch.Associative = false;
                hatch.AppendLoop((int)HatchLoopTypes.Default, ObjIds);
                hatch.EvaluateHatch(true);
                p1.Erase();
            }
            en.Add(hatch);
        }
Example #3
0
        /// <summary>Look for a sequence of candles that are entirely above or below the MA</summary>
        private IEnumerable <Bulge> FindBulges(Idx idx, Indicator moving_average)
        {
            if (!idx.Within(Instrument.IdxFirst, Instrument.IdxLast))
            {
                yield break;
            }

            var mcs = Instrument.MCS;

            // Find spans of non-intersecting candles
            var bulge = new Bulge {
                Sign = 0, Range = RangeF.Invalid
            };

            for (var i = idx; i != Instrument.IdxFirst; --i)
            {
                var candle = Instrument[i];
                var ma     = moving_average[i];

                var hi = candle.High - ma;
                var lo = candle.Low - ma;
                if (Math.Abs(hi) < mcs * BulgeDistanceTolerance)
                {
                    hi = 0;
                }
                if (Math.Abs(lo) < mcs * BulgeDistanceTolerance)
                {
                    lo = 0;
                }
                var intersecting = hi == 0 || lo == 0 || Math.Sign(hi) != Math.Sign(lo);
                if (!intersecting && Math.Sign(hi) != -bulge.Sign)
                {
                    // Record the price range spanned
                    bulge.Range.Encompass(i);
                    bulge.Sign = Math.Sign(hi);
                }
                else
                {
                    if (bulge.Range.Size >= NonIntersectingCount)
                    {
                        yield return(bulge);
                    }

                    // Reset for the next bulge
                    bulge = new Bulge {
                        Sign = 0, Range = RangeF.Invalid
                    };
                }
            }
        }
        public override void WriteGroupCodes()
        {
            int flags;

            WriteGroupCodeValue(10, X0.ToString().Trim());
            WriteGroupCodeValue(20, Y0.ToString().Trim());
            WriteGroupCodeValue(30, Z0.ToString().Trim());

            WriteGroupCodeValue(40, StartingWidth.ToString().Trim());
            WriteGroupCodeValue(41, EndingWidth.ToString().Trim());
            WriteGroupCodeValue(42, Bulge.ToString().Trim());
            WriteGroupCodeValue(50, CurveFitTangentDirection.ToString().Trim());

            flags = 0;

            if (ExtraVertexCreatedByCurveFitting)
            {
                flags += 1;
            }
            if (HasCurveFitTangent)
            {
                flags += 2;
            }
            if (SplineVertexCreatedBySplineFitting)
            {
                flags += 8;
            }
            if (SplineFrameControlPoint)
            {
                flags += 16;
            }
            if (Is3DPolylineVertex)
            {
                flags += 32;
            }
            if (Is3DPolygonMeshVertex)
            {
                flags += 64;
            }
            if (IsPolyFaceMeshVertex)
            {
                flags += 128;
            }

            WriteGroupCodeValue(70, flags.ToString().Trim());
        }
Example #5
0
    private void Update()
    {
        float dt = Time.deltaTime;

        timer += dt;

        // we may want to add bulges
        if (timer >= timeNextBulge)
        {
            AddBulge();
        }

        // always start resetting the vertices to their original positions
        Array.Copy(_mainSphereVerticesOriginalPositions, mainVerts, _totalVertices);
        Array.Copy(_wireSphereVerticesOriginalPositions, wireVerts, _totalVertices);
        Array.Copy(_tinySpheresOriginalPositions, tsPositions, _totalTinySpheres);

        // update the vertices according to the active bulges
        for (int i = activeBulges.Count - 1; i >= 0; --i)
        {
            // update the bulge first
            Bulge b = activeBulges[i];
            UpdateBulge(dt, ref b);

            // if it's over let's remove it from the list, otherwise update it (remember we have to do this because it's a struct instead of a class)
            if (b.timer < b.duration)
            {
                activeBulges[i] = b;
            }
            else
            {
                activeBulges.RemoveAt(i);
            }
        }

        // finally update the mesh
        _mainSphereMesh.vertices = mainVerts;
        _wireSphereMesh.vertices = wireVerts;
        for (int i = 0; i < _totalTinySpheres; i++)
        {
            _tinySpheres[i].localPosition = tsPositions[i];
        }
        mainSphereMF.mesh = _mainSphereMesh;
        wireSphereMF.mesh = _wireSphereMesh;
    }
Example #6
0
    /// <summary>
    /// Adds a new bulge, with random values for the center, the duration and (maybe) other stuff, to the list
    /// </summary>
    private void AddBulge()
    {
        // create the new bulge
        Bulge b = new Bulge();

        b.center   = UnityEngine.Random.onUnitSphere * sphereRadius;
        b.duration = UnityEngine.Random.Range(minBulgeDuration, maxBulgeDuration);
        b.timer    = 0.0f;
        b.aoe      = UnityEngine.Random.Range(minAreaOfEffect, maxAreaOfEffect);

        // add it to the list
        activeBulges.Add(b);

        // calculate the time for the new bulge
        float interval = UnityEngine.Random.Range(minTimeBetweenBulges, maxTimeBetweenBulges);

        timeNextBulge += interval;
    }
Example #7
0
    /// <summary>
    /// Updates the given bulge and adapts the vertices of the spheres according to its current position and time
    /// </summary>
    /// <param name="b"></param>
    private void UpdateBulge(float dt, ref Bulge b)
    {
        // always update the time first
        b.timer += dt;

        // we can early quit if the bulge is over
        if (b.timer >= b.duration)
        {
            return;
        }

        // calculate the intensity with the current time
        float intensity = 0.0f;

        if (b.timer < 0.5f * b.duration)
        {
            // the bulge is growing
            intensity = b.timer / (0.5f * b.duration);
        }
        else if (b.timer < b.duration)
        {
            // only update if it's not over
            intensity = (b.duration - b.timer) / (0.5f * b.duration);
        }

        // now with the intensity we can calculate the area of effect
        float areaOfEffect = intensity * b.aoe;
        float aoeSq        = areaOfEffect * areaOfEffect;

        // and with that we can update the vertices in the spheres
        Vector3 dir = b.center.normalized;

        for (int i = 0; i < _totalVertices; ++i)
        {
            Vector3 origV  = _mainSphereVerticesOriginalPositions[i];
            float   distSq = (b.center - origV).sqrMagnitude;
            if (distSq < aoeSq)
            {
                // we're close enough to be affected by the bulge
                float dist   = Mathf.Sqrt(distSq);
                float t      = Mathf.Clamp01(dist / areaOfEffect) * 0.5f * Mathf.PI; //< normalize in the range [0..PI/2] because cos(0) = 1, cos(PI/2) = 0
                float height = Mathf.Cos(t) * 0.5f * areaOfEffect;

                // add that height to the vertex
                // NOTE: [Barkley] Not sure if it's nicer with this line uncommented. The effect seems subtle so I left it commented out, but I think it looks slightly nicer with it uncommented
                dir           = origV.normalized;
                mainVerts[i] += dir * height;
                wireVerts[i] += dir * height;
            }
        }

        // I tried to adpat the code above but it doesn't work, balls don' come back to their original place, they stay still on the
        // highest position of the bulge once they get there. I don't really understand why, tho

        Transform parent           = transform.parent;
        Transform tinySpheres      = transform.GetChild(2);
        int       totalMiniSpheres = tinySpheres.childCount;

        for (int i = 0; i < totalMiniSpheres; i++)
        {
            Vector3 origS     = tinySpheres.GetChild(i).transform.localPosition;
            float   distSq    = (b.center - origS).sqrMagnitude;
            int     vertIndex = tinySpheres.GetChild(i).GetComponent <TinySphere>().Index;
            if (distSq < aoeSq)
            {
                // we're close enough to be affected by the bulge
                float dist   = Mathf.Sqrt(distSq);
                float t      = Mathf.Clamp01(dist / areaOfEffect) * 0.5f * Mathf.PI; //< normalize in the range [0..PI/2] because cos(0) = 1, cos(PI/2) = 0
                float height = Mathf.Cos(t) * 0.5f * areaOfEffect;

                // add that height to the vertex
                // NOTE: [Barkley] Not sure if it's nicer with this line uncommented. The effect seems subtle so I left it commented out, but I think it looks slightly nicer with it uncommented
                dir             = origS.normalized;
                tsPositions[i] += dir * height;
            }
        }
    }