Example #1
0
 protected override void OnBarUpdate()
 {
     // Use this method for calculating your indicator values. Assign a value to each
     // plot below by replacing 'Close[0]' with your own formula.
     Plot0.Set(Close[0]);
     Plot1.Set(Close[0]);
     Plot3.Set(Close[0]);
 }
        protected override void CalcBar()
        {
            if (Bars.LastBarInSession)
            {
                m_upperband.Value = (Bars.Close[0] * (1 + (numdevs * volstddev[0] / Math.Sqrt(252))));
                m_lowerband.Value = (Bars.Close[0] * (1 - (numdevs * volstddev[0] / Math.Sqrt(252))));
            }
            else
            {
                m_upperband.Value = (Bars.Close[1] * (1 + (numdevs * volstddev[0] / Math.Sqrt(252))));
                m_lowerband.Value = (Bars.Close[1] * (1 - (numdevs * volstddev[0] / Math.Sqrt(252))));
            }

            Plot1.Set(0, m_upperband.Value);
            Plot2.Set(0, m_lowerband.Value);

            if (enable_depth)
            {
                Plot3.Set(0, (Bars.Close[0] - m_upperband.Value) / (m_upperband.Value - m_lowerband.Value));
                Plot4.Set(0, (m_lowerband.Value - Bars.Close[0]) / (m_upperband.Value - m_lowerband.Value));
            }
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.


            if (CurrentBar < 30)
            {
                return;
            }


            if ((Low[0] <= DonchianChannel(14)[0]) & (Low[1] > DonchianChannel(14)[1]))
            {
                Plot1.Set(1);
            }


            if ((High[0] >= DonchianChannel(14)[0]) & (High[1] < DonchianChannel(14)[1]))
            {
                Plot0.Set(1);
            }

            int up   = 0;
            int down = 0;
            int y    = 0;

            for (int x = 1; x <= 100; x++)
            {
                if ((Low[x] <= DonchianChannel(14)[x]) & (Low[x + 1] > DonchianChannel(14)[x + 1]))
                {
                    up = 1;
                    y  = x;
                    break;
                }


                if ((High[x] >= DonchianChannel(14)[x]) & (High[x + 1] < DonchianChannel(14)[x + 1]))
                {
                    down = 1;
                    y    = x;
                    break;
                }
            }


            int firstup   = 0;
            int firstdown = 0;


            for (int x = 0; x <= 100; x++)
            {
                if ((up == 1) & (High[x] > High[x + 1]))
                {
                    if (x >= y)
                    {
                        break;
                    }

                    if (x != 0)
                    {
                        firstup = 1;
                        break;
                    }

                    /*
                     * if (!(x < y))
                     * {
                     *  break;
                     * }*/
                }


                if ((down == 1) & (Low[x] < Low[x + 1]))
                {
                    if (x >= y)
                    {
                        break;
                    }

                    if (x != 0)
                    {
                        firstdown = 1;
                        break;
                    }

                    /*
                     * if (!(x < y))
                     * {
                     *  break;
                     * }*/
                }
            }

            if ((firstup == 0) & (up == 1) & (High[0] > High[1]))
            {
                Plot3.Set(1);
            }

            if ((firstdown == 0) & (down == 1) & (Low[0] < Low[1]))
            {
                Plot2.Set(1);
            }
        }
Example #4
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Try to connect, if we are not yet connected.
            // We do this here so that we do not connect everytime the indicator is instanciated.
            // Indicators are often instanciated several times before they are actually used.
            if (_indicatorState == IndicatorState.Uninitialized)
            {
                OpenConnection();
            }

            // Are we in an error state?  If so, display and exit.
            if (_indicatorState == IndicatorState.Error)
            {
                DrawError();
                return;
            }

            // If we are actually connected to a socket, then communicate with it.
            if (_sock != null)
            {
                StringBuilder line = new StringBuilder();

                long when = Time[0].Second +
                            Time[0].Minute * 100l +
                            Time[0].Hour * 10000l +
                            Time[0].Day * 1000000l +
                            Time[0].Month * 100000000l +
                            Time[0].Year * 10000000000l;

                line.Append("\"" + PACKET_BAR + "\",");
                line.Append(when);
                line.Append(",\"");
                line.Append(this.Instrument.FullName);
                line.Append("\"");

                foreach (string name in _sourceData)
                {
                    IDataSeries source;
                    int         totalBars = 1;
                    string      name2     = name;

                    ParseArraySize(name, ref totalBars, ref name2);

                    if (string.Compare(name2, "HIGH", true) == 0)
                    {
                        source = High;
                    }
                    else if (string.Compare(name2, "LOW", true) == 0)
                    {
                        source = Low;
                    }
                    else if (string.Compare(name2, "OPEN", true) == 0)
                    {
                        source = Open;
                    }
                    else if (string.Compare(name2, "CLOSE", true) == 0)
                    {
                        source = Close;
                    }
                    else if (string.Compare(name2, "VOL", true) == 0)
                    {
                        source = Volume;
                    }
                    else if (string.Compare(name2, "THIS", true) == 0)
                    {
                        source = Values[0];
                    }
                    else
                    {
                        source = Eval(name2);
                        if (source == null)
                        {
                            return;
                        }
                    }

                    // now copy needed data
                    var cnt = CurrentBar + 1;

                    for (int i = 0; i < totalBars; i++)
                    {
                        line.Append(",");

                        if (i >= cnt)
                        {
                            line.Append("?");
                        }
                        else
                        {
                            //line.Append(Convert.ToString(source[i]));
                            line.Append(Convert.ToString(source[i], _cultureUSA));
                        }
                    }
                }

                Send(line.ToString());

                // if we are expecting data back from the socket, then wait for it.
                if (_blockingMode)
                {
                    // we are now waiting for a bar
                    _indicatorState = IndicatorState.SentBar;
                    while (_indicatorState != IndicatorState.Error && _indicatorState != IndicatorState.Ready)
                    {
                        WaitForPacket();
                    }

                    // we got a bar message, then display it
                    if (_indicatorState == IndicatorState.Ready)
                    {
                        if (!double.IsNaN(_indicatorData[0]))
                        {
                            Plot1.Set(_indicatorData[0]);
                        }

                        if (!double.IsNaN(_indicatorData[1]))
                        {
                            Plot2.Set(_indicatorData[1]);
                        }

                        if (!double.IsNaN(_indicatorData[2]))
                        {
                            Plot3.Set(_indicatorData[2]);
                        }

                        if (!double.IsNaN(_indicatorData[3]))
                        {
                            Bar1.Set(_indicatorData[3]);
                        }

                        if (!double.IsNaN(_indicatorData[4]))
                        {
                            Bar2.Set(_indicatorData[4]);
                        }

                        if (!double.IsNaN(_indicatorData[5]))
                        {
                            Bar3.Set(_indicatorData[5]);
                        }

                        if (!double.IsNaN(_indicatorData[6]))
                        {
                            IndSell.Set(_indicatorData[6]);
                        }

                        if (!double.IsNaN(_indicatorData[7]))
                        {
                            IndBuy.Set(_indicatorData[7]);
                        }
                    }
                }
                else
                {
                    var hold = this.DrawOnPricePanel;
                    DrawOnPricePanel = false;
                    DrawTextFixed("general msg", "This indicator only sends data, so there is no display.", TextPosition.Center);
                    DrawOnPricePanel = hold;
                }
            }
        }