コード例 #1
0
 // Start is called before the first frame update
 void Start()
 {
     BPlay = GameObject.Find("Play");
     BStop = GameObject.Find("Stop");
     Cube  = GameObject.Find("Cube");
     BPlay.SetActive(true);
     BStop.SetActive(false);
 }
コード例 #2
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             if (hit.collider.tag == "Play")
             {
                 BPlay.SetActive(false);
                 BStop.SetActive(true);
                 Cube.GetComponent <AudioSource>().Play();
             }
             if (hit.collider.tag == "Stop")
             {
                 BPlay.SetActive(true);
                 BStop.SetActive(false);
                 Cube.GetComponent <AudioSource>().Stop();
             }
         }
     }
 }
コード例 #3
0
ファイル: csInd.cs プロジェクト: fandres70/NinjaTrader.Base
        protected override void OnBarUpdate()
        {
            #region Filtered Wave

            if (CurrentBar == 0)                                                               //initialize variables
            {
                dVal = devType == DeviationType.Points ? devValue * TickSize : devValue / 100; // adjust deviation value to points or percent
                ResetPK(); ResetTR();
                return;
            }

            if (WaveCount() == 0)             //update variables unitl first peak or trough is formed
            {
                if (Comp(High[0], pk) >= 0)
                {
                    ResetPK();                                         // new high
                }
                else if (Comp(Low[0], tr) <= 0)
                {
                    ResetTR();                                             // new low
                }
            }

            if (Comp(Low[0], pkRS) <= 0)         //Peak has formed; downswing
            {
                if (swing != -1)                 // Set peak and switch to downswing
                {
                    peak.Insert(0, pk);
                    peakBar.Insert(0, pkBar);
                    if (trough.Count > 0)
                    {
                        midPoint.Insert(0, ((double)peak[0] + (double)trough[0]) / 2);
                        midBar.Insert(0, ((int)peakBar[0] + (int)troughBar[0]) / 2);
                        if (midBar.Count > 1)
                        {
                            int xMid = CurrentBar - (int)midBar[0];
                            DrawDot("Mid" + CurrentBar, true, xMid, (double)midPoint[0], Color.Gold);
                        }
                    }
                    int xPeak = CurrentBar - pkBar;
                    DrawDot("Peak" + pkBar, true, xPeak, (double)peak[0], Color.Green);
                    swing = -1;
                }
                ResetTR();
                pk = trRS; pkRS = pk - LDev(pk, dVal);
            }

            else if (Comp(High[0], trRS) >= 0)  //Trough has formed; upswing
            {
                if (swing != 1)                 // Set trough and switch to upswing
                {
                    trough.Insert(0, tr);
                    troughBar.Insert(0, trBar);
                    if (peak.Count > 0)
                    {
                        midPoint.Insert(0, ((double)peak[0] + (double)trough[0]) / 2);
                        midBar.Insert(0, ((int)peakBar[0] + (int)troughBar[0]) / 2);
                        if (midBar.Count > 1)
                        {
                            int xMid = CurrentBar - (int)midBar[0];
                            DrawDot("Mid" + CurrentBar, true, xMid, (double)midPoint[0], Color.Gold);
                        }
                    }
                    int xTrough = CurrentBar - trBar;
                    DrawDot("Trough" + trBar, true, xTrough, (double)trough[0], Color.Blue);
                    swing = 1;
                }
                ResetPK();
                tr = pkRS; trRS = tr + HDev(tr, dVal);
            }

            #endregion

            #region Set Initial Stops

            if (WaveCount() < 5)
            {
                ll = Math.Min(ll, Low[0]);
                hh = Math.Max(hh, High[0]);
                return;
            }
            if (WaveCount() == 5)
            {
                init += 1;
                if (init == 1)
                {
                    //double b = MAX(High, CurrentBar)[0] + TickSize;
                    //double s = MIN(Low, CurrentBar)[0] - TickSize;
                    double b = hh + TickSize;
                    double s = ll - TickSize;
                    BStop.Set(b);
                    SStop.Set(s);
                    return;
                }
            }

            #endregion

            #region Strategy

            switch (trend)
            {
            case 0:                               // neutral trend - strategy starting
                if (Comp(High[0], BStop[1]) >= 0) // up trend
                {
                    BStop.Set(High[0] + TickSize); SStop.Set(SStop[1]);
                    trend = 1; ss = SStop[1]; slope = 0;
                }
                else if (Comp(Low[0], SStop[1]) <= 0)                           // down trend
                {
                    SStop.Set(Low[0] - TickSize); BStop.Set(BStop[1]);
                    trend = -1; bs = BStop[1]; slope = 0;
                }
                else
                {
                    BStop.Set(BStop[1]); SStop.Set(SStop[1]);
                }
                break;

            case 1:
                if (Comp(Low[0], SStop[1]) <= 0)                                // switch to down trend
                {
                    SStop.Set(Low[0] - TickSize); BStop.Set(BStop[1]);
                    trend = -1; bs = BStop[1]; slope = 0;
                }
                else                         // continue uptrend
                {
                    BStop.Set(Math.Max(BStop[1], High[0] + TickSize));
                    slope = Math.Max(slope, MSlope());
                    ss   += slope;
                    double s = Math.Floor(ss * (1.0 / TickSize)) / (1.0 / TickSize);
                    if (Comp(s, MIN(Low, period)[0] - TickSize) >= 0)
                    {
                        s = MIN(Low, period)[0] - TickSize; ss = s;
                    }
                    SStop.Set(s);
                }

                break;

            case -1:
                if (Comp(High[0], BStop[1]) >= 0)                                       // switch to up trend
                {
                    BStop.Set(High[0] + TickSize); SStop.Set(SStop[1]);
                    trend = 1; ss = SStop[1]; slope = 0;
                }
                else                         // continue downtrend
                {
                    SStop.Set(Math.Min(SStop[1], Low[0] - TickSize));
                    slope = Math.Min(slope, MSlope());
                    bs   += slope;
                    double b = Math.Ceiling(bs * (1.0 / TickSize)) / (1.0 / TickSize);
                    //b = Math.Max(b, MAX(High, period)[0] + TickSize);
                    if (Comp(b, MAX(High, period)[0] + TickSize) <= 0)
                    {
                        b = MAX(High, period)[0] + TickSize; bs = b;
                    }
                    BStop.Set(b);
                }

                break;
            }

            #endregion
        }