public bool Solve(Components.Circuit cir, BasicAnalysis ana)
        {
            List <Node> nodos = new List <Node>();

            Voltages = new Dictionary <double, Dictionary <string, double> >();
            Currents = new Dictionary <double, Dictionary <string, double> >();
            circuit  = cir;

            SolveInfo solveinfo = new SolveInfo();

            //nodos.AddRange(cir.Nodes.Values);
            //nodos.Remove(cir.Reference);

            PreAnalizeToSolve(cir, nodos, solveinfo);

            TransientAnalysis analis = ana as TransientAnalysis;
            double            t, tf, deltat;

            deltat          = StringUtils.DecodeString(analis.Step);
            tf              = StringUtils.DecodeString(analis.FinalTime);
            t               = 0;
            cir.CircuitTime = t;
            cir.Reset();

            while (t < tf)
            {
                //Calculo de tensiones de nodos
                Calculate(solveinfo, t);

                Dictionary <string, double> result = new Dictionary <string, double>();

                #region almacenamiento temporal

                foreach (var nodo in nodos)
                {
                    result.Add(nodo.Name, nodo.Voltage.Real);
                }

                if (!Voltages.ContainsKey(t))
                {
                    Voltages.Add(t, result);
                }
                #endregion

                //calculo las corrientes:
                CalculateCurrents(cir, t);
                Dictionary <string, double> currents = new Dictionary <string, double>();
                StorageCurrents(cir, currents);
                Currents.Add(t, currents);


                cir.CircuitTime = t;
                t += deltat;
            }
            cir.State = Circuit.CircuitState.Solved;

            return(true);
        }
 public static void Main()
 { 
     // 2 variables to store path of file and txt in that file
     string path, text;
     
     // Keep prompting the user for the path if he/she doesn't co-operate
     do
     {
         Console.Write("The file's path: ");
         path = Console.ReadLine();
     
     }
     while (string.IsNullOrEmpty(path?.Trim()));
     
     // Check if the path is valid or invalid
     try
     {
         // Store the text in the file if the path is VALID
         text = File.ReadAllText(path);
     }
     catch (Exception)
     {
         // Display useful messages and exit if the path is INVALID
         Console.WriteLine("FILE DOES NOT EXIST !");
         Console.WriteLine("-> please enter the file's full path");
         return;
     }
     
     // Store the number of letters/words/sentences in text in their variables
     var numberOfLetters = BasicAnalysis.CharacterCounter(text.Trim());
     var numberOfWords = BasicAnalysis.WordCounter(text.Trim());
     var numberOfSentences = BasicAnalysis.SentenceCounter(text.Trim());
     
     // Store the average number of letters\sentences per 100 words
     var averageNumberOfLetters = (int) Math.Round(ReadabilityAnalysis.LettersAverageNumber(numberOfLetters, numberOfWords));
     var averageNumberOfSentences = (int) Math.Round(ReadabilityAnalysis.SentencesAverageNumber(numberOfSentences, numberOfWords));
     
     // Populate the array with the number of times the alphabets have shown in text 
     for (var i = 0; i < Globals.AlphabetArray.Length; i++)
     {
         Globals.AlphabetFrequencies[i] = FrequencyAnalysis.Frequency(text, Globals.AlphabetArray[i]);
     }
     
     // Store the frequency of the letter that has appeared in text only
     /* It's max size is 26 because it won't store more than the alphabets */
     var frequencies = new int[Globals.Alphabet];
     // Store frequency's percentage of letter that has appeared in text
     /* It's with max size 26 because it won't store more than the alphabets */
     var frequenciesPercentage = new float[Globals.Alphabet];
     
     // Iterate over the array stored the frequencies of all alphabets
     for (var i = 0; i < Globals.AlphabetFrequencies.Length; i++)
     {
         // Check if the letter has appeared at least one in text
         if (Globals.AlphabetFrequencies[i] > 0)
         {
             // Populate "frequencies" array with that letter's frequency
             frequencies[i] = Globals.AlphabetFrequencies[i];
             // Populate "frequenciesPercentage" array with that letter's frequency percentage 
             frequenciesPercentage[i] = FrequencyAnalysis.FrequencyPercentage(text, Globals.AlphabetArray[i]);
             
             // Print the frequency, frequency percentage and histogram to console
             Console.Write("Frequency of {0}: {1:F}%\t", Globals.AlphabetArray[i], frequenciesPercentage[i]);
             FrequencyAnalysis.HistogramDrawer(text, Globals.AlphabetArray[i]);
             Console.WriteLine();
         }
     }
     // Display the readability of the text
     ReadabilityAnalysis.Readability(averageNumberOfLetters, averageNumberOfSentences);
     // Display the Most frequently used word
     Console.WriteLine("The most frequently used word is: " + AdvancedAnalysis.MostFrequentlyUsedWord(text));
 }
        public override bool Solve(Circuit cir, BasicAnalysis ana)
        {
            List <Node> nodos = new List <Node>();

            CurrentAnalysis = ana as ComplexPlainAnalysis;
            CurrentCircuit  = cir;

            //List<Node> nodosnorton = new List<Node>();
            //List<Node> nodoscalculables = new List<Node>();
            //List<SpecialComponentInfo> especialcomponents;
            Voltages     = new Dictionary <Complex32, Dictionary <string, Complex32> >();
            Currents     = new Dictionary <Complex32, Dictionary <string, Complex32> >();
            WfromIndexes = new Dictionary <Tuple <int, int>, Complex32>();
            SolveInfo solveinfo = new SolveInfo();

            PreAnalizeToSolve(cir, nodos, solveinfo);


            ComplexPlainAnalysis analis = ana as ComplexPlainAnalysis;
            double w, sig, wi, wf, deltaw, deltasig, sigmamin, sigmamax;

            wi       = analis.WMin;
            wf       = analis.WMax;
            sigmamax = analis.SigmaMax;
            sigmamin = analis.SigmaMin;
            w        = wi;
            sig      = sigmamin;
            deltaw   = (wf - wi) / analis.Points;
            deltasig = (sigmamax - sigmamin) / analis.Points;

            Complex32 W = Complex32.Zero;

            for (int i = 0; i <= analis.Points; i++)
            {
                for (int j = 0; j <= analis.Points; j++)
                {
                    //Calculo de tensiones de nodos
                    W = new Complex32((float)(sigmamin + j * deltasig), (float)(wi + i * deltaw));
                    ACSweepSolver.Calculate(solveinfo, W);

                    //          Node    Voltage
                    Dictionary <string, Complex32> result = new Dictionary <string, Complex32>();

                    #region almacenamiento temporal

                    foreach (var nodo in nodos)
                    {
                        result.Add(nodo.Name, nodo.Voltage);
                    }
                    if (!Voltages.ContainsKey(W))
                    {
                        Voltages.Add(W, result);
                        WfromIndexes.Add(new Tuple <int, int>(i, j), W);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    // Results[i,j] = new Tuple<Complex32,Complex32>(W,

                    #endregion

                    //calculo las corrientes:
                    CalculateCurrents(cir, W);
                    Dictionary <string, Complex32> currents = new Dictionary <string, Complex32>();
                    StorageCurrents(cir, currents);
                    Currents.Add(W, currents);
                }
            }
            cir.State = Circuit.CircuitState.Solved;

            return(true);
        }
        public virtual bool Solve(Circuit cir, BasicAnalysis ana)
        {
            //int fila = 0;
            List <Node> nodos = new List <Node>();

            circuit = cir;

            if (cir.Reference == null)
            {
                foreach (var nodo in cir.Nodes.Values)
                {
                    //creo una lista de nodos sin el nodo referencia
                    if (!nodo.IsReference)
                    {
                        nodos.Add(nodo);
                    }
                }
            }
            else
            {
                nodos.AddRange(cir.Nodes.Values);
                nodos.Remove(cir.Reference);
            }


            List <Node> nodosnorton = new List <Node>();
            List <Node> nortoncopia = new List <Node>();

            foreach (var nodo in nodos)
            {
                if (nodo.TypeOfNode == Node.NodeType.MultibranchCurrentNode ||
                    nodo.TypeOfNode == Node.NodeType.VoltageLinkedNode ||
                    nodo.TypeOfNode == Node.NodeType.VoltageDivideNode)
                {
                    nodosnorton.Add(nodo);
                }
            }

            #region Calculo de tensiones de nodos

            nortoncopia.Clear();
            foreach (var item in nodosnorton)
            {
                nortoncopia.Add(item);
            }

            Calculate(nortoncopia);
            #endregion

            //#region almacenamiento temporal


            //#endregion

            //calculo las corrientes:
            CalculateCurrents(cir);


            cir.State = Circuit.CircuitState.Solved;
            return(true);
        }
        public bool Solve(Components.Circuit cir, BasicAnalysis ana)
        {
            List<Node> nodos = new List<Node>();
            Voltages = new Dictionary<double, Dictionary<string, double>>();
            Currents = new Dictionary<double, Dictionary<string, double>>();
            circuit = cir;

            SolveInfo solveinfo = new SolveInfo();

            //nodos.AddRange(cir.Nodes.Values);
            //nodos.Remove(cir.Reference);
           
            PreAnalizeToSolve(cir, nodos, solveinfo);
       
            TransientAnalysis analis = ana as TransientAnalysis;
            double t, tf, deltat;

            deltat = StringUtils.DecodeString(analis.Step);
            tf = StringUtils.DecodeString(analis.FinalTime);
            t = 0;
            cir.CircuitTime = t;
            cir.Reset();

            while (t < tf)
            {
                //Calculo de tensiones de nodos
                Calculate(solveinfo, t);

                Dictionary<string, double> result = new Dictionary<string, double>();

                #region almacenamiento temporal

                foreach (var nodo in nodos)
                {
                    result.Add(nodo.Name, nodo.Voltage.Real);
                }

                if (!Voltages.ContainsKey(t))
                    Voltages.Add(t, result);
                #endregion

                //calculo las corrientes:
                CalculateCurrents(cir, t);
                Dictionary<string, double> currents = new Dictionary<string, double>();
                StorageCurrents(cir, currents);
                Currents.Add(t, currents);


                cir.CircuitTime = t;
                t += deltat;
            }
            cir.State = Circuit.CircuitState.Solved;

            return true;
        }
        public override bool Solve(Circuit cir, BasicAnalysis ana)
        {
            List <Node> nodos = new List <Node>();

            Voltages = new Dictionary <double, Dictionary <string, Complex32> >();
            Currents = new Dictionary <double, Dictionary <string, Complex32> >();

            //List<Node> nodosnorton;
            //List<Node> nodoscalculables;
            //List<SpecialComponentInfo> specialcomponents;
            SolveInfo solveinfo = new SolveInfo();

            PreAnalizeToSolve(cir, nodos, solveinfo);

            ACAnalysis analis = ana as ACAnalysis;
            double     w, wi, wf, deltaw, wx, pow = 1;

            wi = StringUtils.DecodeString(analis.StartFrequency);
            wf = StringUtils.DecodeString(analis.EndFrequency);
            w  = wi;
            int i = (int)Math.Log10(wi) + 1;

            wx = Math.Pow(10, i);
            if (analis.ScanType == ACAnalysis.ACAnalysisScan.Linear)
            {
                deltaw = (wf - wi) / analis.Points;
            }
            else
            {
                deltaw = 1.0d / analis.Points;
                pow    = Math.Pow(10, deltaw);
            }

            while (w < wf)
            {
                //Calculo de tensiones de nodos
                Complex32 W = new Complex32(0, (float)w);
                Calculate(solveinfo, W);

                Dictionary <string, Complex32> result = new Dictionary <string, Complex32>();

                #region almacenamiento temporal

                foreach (var nodo in nodos)
                {
                    result.Add(nodo.Name, nodo.Voltage);
                }

                if (!Voltages.ContainsKey(w))
                {
                    Voltages.Add(w, result);
                }
                #endregion

                //calculo las corrientes:
                CalculateCurrents(cir, W);
                Dictionary <string, Complex32> currents = new Dictionary <string, Complex32>();
                StorageCurrents(cir, currents);
                Currents.Add(w, currents);


                if (analis.ScanType == ACAnalysis.ACAnalysisScan.Linear)
                {
                    w += deltaw;
                }
                else
                {
                    w = w * pow;
                    if (w > 0.95 * wx)
                    {
                        i++;
                        wi = wx;
                        wx = Math.Pow(10, i);
                        w  = wi;
                    }
                }
            }

            cir.State = Circuit.CircuitState.Solved;
            return(true);
        }
        public override bool Solve(Circuit cir, BasicAnalysis ana)
        {
            List<Node> nodos = new List<Node>();
            Voltages = new Dictionary<double, Dictionary<string, Complex32>>();
            Currents = new Dictionary<double, Dictionary<string, Complex32>>();

            //List<Node> nodosnorton;
            //List<Node> nodoscalculables;
            //List<SpecialComponentInfo> specialcomponents;
            SolveInfo solveinfo = new SolveInfo();

            PreAnalizeToSolve(cir, nodos, solveinfo);

            ACAnalysis analis = ana as ACAnalysis;
            double w, wi, wf, deltaw, wx, pow = 1;

            wi = StringUtils.DecodeString(analis.StartFrequency);
            wf = StringUtils.DecodeString(analis.EndFrequency);
            w = wi;
            int i = (int)Math.Log10(wi) + 1;
            wx = Math.Pow(10, i);
            if (analis.ScanType == ACAnalysis.ACAnalysisScan.Linear)
                deltaw = (wf - wi) / analis.Points;
            else
            {
                deltaw = 1.0d / analis.Points;
                pow = Math.Pow(10, deltaw);
            }

            while (w < wf)
            {
                //Calculo de tensiones de nodos
                Complex32 W = new Complex32(0, (float)w);
                Calculate(solveinfo, W);

                Dictionary<string, Complex32> result = new Dictionary<string, Complex32>();

                #region almacenamiento temporal
 
                foreach (var nodo in nodos)
                {
                    result.Add(nodo.Name, nodo.Voltage);
                }

                if (!Voltages.ContainsKey(w))
                    Voltages.Add(w, result);
                #endregion

                //calculo las corrientes:
                CalculateCurrents(cir, W);
                Dictionary<string, Complex32> currents = new Dictionary<string, Complex32>();
                StorageCurrents(cir, currents);
                Currents.Add(w, currents);


                if (analis.ScanType == ACAnalysis.ACAnalysisScan.Linear)
                    w += deltaw;
                else
                {
                    w = w * pow;
                    if (w > 0.95 * wx)
                    {
                        i++;
                        wi = wx;
                        wx = Math.Pow(10, i);
                        w = wi;
                    }
                }
            }

            cir.State = Circuit.CircuitState.Solved;
            return true;
        }
Esempio n. 8
0
        private void UpdatePlot(DurationEnum duration)
        {
            Plots.Clear();

            if (Ticks == null || !Ticks.Any())
            {
                return;
            }

            var candles = CreatePlot(Name, CreateCandleStickSeries(Name + " " + duration, Ticks));

            var dateValues = Ticks.ToDateValuePoints(x => x.Close).ToList();

            var ema          = MovingAverage.CalculateEma(Ticks, 22);
            var channels     = MovingAverage.CalculateEmaChannels(Ticks, 22, 60);
            var lowerChannel = channels.Select(x => new DateValue {
                Date = x.Date, Value = x.LowerValue
            }).ToList();
            var upperChannel = channels.Select(x => new DateValue {
                Date = x.Date, Value = x.UpperValue
            }).ToList();

            var plotChannels = CreatePlot("Channels",
                                          CreateLineSeries("Close Price", OxyColor.FromUInt32(0xCCF0A30A), dateValues),
                                          CreateLineSeries("EMA 22", OxyColor.FromUInt32(0xCCFA6800), ema),
                                          CreateLineSeries("Lower Channel", OxyColor.FromUInt32(0xCCA4C400), lowerChannel),
                                          CreateLineSeries("Upper Channel", OxyColor.FromUInt32(0xCC60A917), upperChannel));

            var plotMa = CreatePlot("Moving Average",
                                    CreateLineSeries("Close Price", OxyColor.FromUInt32(0xCCF0A30A), dateValues),
                                    CreateLineSeries("MA 10", OxyColor.FromUInt32(0xCCA4C400), BasicAnalysis.CalculateMovingAverage(Ticks, 10)),
                                    CreateLineSeries("MA 100", OxyColor.FromUInt32(0xCC60A917), BasicAnalysis.CalculateMovingAverage(Ticks, 100)));

            var plotMinMax = CreatePlot("Min max",
                                        CreateLineSeries("Close Price", OxyColor.FromUInt32(0xCCF0A30A), dateValues),
                                        CreateLineSeries("Max 50", OxyColor.FromUInt32(0xCCA4C400), BasicAnalysis.CalculateMax(Ticks, 50)),
                                        CreateLineSeries("Min 50", OxyColor.FromUInt32(0xCC60A917), BasicAnalysis.CalculateMin(Ticks, 50)));

            var returns = CreatePlot("Returns", "P4",
                                     CreateTwoColorLineSeries("Annualized Returns", OxyColor.FromUInt32(0xCC60A917), OxyColor.FromUInt32(0xCCFA6800), CalculateReturns(dateValues)));

            Plots.Add(new PlotViewModel(candles));
            Plots.Add(new PlotViewModel(plotChannels));
            Plots.Add(new PlotViewModel(plotMa));
            Plots.Add(new PlotViewModel(plotMinMax));
            Plots.Add(new PlotViewModel(returns));

            //analysisPlotModel.Series.Add(closePrices);

            //analysisPlotModel.Series.Add(CreateLineSeries("MA 10", OxyColor.FromUInt32(0xCCA4C400), BasicAnalysis.CalculateMovingAverage(Ticks, 10)));
            //analysisPlotModel.Series.Add(CreateLineSeries("MA 100", OxyColor.FromUInt32(0xCC60A917), BasicAnalysis.CalculateMovingAverage(Ticks, 100)));

            //analysisPlotModel.Series.Add(CreateLineSeries("Max 10", OxyColor.FromUInt32(0xCC911A0E), BasicAnalysis.CalculateMax(Ticks, 10)));
            //analysisPlotModel.Series.Add(CreateLineSeries("Max 100", OxyColor.FromUInt32(0xCC1569CE), BasicAnalysis.CalculateMax(Ticks, 100)));

            //if (dateValues.Count > 30)
            //{
            //    var anno1 = new TextAnnotation();
            //    anno1.Text = "sdkjfhsdjkfhsd";
            //    anno1.TextPosition = DateTimeAxis.CreateDataPoint(dateValues[10].Date, dateValues[10].Value);
            //    analysisPlotModel.Annotations.Add(anno1);

            //    var anno2 = new ArrowAnnotation();
            //    anno2.Text = "bla blas bla";
            //    anno2.EndPoint = DateTimeAxis.CreateDataPoint(dateValues[30].Date, dateValues[30].Value);
            //    anno2.ArrowDirection = new ScreenVector(50, anno2.EndPoint.Y * 0.3);
            //    analysisPlotModel.Annotations.Add(anno2);
            //}

            //Plots.Add(new PlotViewModel(analysisPlotModel));

            var clenow = new SimpleClenow(Ticks);
        }
        public override bool Solve(Circuit cir, BasicAnalysis ana)
        {
            List<Node> nodos = new List<Node>();
            CurrentAnalysis = ana as ComplexPlainAnalysis;
            CurrentCircuit = cir;

            //List<Node> nodosnorton = new List<Node>();
            //List<Node> nodoscalculables = new List<Node>();
            //List<SpecialComponentInfo> especialcomponents;
            Voltages = new Dictionary<Complex32, Dictionary<string, Complex32>>();
            Currents = new Dictionary<Complex32, Dictionary<string, Complex32>>();
            WfromIndexes = new Dictionary<Tuple<int, int>, Complex32>();
            SolveInfo solveinfo = new SolveInfo();

            PreAnalizeToSolve(cir, nodos, solveinfo);


            ComplexPlainAnalysis analis = ana as ComplexPlainAnalysis;
            double w, sig, wi, wf, deltaw, deltasig, sigmamin, sigmamax;

            wi = analis.WMin;
            wf = analis.WMax;
            sigmamax = analis.SigmaMax;
            sigmamin = analis.SigmaMin;
            w = wi;
            sig = sigmamin;
            deltaw = (wf - wi) / analis.Points;
            deltasig = (sigmamax - sigmamin) / analis.Points;

            Complex32 W = Complex32.Zero;

            for (int i = 0; i <= analis.Points; i++)
            {

                for (int j = 0; j <= analis.Points; j++)
                {
                    //Calculo de tensiones de nodos
                    W = new Complex32((float)(sigmamin + j * deltasig), (float)(wi + i * deltaw));
                    ACSweepSolver.Calculate(solveinfo, W);
                    
                    //          Node    Voltage
                    Dictionary<string, Complex32> result = new Dictionary<string, Complex32>();

                    #region almacenamiento temporal
                  
                    foreach (var nodo in nodos)
                    {
                        result.Add(nodo.Name, nodo.Voltage);
                    }
                    if (!Voltages.ContainsKey(W))
                    {
                        Voltages.Add(W, result);
                        WfromIndexes.Add(new Tuple<int, int>(i, j), W);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                   // Results[i,j] = new Tuple<Complex32,Complex32>(W, 

                    #endregion

                    //calculo las corrientes:
                    CalculateCurrents(cir, W);
                    Dictionary<string, Complex32> currents = new Dictionary<string, Complex32>();
                    StorageCurrents(cir, currents);
                    Currents.Add(W, currents);

                }
            }
            cir.State = Circuit.CircuitState.Solved;

            return true;
        }
Esempio n. 10
0
        public SimpleClenow(IList <TickData> ticks)
        {
            var ma50Line  = BasicAnalysis.CalculateMovingAverage(ticks, 50);
            var ma100Line = BasicAnalysis.CalculateMovingAverage(ticks, 100);

            var max50Line = BasicAnalysis.CalculateMax(ticks, 50);
            var min50Line = BasicAnalysis.CalculateMin(ticks, 50);

            var atrLine = BasicAnalysis.CalculateAtr(ticks, 100);

            var data = (from ma50 in ma50Line
                        join ma100 in ma100Line on ma50.Date equals ma100.Date
                        join max50 in max50Line on ma50.Date equals max50.Date
                        join min50 in min50Line on ma50.Date equals min50.Date
                        join atr in atrLine on ma50.Date equals atr.Date
                        join tick in ticks on ma50.Date equals tick.Time
                        select new
            {
                Tick = tick,
                Ma50 = ma50.Value,
                Ma100 = ma100.Value,
                Max50 = max50.Value,
                Min50 = min50.Value,
                Atr = atr.Value,

                LongAllowed = ma50.Value > ma100.Value,
                ShortAllowed = ma50.Value < ma100.Value,

                BuySignal = tick.Close >= max50.Value,
                SellSignal = tick.Close <= min50.Value,
            })
                       .ToList();

            var decisions = new List <Tuple <int, Signal> >();

            for (int i = 0; i < data.Count - 1; i++)
            {
                var lastDecision     = decisions.LastOrDefault();
                var lastDecisionType = lastDecision != null ? lastDecision.Item2.DecisionType : DecisionType.StayAway;

                var currentPoint = data[i];

                var closePrice = currentPoint.Tick.Close;
                var entryPrice = data[i + 1].Tick.Open;

                if (currentPoint.BuySignal && currentPoint.LongAllowed)
                {
                    if (lastDecisionType == DecisionType.Buy)
                    {
                        continue;
                    }

                    decisions.Add(new Tuple <int, Signal>(i, new Signal(currentPoint.Tick.Time, DecisionType.Buy, entryPrice)));
                    continue;
                }

                if (currentPoint.SellSignal && currentPoint.ShortAllowed)
                {
                    if (lastDecisionType == DecisionType.Sell)
                    {
                        continue;
                    }

                    decisions.Add(new Tuple <int, Signal>(i, new Signal(currentPoint.Tick.Time, DecisionType.Sell, entryPrice)));
                    continue;
                }

                if (!currentPoint.LongAllowed && lastDecisionType == DecisionType.Buy)
                {
                    decisions.Add(new Tuple <int, Signal>(i, new Signal(currentPoint.Tick.Time, DecisionType.Close, entryPrice)));
                    continue;
                }

                if (!currentPoint.ShortAllowed && lastDecisionType == DecisionType.Sell)
                {
                    decisions.Add(new Tuple <int, Signal>(i, new Signal(currentPoint.Tick.Time, DecisionType.Close, entryPrice)));
                    continue;
                }

                if (lastDecision != null)
                {
                    //stop loss
                    var ticksRange = data
                                     .Skip(lastDecision.Item1)
                                     .Take(i - lastDecision.Item1)
                                     .ToList();

                    if (lastDecisionType == DecisionType.Buy)
                    {
                        var highestClose = ticksRange.Max(x => x.Tick.Close);
                        highestClose -= 3 * currentPoint.Atr;
                        if (closePrice < highestClose)
                        {
                            decisions.Add(new Tuple <int, Signal>(i, new Signal(currentPoint.Tick.Time, DecisionType.Close, entryPrice)));
                            continue;
                        }
                    }

                    if (lastDecisionType == DecisionType.Sell)
                    {
                        var lowestClose = ticksRange.Min(x => x.Tick.Close);
                        lowestClose += 3 * currentPoint.Atr;
                        if (closePrice > lowestClose)
                        {
                            decisions.Add(new Tuple <int, Signal>(i, new Signal(currentPoint.Tick.Time, DecisionType.Close, entryPrice)));
                            continue;
                        }
                    }
                }
            }

            var temp = decisions.Select(x => x.Item2).ToList();

            IndexLine.Clear();

            var dataAndDecisions = (from d in data
                                    join dec in decisions on d.Tick.Time equals dec.Item2.Date into joined
                                    from jn in joined.DefaultIfEmpty()
                                    select new
            {
                Tick = d.Tick,
                Decision = jn != null ? jn.Item2 : null
            })
                                   .ToList();

            Signal lastDec = null;

            for (int i = 0; i < dataAndDecisions.Count; i++)
            {
                var currentPoint  = dataAndDecisions[i];
                var previousPoint = i == 0 ? currentPoint : dataAndDecisions[i - 1];

                var lastIndexPoint = IndexLine.LastOrDefault();
                var lastIndexValue = lastIndexPoint != null ? lastIndexPoint.Value : 100;

                if (lastDec == null)
                {
                    IndexLine.Add(new DateValue {
                        Date = currentPoint.Tick.Time, Value = lastIndexValue
                    });
                }
                else
                {
                    var perf = currentPoint.Tick.Close / previousPoint.Tick.Close;
                    if (lastDec.DecisionType == DecisionType.Buy)
                    {
                        IndexLine.Add(new DateValue {
                            Date = currentPoint.Tick.Time, Value = lastIndexValue * perf
                        });
                    }

                    if (lastDec.DecisionType == DecisionType.Sell)
                    {
                        IndexLine.Add(new DateValue {
                            Date = currentPoint.Tick.Time, Value = lastIndexValue * (2 - perf)
                        });
                    }
                }

                if (currentPoint.Decision != null)
                {
                    if (currentPoint.Decision.DecisionType == DecisionType.Close)
                    {
                        lastDec = null;
                        continue;
                    }

                    lastDec = currentPoint.Decision;
                }
            }
        }
        public virtual bool Solve(Circuit cir, BasicAnalysis ana)
        {
            //int fila = 0;
            List<Node> nodos = new List<Node>();
            circuit = cir;

            if (cir.Reference == null)
            {
                foreach (var nodo in cir.Nodes.Values)
                {
                    //creo una lista de nodos sin el nodo referencia
                    if (!nodo.IsReference)
                        nodos.Add(nodo);
                } 
            }
            else
            {
                nodos.AddRange(cir.Nodes.Values);
                nodos.Remove(cir.Reference);
            }
           

            List<Node> nodosnorton = new List<Node>();
            List<Node> nortoncopia = new List<Node>();

            foreach (var nodo in nodos)
            {
                if (nodo.TypeOfNode == Node.NodeType.MultibranchCurrentNode ||
                    nodo.TypeOfNode == Node.NodeType.VoltageLinkedNode ||
                    nodo.TypeOfNode == Node.NodeType.VoltageDivideNode)
                    nodosnorton.Add(nodo);
            }

            #region Calculo de tensiones de nodos

            nortoncopia.Clear();
            foreach (var item in nodosnorton)
            {
                nortoncopia.Add(item);
            }

            Calculate(nortoncopia);
            #endregion

            //#region almacenamiento temporal


            //#endregion
            
            //calculo las corrientes:
            CalculateCurrents(cir);


            cir.State = Circuit.CircuitState.Solved;
            return true;
        }