Ejemplo n.º 1
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                Period1 = CreateParameterInt("Period 1", 5);
                Period2 = CreateParameterInt("Period 2", 3);
                Period3 = CreateParameterInt("Period 3", 3);
                Period4 = CreateParameterInt("Period 4", 3);

                SeriesOne = CreateSeries("Stochastic", Color.BlueViolet, IndicatorChartPaintType.Line, true);
                SeriesTwo = CreateSeries("Stochastic Signal Line", Color.Green, IndicatorChartPaintType.Line, true);
            }
            else if (state == IndicatorState.Dispose)
            {
                if (_dm != null)
                {
                    _dm.Clear(); _dm     = null;
                    _diff.Clear(); _diff = null;

                    _dms.Clear(); _dms   = null;
                    _dms2.Clear(); _dms2 = null;

                    _diffS.Clear(); _diffS   = null;
                    _diffS2.Clear(); _diffS2 = null;
                }
            }
        }
Ejemplo n.º 2
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _lengthJaw   = CreateParameterInt("Jaw length", 13);
                _lengthLips  = CreateParameterInt("Lips length", 8);
                _lengthTeeth = CreateParameterInt("Teeth length", 5);

                _shiftJaw   = CreateParameterInt("Jaw offset", 8);
                _shiftLips  = CreateParameterInt("Lips offset", 3);
                _shiftTeeth = CreateParameterInt("Teeth offset", 5);

                _seriesJaw   = CreateSeries("Jaw", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
                _seriesTeeth = CreateSeries("Teeth", Color.DarkRed, IndicatorChartPaintType.Line, true);
                _seriesLips  = CreateSeries("Lips", Color.LawnGreen, IndicatorChartPaintType.Line, true);

                _smaJaw = IndicatorsFactory.CreateIndicatorByName("Ssma", Name + "SsmaJaw", false);
                ((IndicatorParameterInt)_smaJaw.Parameters[0]).Bind(_lengthJaw);
                ProcessIndicator("Jaw SSMA", _smaJaw);

                _smaLips = IndicatorsFactory.CreateIndicatorByName("Ssma", Name + "SsmaLips", false);
                ((IndicatorParameterInt)_smaLips.Parameters[0]).Bind(_lengthLips);
                ProcessIndicator("Lips SSMA", _smaLips);

                _smaTeeth = IndicatorsFactory.CreateIndicatorByName("Ssma", Name + "SsmaTeeth", false);
                ((IndicatorParameterInt)_smaTeeth.Parameters[0]).Bind(_lengthTeeth);
                ProcessIndicator("Teeth SSMA", _smaTeeth);
            }
        }
Ejemplo n.º 3
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _series = CreateSeries("A D", Color.Aqua, IndicatorChartPaintType.Line, true);
     }
 }
Ejemplo n.º 4
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                Period1 = CreateParameterInt("Period 1", 5);
                Period2 = CreateParameterInt("Period 2", 3);
                Period3 = CreateParameterInt("Period 3", 3);

                SeriesOne = CreateSeries("K value", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
                SeriesTwo = CreateSeries("K average", Color.DarkRed, IndicatorChartPaintType.Line, true);
            }
            else if (state == IndicatorState.Dispose)
            {
                if (_t1 != null)
                {
                    _t1.Clear(); _t1 = null;
                    _t2.Clear(); _t2 = null;

                    _tM1.Clear(); _tM1 = null;
                    _tM2.Clear(); _tM2 = null;

                    _k.Clear(); _k   = null;
                    _kM.Clear(); _kM = null;
                }
            }
        }
Ejemplo n.º 5
0
        public static void ToggleInicatorState(Vehicle veh, IndicatorState state)
        {
            switch (state)
            {
            case IndicatorState.Off:
                veh.IsLeftIndicatorLightOn  = false;
                veh.IsRightIndicatorLightOn = false;
                break;

            case IndicatorState.Left:
                veh.IsLeftIndicatorLightOn  = true;
                veh.IsRightIndicatorLightOn = false;
                break;

            case IndicatorState.Right:
                veh.IsLeftIndicatorLightOn  = false;
                veh.IsRightIndicatorLightOn = true;
                break;

            case IndicatorState.Hazard:
                veh.IsLeftIndicatorLightOn  = true;
                veh.IsRightIndicatorLightOn = true;
                break;
            }
        }
Ejemplo n.º 6
0
        public IndicatorWidget(string label = null, IndicatorState state = IndicatorState.RANDOM)
        {
            if (label == null)
            {
                int pos = Random.Range(0, possibleValues.Count);
                val = possibleValues[pos];
                possibleValues.RemoveAt(pos);
            }
            else
            {
                if (possibleValues.Contains(label))
                {
                    val = label;
                    possibleValues.Remove(label);
                }
                else
                {
                    val = "NLL";
                }
            }
            if (state == IndicatorState.RANDOM)
            {
                on = Random.value > 0.4f;
            }
            else
            {
                on = state == IndicatorState.ON ? true : false;
            }

            Debug.Log("Added indicator widget: " + val + " is " + (on ? "ON" : "OFF"));
        }
Ejemplo n.º 7
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _lenght = CreateParameterInt("Length", 14);
         _series = CreateSeries("ER", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
     }
 }
Ejemplo n.º 8
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _period = CreateParameterInt("Period", 14);
         _series = CreateSeries("Cmo", Color.Orange, IndicatorChartPaintType.Line, true);
     }
 }
Ejemplo n.º 9
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _series = CreateSeries("MFI", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
         _period = CreateParameterInt("Period", 3);
     }
 }
Ejemplo n.º 10
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _period      = CreateParameterInt("Period", 20);
         _candlePoint = CreateParameterStringCollection("Candle point", "Close", Entity.CandlePointsArray);
         _series      = CreateSeries("StdDev", Color.Green, IndicatorChartPaintType.Line, true);
     }
 }
Ejemplo n.º 11
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _lenght      = CreateParameterInt("Length", 20);
         _candlePoint = CreateParameterStringCollection("Candle Point", "Typical", Entity.CandlePointsArray);
         _series      = CreateSeries("Cci", Color.CadetBlue, IndicatorChartPaintType.Line, true);
     }
 }
Ejemplo n.º 12
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _length      = CreateParameterInt("Length", 5);
         _candlePoint = CreateParameterStringCollection("Candle point", "Close", Entity.CandlePointsArray);
         _series      = CreateSeries("Momentum", Color.Aqua, IndicatorChartPaintType.Line, true);
     }
 }
Ejemplo n.º 13
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _lenght     = CreateParameterInt("Length", 5);
         _seriesUp   = CreateSeries("SeriesUp", Color.Blue, IndicatorChartPaintType.Point, true);
         _seriesDown = CreateSeries("SeriesDown", Color.DarkRed, IndicatorChartPaintType.Point, true);
     }
 }
Ejemplo n.º 14
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         lenght1 = CreateParameterInt("Lenght 1", 20);
         lenght2 = CreateParameterInt("Lenght 2", 10);
         series1 = CreateSeries("VO", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
     }
 }
Ejemplo n.º 15
0
        public override void OnStateChange(IndicatorState state)
        {
            _period       = CreateParameterInt("Length", 14);
            _seriesZigZag = CreateSeries("ZigZag", Color.CornflowerBlue, IndicatorChartPaintType.Point, false);
            _seriesZigZag.CanReBuildHistoricalValues = true;

            _seriesToLine = CreateSeries("ZigZagLine", Color.CornflowerBlue, IndicatorChartPaintType.Point, true);
            _seriesToLine.CanReBuildHistoricalValues = true;
        }
Ejemplo n.º 16
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         period1 = CreateParameterInt("Period 1", 7);
         period2 = CreateParameterInt("Period 2", 14);
         period3 = CreateParameterInt("Period 3", 28);
         series1 = CreateSeries("UO", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
     }
 }
        internal void SetActualBitrate(int ave, IndicatorState state)
        {
            if (ave < MinBitrate + 30)
            {
                ave = MinBitrate + 30;
            }

            ActualBitrate.Value      = ave;
            ActualBitrateState.Value = state;
        }
 public M4CoffeeMakerApi()
 {
     warmerPlateStatus = WarmerPlateStatus.WARMER_EMPTY;
     boilerStatus      = BoilerStatus.EMPTY;
     boilerState       = BoilerState.OFF;
     brewButtonStatus  = BrewButtonStatus.NOT_PUSHED;
     warmerState       = WarmerState.OFF;
     indicatorState    = IndicatorState.OFF;
     reliefValveState  = ReliefValveState.CLOSED;
 }
Ejemplo n.º 19
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _lookUp   = CreateParameterInt("Look Up", 10);
                _lookBack = CreateParameterInt("Look Back", 10);

                _series = CreateSeries("FBD value", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
            }
        }
Ejemplo n.º 20
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _period      = CreateParameterInt("Period", 14);
                _candlePoint = CreateParameterStringCollection("Candle Point", "Close", Entity.CandlePointsArray);

                _seriesRegressionLine = CreateSeries("Regression Line ", Color.HotPink,
                                                     IndicatorChartPaintType.Line, true);
            }
        }
Ejemplo n.º 21
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _first   = CreateParameterInt("Tenkan", 9);
                _second  = CreateParameterInt("Kijun", 26);
                _fird    = CreateParameterInt("Sencou", 52);
                _sdvig   = CreateParameterInt("Chinkou", 26);
                _chinkou = CreateParameterInt("Deviation", 26);


                _seriesEtalon = CreateSeries("Tenkan", Color.BlueViolet, IndicatorChartPaintType.Line, true);
                _seriesEtalon.CanReBuildHistoricalValues = false;

                _seriesRoundet = CreateSeries("Kijun", Color.OrangeRed, IndicatorChartPaintType.Line, true);
                _seriesRoundet.CanReBuildHistoricalValues = false;

                _seriesLate = CreateSeries("Chinkou", Color.DarkRed, IndicatorChartPaintType.Point, true);
                _seriesLate.CanReBuildHistoricalValues = true;

                _seriesFirst = CreateSeries("Sencou A", Color.LimeGreen, IndicatorChartPaintType.Line, true);
                _seriesFirst.CanReBuildHistoricalValues = false;

                _seriesSecond = CreateSeries("Sencou B", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
                _seriesSecond.CanReBuildHistoricalValues = false;
            }
            else if (state == IndicatorState.Dispose)
            {
                if (_valuesEtalonLine_Kejun_sen != null)
                {
                    _valuesEtalonLine_Kejun_sen.Clear();
                }

                if (_valuesLineRounded_Teken_sen != null)
                {
                    _valuesLineRounded_Teken_sen.Clear();
                }

                if (_valuesLineLate_Chinkou_span != null)
                {
                    _valuesLineLate_Chinkou_span.Clear();
                }

                if (_valuesLineFirst_Senkkou_span_A != null)
                {
                    _valuesLineFirst_Senkkou_span_A.Clear();
                }

                if (_valuesLineSecond_Senkou_span_B != null)
                {
                    _valuesLineSecond_Senkou_span_B.Clear();
                }
            }
        }
Ejemplo n.º 22
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _lenghtUp   = CreateParameterInt("Length up", 21);
                _lenghtDown = CreateParameterInt("Lenght down", 21);

                _seriesUp   = CreateSeries("Up line", Color.Aqua, IndicatorChartPaintType.Line, true);
                _seriesDown = CreateSeries("Down line", Color.BlueViolet, IndicatorChartPaintType.Line, true);
            }
        }
Ejemplo n.º 23
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _period = CreateParameterInt("Period", 14);

                _seriesLine = CreateSeries("EaseOfMovement", Color.Aqua, IndicatorChartPaintType.Line, true);
                _seriesLine.CanReBuildHistoricalValues = false;

                _seriesEomRaw = CreateSeries("Eom Raw", Color.Red, IndicatorChartPaintType.Line, false);
            }
        }
        public void MatrixScan(MatrixScan matrixScan, Frame didUpdate)
        {
            if (didUpdate.TrackedCodes.Count == 0)
            {
                return;
            }

            IndicatorState indicatorState = CalculateIndicatorState(didUpdate.TrackedCodes);

            if (lastIndicatorState != indicatorState)
            {
                bubbles.Clear();
                if (indicatorState != IndicatorState.HIGHLIGHT_ONLY)
                {
                    foreach (var it in didUpdate.TrackedCodes)
                    {
                        var bubble = bubbleFactory.CreateBubble(indicatorState, it.Value);
                        bubbles.AddOrUpdate(
                            it.Key.LongValue(),
                            bubble,
                            (arg1, arg2) => bubble);

                        viewBasedMatrixScanOverlay.SetOffsetForCode(GetOffsetForCode(it.Value, it.Key.LongValue()), it.Key.LongValue());
                        viewBasedMatrixScanOverlay.Post(() =>
                        {
                            if (bubbles.ContainsKey(it.Key.LongValue()))
                            {
                                viewBasedMatrixScanOverlay.SetViewForCode(GetViewForCode(it.Value, it.Key.LongValue()), it.Key.LongValue());
                            }
                        });
                    }
                }
            }
            lastIndicatorState = indicatorState;

            foreach (var id in didUpdate.AddedIdentifiers)
            {
                if (didUpdate.TrackedCodes.ContainsKey(id))
                {
                    var bubble = bubbleFactory.CreateBubble(indicatorState, didUpdate.TrackedCodes[id]);
                    bubbles.AddOrUpdate(
                        id.LongValue(),
                        bubble,
                        (arg1, arg2) => bubble);
                }
            }

            foreach (var id in didUpdate.RemovedIdentifiers)
            {
                ((IDictionary <long, BaseBubble>)bubbles).Remove(id.LongValue());
            }
        }
Ejemplo n.º 25
0
 public void UpdateHatchIndicatorState()
 {
     if (Location is Hatch)
     {
         var thisSide = FindLocale(this) as Room;
         var otherHatch = Portal.FindOppositeSide(Location);
         Room otherSide = otherHatch == null ? null : otherHatch.Location as Room;
         if (thisSide != null && otherSide != null && thisSide.AirLevel == otherSide.AirLevel)
             Indicator = IndicatorState.green;
         else
             Indicator = IndicatorState.red;
     }
 }
Ejemplo n.º 26
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _length = CreateParameterInt("Period", 13);

                _series = CreateSeries("Values", Color.LimeGreen, IndicatorChartPaintType.Column, true);

                _sma = IndicatorsFactory.CreateIndicatorByName("Sma", Name + "Sma", false);
                ((IndicatorParameterInt)_sma.Parameters[0]).Bind(_length);
                ProcessIndicator("Sma", _sma);
            }
        }
Ejemplo n.º 27
0
 public void SetIndicatorState(IndicatorState state)
 {
     if (state == IndicatorState.On)
     {
         _boilerStatus     = BoilerStatus.Empty;
         _warmerStatus     = WarmerPlateStatus.PotNotEmpty;
         _brewButtonStatus = BrewButtonStatus.NotPushed;
         return;
     }
     _boilerStatus     = BoilerStatus.NotEmpty;
     _warmerStatus     = WarmerPlateStatus.PotEmpty;
     _brewButtonStatus = BrewButtonStatus.Pushed;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Tell the remote that we are about to disconnect.
 /// </summary>
 protected void PerformGoodBye()
 {
     try
     {
         Log("Encog: Shutting down socket", LogLevel.Information);
         Send("\"" + PACKET_GOODBYE + "\"");
         _sock.Close();
         _sock = null;
     }
     finally
     {
         _indicatorState = IndicatorState.Uninitialized;
     }
 }
Ejemplo n.º 29
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _series    = CreateSeries("Kalman", Color.DodgerBlue, IndicatorChartPaintType.Line, true);
                _sharpness = CreateParameterDecimal("Sharpness", 1);
                K          = CreateParameterDecimal("K", 1);
            }

            if (state == IndicatorState.Dispose)
            {
                _velocity.Clear();
            }
        }
Ejemplo n.º 30
0
        public override void OnStateChange(IndicatorState state)
        {
            if (state == IndicatorState.Configure)
            {
                _lenght = CreateParameterInt("Length", 5);

                _seriesUp   = CreateSeries("SeriesUp", Color.DarkRed, IndicatorChartPaintType.Point, true);
                _seriesDown = CreateSeries("SeriesDown", Color.DarkGreen, IndicatorChartPaintType.Point, true);

                _fractial = IndicatorsFactory.CreateIndicatorByName("Fractail_lenth", Name + "Fractail", false);
                ((IndicatorParameterInt)_fractial.Parameters[0]).Bind(_lenght);
                ProcessIndicator("Fractail", _fractial);
            }
        }
Ejemplo n.º 31
0
 public override void OnStateChange(IndicatorState state)
 {
     if (state == IndicatorState.Configure)
     {
         _series = CreateSeries("OBV", Color.Orange, IndicatorChartPaintType.Line, true);
     }
     else if (state == IndicatorState.Dispose)
     {
         if (_temp != null)
         {
             _temp.Clear();
         }
     }
 }
        /// <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;
                }
            }
        }
        /// <summary>
        /// Process a packet.
        /// </summary>
        /// <param name="line">The packet line.</param>
        protected void GotPacket(String line)
        {
            var list = ParseCSV(line);
            var temp = new List<string>();

            list[0] = list[0].ToUpper();

            // a SIGNALS packet tells us what indicators and fund data the remote wants.
            if( string.Compare(list[0],PACKET_SIGNALS,true)==0 )
            {
                _sourceData = new List<string>();
                for(int i=1;i<list.Count;i++)
                {
                    _sourceData.Add(list[i]);
                }

            }
            // The INIT packet tells us what protocol version we are using,
            // and if blocking mode is requested.
            else if ( string.Compare(list[0],PACKET_INIT,true)==0 )
            {
                _blockingMode = list[1].Trim()=="1";
                _indicatorState = IndicatorState.Ready;
                Log("Encog: Blocking mode: " + _blockingMode, LogLevel.Information );
            }
            // The ERROR packet allows the server to put us into an error state and
            // provide a string that tells the reason.
            else if ( string.Compare(list[0],PACKET_ERROR,true)==0 )
            {
                PerformError("Server Error: " + list[1]);
            }
            // The WARNING packet allows the server to log a warning.
            else if ( string.Compare(list[0],PACKET_WARNING,true)==0 )
            {
                Log("Encog Warning: " + list[1],LogLevel.Warning);
            }
            // The IND packet provides indicator data, to be displayed.  Only used
            // when in blocking mode.
            else if ( string.Compare(list[0],PACKET_IND,true)==0 )
            {
                if( list.Count != 9 )
                {
                    PerformError("Not enough indicator values from Encog, must have 8, had:" + (list.Count-1));
                    return;
                }

                try
                {
                    for(int i=0;i<8;i++)
                    {
                        if( "?".Equals(list[i+1]) )
                        {
                            _indicatorData[i] = double.NaN;
                        }
                        else
                        {
                            //_indicatorData[i] = double.Parse(list[i+1]);
                            _indicatorData[i] = double.Parse(list[i+1],_cultureUSA);
                        }
                    }
                }
                catch(FormatException ex)
                {
                    PerformError(ex.Message);
                }
                _indicatorState = IndicatorState.Ready;
            }
        }
        /// <summary>
        /// Open a connection to Encog. Also send the HELLO packet.
        /// </summary>
        protected void OpenConnection()
        {
            try
            {
                IPAddress[] ips = Dns.GetHostAddresses(host);
                IPAddress targetIP = null;

                // first we need to resolve the host name to an IP address
                foreach( IPAddress ip in ips )
                {
                    if( ip.AddressFamily == AddressFamily.InterNetwork )
                    {
                        targetIP = ip;
                        break;
                    }
                }

                // if successful, then connect to the remote and send the HELLO packet.
                if( targetIP!=null )
                {
                    IPEndPoint endPoint = new IPEndPoint(targetIP,port);
                    _sock = new Socket(targetIP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    _sock.Connect(endPoint);
                    Send("\""+PACKET_HELLO+"\",\"NinjaTrader 7\",\""+indicatorName+"\"");
                }
                else
                {
                    // report failure and exit
                    PerformError("Failed to resolve: " + host);
                    return;
                }

                // make sure the socket will timeout
                _sock.ReceiveTimeout = TIMEOUT;
                _indicatorState = IndicatorState.Uninitialized;

                while( _indicatorState == IndicatorState.Uninitialized )
                {
                    WaitForPacket();
                }
            }
            catch (Exception ex)
            {
                _sock = null;
                PerformError(ex.Message);
            }
        }
 /// <summary>
 /// Handle an error.  Display the error to the user, log it,
 /// and set the state to error.  No further processing on this
 /// indicator will occur.
 /// </summary>
 /// <param name="whatError">The error text.</param>
 protected void PerformError(string whatError)
 {
     try
     {
         _indicatorState = IndicatorState.Error;
         _errorText = whatError;
         Log("Encog Error: " + whatError ,LogLevel.Error);
         Log("Encog: Shutting down socket", LogLevel.Information);
         Send("\""+PACKET_GOODBYE+"\"");
         _sock.Close();
         _sock = null;
     }
     finally
     {
         DrawError();
     }
 }
 /// <summary>
 /// Tell the remote that we are about to disconnect.
 /// </summary>
 protected void PerformGoodBye()
 {
     try
     {
         Log("Encog: Shutting down socket", LogLevel.Information);
         Send("\""+PACKET_GOODBYE+"\"");
         _sock.Close();
         _sock = null;
     }
     finally
     {
         _indicatorState = IndicatorState.Uninitialized;
     }
 }
Ejemplo n.º 37
0
 public void SetIndicatorState(IndicatorState indicatorState)
 {
     this.IndicatorState = indicatorState;
 }