Index: /branches/sluengo/HeuristicLab.Problems.TradeRules/Evaluator/EvaluatorTradeRules.cs
===================================================================
--- /branches/sluengo/HeuristicLab.Problems.TradeRules/Evaluator/EvaluatorTradeRules.cs	(revision 9324)
+++ /branches/sluengo/HeuristicLab.Problems.TradeRules/Evaluator/EvaluatorTradeRules.cs	(revision 9325)
@@ -56,5 +56,5 @@
             
             double tradingCash = OnlineTradeRulesCalculator.Calculate(estimatedValues, problemData, problemData.TrainingIndices);
-            
+
             return tradingCash;
         }
Index: /branches/sluengo/HeuristicLab.Problems.TradeRules/HeuristicLab.Problems.TradeRules-1.0.csproj
===================================================================
--- /branches/sluengo/HeuristicLab.Problems.TradeRules/HeuristicLab.Problems.TradeRules-1.0.csproj	(revision 9324)
+++ /branches/sluengo/HeuristicLab.Problems.TradeRules/HeuristicLab.Problems.TradeRules-1.0.csproj	(revision 9325)
@@ -32,58 +32,4 @@
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Collections-3.3">
-      <HintPath>..\bin\HeuristicLab.Collections-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Common-3.3">
-      <HintPath>..\bin\HeuristicLab.Common-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Core-3.3">
-      <HintPath>..\bin\HeuristicLab.Core-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Data-3.3">
-      <HintPath>..\bin\HeuristicLab.Data-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4">
-      <HintPath>..\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Operators-3.3">
-      <HintPath>..\bin\HeuristicLab.Operators-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Operators.Programmable-3.3">
-      <HintPath>..\bin\HeuristicLab.Operators.Programmable-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Optimization-3.3">
-      <HintPath>..\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Optimizer-3.3">
-      <HintPath>..\bin\HeuristicLab.Optimizer-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Parameters-3.3">
-      <HintPath>..\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Persistence-3.3">
-      <HintPath>..\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
-      <HintPath>..\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Problems.Instances-3.3">
-      <HintPath>..\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
-    </Reference>
-    <Reference Include="HeuristicLab.Random-3.3">
-      <HintPath>..\bin\HeuristicLab.Random-3.3.dll</HintPath>
-    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
@@ -130,4 +76,56 @@
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj">
+      <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project>
+      <Name>HeuristicLab.Analysis-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
+      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
+      <Name>HeuristicLab.Collections-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj">
+      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
+      <Name>HeuristicLab.Common.Resources-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
+      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
+      <Name>HeuristicLab.Common-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
+      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
+      <Name>HeuristicLab.Core-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
+      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
+      <Name>HeuristicLab.Data-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">
+      <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project>
+      <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Operators.Programmable\3.3\HeuristicLab.Operators.Programmable-3.3.csproj">
+      <Project>{6A5F8C2D-B0C3-4B36-BC20-9B1A91EE6DB6}</Project>
+      <Name>HeuristicLab.Operators.Programmable-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
+      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
+      <Name>HeuristicLab.Operators-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
+      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
+      <Name>HeuristicLab.Optimization-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
+      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
+      <Name>HeuristicLab.Parameters-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
+      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
+      <Name>HeuristicLab.Persistence-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
+      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
+      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
+    </ProjectReference>
     <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj">
       <Project>{5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}</Project>
@@ -138,6 +136,25 @@
       <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
     </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
+      <Project>{DF87C13E-A889-46FF-8153-66DCAA8C5674}</Project>
+      <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj">
+      <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project>
+      <Name>HeuristicLab.Problems.Instances-3.3</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
+      <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
+      <Name>HeuristicLab.Random-3.3</Name>
+    </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <PropertyGroup>
+    <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
+set ProjectDir=$(ProjectDir)
+set SolutionDir=$(SolutionDir)
+set Outdir=$(Outdir)
+</PreBuildEvent>
+  </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
Index: /branches/sluengo/HeuristicLab.Problems.TradeRules/Interpreter.cs
===================================================================
--- /branches/sluengo/HeuristicLab.Problems.TradeRules/Interpreter.cs	(revision 9324)
+++ /branches/sluengo/HeuristicLab.Problems.TradeRules/Interpreter.cs	(revision 9325)
@@ -24,4 +24,5 @@
         private int initialTraining;
         private int initialTest;
+
         [ThreadStatic]
         private static Dictionary<ISymbolicExpressionTreeNode, double> signalCache;
@@ -208,7 +209,4 @@
         #endregion
 
-
-        
-
         private double Evaluate(Dataset dataset, ref int row, InterpreterState state)
         {
@@ -248,5 +246,5 @@
                     {
                         double sum = Evaluate(dataset, ref row, state);
-                        int integerValue = (int) Math.Floor(sum);
+                        int integerValue = (int)Math.Floor(sum);
                         if (integerValue > 100) integerValue = 100;
                         if (row < integerValue)
@@ -254,5 +252,5 @@
                             string variableName = dataset.GetValue(row, 3);
                             double inferiorValue = Convert.ToDouble(variableName);
-                            return inferiorValue/(row+1);
+                            return inferiorValue / (row + 1);
                         }
                         else
@@ -268,26 +266,14 @@
                     {
                         double result = Evaluate(dataset, ref row, state);
-                        for (int i = 1; i < currentInstr.nArguments; i++)
-                        {
-                            if (result > 0.0) result = Evaluate(dataset, ref row, state);
-                            else
-                            {
-                                SkipInstructions(state);
-                            }
-                        }
-                        return result > 0.0 ? 1.0 : -1.0;
+                        double result2 = Evaluate(dataset, ref row, state);
+                        double total = result + result2;
+                        return total < 2 ? -1.0 : 1.0;
                     }
                 case OpCodes.OR:
                     {
                         double result = Evaluate(dataset, ref row, state);
-                        for (int i = 1; i < currentInstr.nArguments; i++)
-                        {
-                            if (result <= 0.0) result = Evaluate(dataset, ref row, state);
-                            else
-                            {
-                                SkipInstructions(state);
-                            }
-                        }
-                        return result > 0.0 ? 1.0 : -1.0;
+                        double result2 = Evaluate(dataset, ref row, state);
+                        double total = result + result2;
+                        return total > -2 ? 1.0 : -1.0;
                     }
                 case OpCodes.NOT:
@@ -339,14 +325,14 @@
                 case OpCodes.Max:
                     {
-                        int n = (int) Evaluate(dataset, ref row, state);
+                        int n = (int)Evaluate(dataset, ref row, state);
                         double max = Double.NegativeInfinity;
-                        int i = Math.Min(n,row);
-                        while(i>=0)
+                        int i = Math.Min(n, row);
+                        while (i >= 0)
                         {
                             int position = row - i;
                             string variableName = dataset.GetValue(position, 2);
                             double intValue = Convert.ToDouble(variableName);
-                            if (intValue>max) max = intValue;
-                        i--;
+                            if (intValue > max) max = intValue;
+                            i--;
                         }
                         return max;
@@ -365,10 +351,10 @@
                             i--;
                         }
-                          return min;
+                        return min;
                     }
                 case OpCodes.Lag:
                     {
-                        int n = (int) Evaluate(dataset, ref row, state);
-                        if (n>row) return 0;
+                        int n = (int)Evaluate(dataset, ref row, state);
+                        if (n > row) return 0;
                         int position = row - n;
                         string variableName = dataset.GetValue(position, 2);
@@ -378,15 +364,8 @@
                 case OpCodes.MACD:
                     {
-                        var MACDNode = currentInstr.dynamicNode;
                         //Taking the number of the days for each EMA
                         double firstEMA = Evaluate(dataset, ref row, state);
                         double secondEMA = Evaluate(dataset, ref row, state);
                         double signal = Evaluate(dataset, ref row, state);
-
-                        //Calculating the factor for each EMA
-                        double factor = 2.0 / (firstEMA + 1.0);
-                        double factor2 = 2.0 / (secondEMA + 1.0);
-                        double factor3 = 2.0 / (signal + 1.0);
-
                         //Initiation of the variables
                         double firstElementEMA = -1000000;
@@ -394,140 +373,149 @@
                         double signalValue = -100000;
                         double macd = 0;
+                        double longitud = 0;
 
                         //Check if this MACD has previous values and retrieve them
-                        if (firstEMACache.ContainsKey(MACDNode)) firstElementEMA = firstEMACache[MACDNode];
-                        if (secondEMACache.ContainsKey(MACDNode)) secondElementEMA = secondEMACache[MACDNode];
-                        if (signalCache.ContainsKey(MACDNode)) signalValue = signalCache[MACDNode];
-
-                        //Calculate the first value in the training for the two EMAs and the signal.
-                        if (row <= initialTraining || row == initialTest)
-                        {
-                            double[] meanValues = dataset.GetDoubleValues("\"Close\"", Enumerable.Range(0, (row + 1))).ToArray();
-                            firstElementEMA = meanValues[0];
-                            secondElementEMA = meanValues[0];
-                            double max = (Math.Max(firstEMA, secondEMA) - 1);//The first macd happens when the longest EMA has its first value. We need -1 because row begin in 0.
-                            for (int i = 1; i <= row; i++)
+                        if (firstEMACache.ContainsKey(currentInstr.dynamicNode)) firstElementEMA = firstEMACache[currentInstr.dynamicNode];
+                        if (secondEMACache.ContainsKey(currentInstr.dynamicNode)) secondElementEMA = secondEMACache[currentInstr.dynamicNode];
+                        if (signalCache.ContainsKey(currentInstr.dynamicNode)) signalValue = signalCache[currentInstr.dynamicNode];
+
+                
+                            //Calculating the factor for each EMA
+                            double factor = 2.0 / (firstEMA + 1.0);
+                            double factor2 = 2.0 / (secondEMA + 1.0);
+                            double factor3 = 2.0 / (signal + 1.0);
+
+                            //Calculate the first value in the training for the two EMAs and the signal.
+                            if (row <= initialTraining || row == initialTest)
                             {
-                                firstElementEMA = meanValues[i] * factor + (1 - factor) * firstElementEMA;
-                                secondElementEMA = meanValues[i] * factor2 + (1 - factor2) * secondElementEMA;
-                                if (i == max) signalValue = firstElementEMA - secondElementEMA;//First signal equals to macd.
-                                else if (i > max)//Calculation for the next signals
+                                double [] meanValues = dataset.GetDoubleValues("\"Close\"", Enumerable.Range(0, row+1)).ToArray();
+                                firstElementEMA = meanValues[0];
+                                secondElementEMA = meanValues[0];
+                                double max = (Math.Max(firstEMA, secondEMA)-1);//The first macd happens when the longest EMA has its first value. We need -1 because row begin in 0.
+                                for (int i = 1; i < meanValues.Length; i++)
                                 {
-                                    macd = firstElementEMA - secondElementEMA;
-                                    signalValue = macd * factor3 + (1 - factor3) * signalValue;
+                                    firstElementEMA = (meanValues[i] * factor) + ((1 - factor) * firstElementEMA);
+                                    secondElementEMA = (meanValues[i] * factor2) + ((1 - factor2) * secondElementEMA);
+                                    if (i == max) signalValue = firstElementEMA - secondElementEMA;//First signal equals to macd.
+                                    else if (i > max)//Calculation for the next signals
+                                    {
+                                        macd = firstElementEMA - secondElementEMA;
+                                        signalValue = macd * factor3 + (1 - factor3) * signalValue;
+                                    }
                                 }
                             }
-                        }
-                        else  //The rest of the rows are calculating with the standard EMA formula
-                        {
-                            //Retrieve the dataset values 
-                            string variableName = dataset.GetValue(row, 2);
-                            double meanValue1 = Convert.ToDouble(variableName);
-
-                            //Calculating EMA
-                            firstElementEMA = meanValue1 * factor + (1 - factor) * firstElementEMA;
-                            secondElementEMA = meanValue1 * factor2 + (1 - factor2) * secondElementEMA;
-
-                            //Calculating signal
-                            macd = firstElementEMA - secondElementEMA;
-                            signalValue = macd * factor3 + (1 - factor3) * signalValue;
-                        }
-
-                        //Save the values for the next iteration
-                        firstEMACache[MACDNode] = firstElementEMA;
-                        secondEMACache[MACDNode] = secondElementEMA;
-                        signalCache[MACDNode] = signalValue;
-
-                        macd = firstElementEMA - secondElementEMA;
+                            else  //The rest of the rows are calculating with the standard EMA formula
+                            {
+                                //Retrieve the dataset values 
+                                string variableName = dataset.GetValue(row, 2);
+                                double meanValue1 = Convert.ToDouble(variableName);
+
+                                //Calculating EMA
+                                firstElementEMA = meanValue1 * factor + (1 - factor) * firstElementEMA;
+                                secondElementEMA = meanValue1 * factor2 + (1 - factor2) * secondElementEMA;
+
+                                //Calculating signal
+                                macd = firstElementEMA - secondElementEMA;
+                                signalValue = macd * factor3 + (1 - factor3) * signalValue;
+                            }
+                            
+                            //Save the values for the next iteration
+                            firstEMACache[currentInstr.dynamicNode] = firstElementEMA;
+                            secondEMACache[currentInstr.dynamicNode] = secondElementEMA;
+                            signalCache[currentInstr.dynamicNode] = signalValue;
+
                         return macd > signalValue ? 1.0 : -1.0;
                     }
                 case OpCodes.RSI:
-                   {
-                       
-                       //Taking the number of the days for EMA
-                       double numberOfDays = Evaluate(dataset, ref row, state);
-
-                       //Calculate the factor for the EMA
-                       double factor = 1.0 / numberOfDays;
-
-                       double positiveEMA = 0;
-                       double negativeEMA = 0;
-                       double yesterdayRSI = double.NegativeInfinity;
-                       double todayRSI = double.NegativeInfinity;
-                       double outputRSI = double.NegativeInfinity;
-                       //Retrieve EMA values
-                       if (RSIPositiveCache.ContainsKey(currentInstr.dynamicNode)) positiveEMA = RSIPositiveCache[currentInstr.dynamicNode];
-                       if (RSINegativeCache.ContainsKey(currentInstr.dynamicNode)) negativeEMA = RSINegativeCache[currentInstr.dynamicNode];
-                       if (RSICache.ContainsKey(currentInstr.dynamicNode)) yesterdayRSI = RSICache[currentInstr.dynamicNode];
-                       if (RSIOutputCache.ContainsKey(currentInstr.dynamicNode)) outputRSI = RSIOutputCache[currentInstr.dynamicNode];
-
-                       if (row == initialTraining || row == initialTest)
-                       {
-                           double[] closeValues = dataset.GetDoubleValues("\"Close\"", Enumerable.Range(0, (row + 1))).ToArray();
-                           outputRSI = -1.0;
-                           for (int i = 1; i <= row; i++)
-                           {
-                               if (numberOfDays>=i)
-                               {
-                                   if ((closeValues[i] - closeValues[i - 1]) > 0) positiveEMA = ((closeValues[i] - closeValues[i - 1])+positiveEMA);
-                                   else negativeEMA = Math.Abs(closeValues[i] - closeValues[i - 1]) + negativeEMA;
-                                   if (numberOfDays == i)
-                                   {
-                                       positiveEMA = positiveEMA/numberOfDays;
-                                       negativeEMA = negativeEMA / numberOfDays;
-                                       yesterdayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA)));
-                                   }
-                               }else{
-                                    if ((closeValues[i] - closeValues[i - 1]) > 0)
+                    {
+                        //Taking the number of the days for EMA
+                        double numberOfDays = Evaluate(dataset, ref row, state);
+
+                        double positiveEMA = 0;
+                        double negativeEMA = 0;
+                        double yesterdayRSI = double.NegativeInfinity;
+                        double todayRSI = double.NegativeInfinity;
+                        double outputRSI = double.NegativeInfinity;
+                        //Retrieve EMA values
+                        if (RSIPositiveCache.ContainsKey(currentInstr.dynamicNode)) positiveEMA = RSIPositiveCache[currentInstr.dynamicNode];
+                        if (RSINegativeCache.ContainsKey(currentInstr.dynamicNode)) negativeEMA = RSINegativeCache[currentInstr.dynamicNode];
+                        if (RSICache.ContainsKey(currentInstr.dynamicNode)) yesterdayRSI = RSICache[currentInstr.dynamicNode];
+                        if (RSIOutputCache.ContainsKey(currentInstr.dynamicNode)) outputRSI = RSIOutputCache[currentInstr.dynamicNode];
+
+        
+                            //Calculate the factor for the EMA
+                            double factor = 1.0 / numberOfDays;
+
+                            if (row == initialTraining || row == initialTest)
+                            {
+                                double[] closeValues = dataset.GetDoubleValues("\"Close\"", Enumerable.Range(0, (row + 1))).ToArray();
+                                outputRSI = -1.0;
+                                for (int i = 1; i <= row; i++)
+                                {
+                                    if (numberOfDays >= i)
                                     {
-                                        positiveEMA = (closeValues[i]-closeValues[i-1]) * factor + (1 - factor) * positiveEMA;
-                                        negativeEMA = 0 * factor + (1 - factor) * negativeEMA;
+                                        if ((closeValues[i] - closeValues[i - 1]) > 0) positiveEMA = ((closeValues[i] - closeValues[i - 1]) + positiveEMA);
+                                        else negativeEMA = Math.Abs(closeValues[i] - closeValues[i - 1]) + negativeEMA;
+                                        if (numberOfDays == i)
+                                        {
+                                            positiveEMA = positiveEMA / numberOfDays;
+                                            negativeEMA = negativeEMA / numberOfDays;
+                                            yesterdayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA)));
+                                        }
                                     }
                                     else
                                     {
-                                        positiveEMA = 0 * factor + (1 - factor) * positiveEMA;
-                                        negativeEMA = Math.Abs(closeValues[i] - closeValues[i - 1]) * factor + (1 - factor) * negativeEMA;
+                                        if ((closeValues[i] - closeValues[i - 1]) > 0)
+                                        {
+                                            positiveEMA = (closeValues[i] - closeValues[i - 1]) * factor + (1 - factor) * positiveEMA;
+                                            negativeEMA = 0 * factor + (1 - factor) * negativeEMA;
+                                        }
+                                        else
+                                        {
+                                            positiveEMA = 0 * factor + (1 - factor) * positiveEMA;
+                                            negativeEMA = Math.Abs(closeValues[i] - closeValues[i - 1]) * factor + (1 - factor) * negativeEMA;
+                                        }
+
+                                        todayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA)));
+
+                                        if ((yesterdayRSI < 30) && (todayRSI > 30)) outputRSI = 1.0;
+                                        else if ((yesterdayRSI > 70) && (todayRSI < 70)) outputRSI = -1.0;
+                                        yesterdayRSI = todayRSI;
                                     }
-                                   
-                                    todayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA)));
-
-                                    if ((yesterdayRSI < 30) && (todayRSI > 30)) outputRSI = 1.0;
-                                   else if ((yesterdayRSI > 70) && (todayRSI < 70)) outputRSI = -1.0;
-                                   yesterdayRSI = todayRSI;
-                               }
-                           }
-                       }
-                       else
-                       {
-                           string todayCloseString = dataset.GetValue(row, 2);
-                           string yesterdayCloseString = dataset.GetValue((row - 1), 2);
-                           double todayClose = Convert.ToDouble(todayCloseString);
-                           double yesterdayClose = Convert.ToDouble(yesterdayCloseString);
-
-                           //Calculating EMA
-                           if ((todayClose - yesterdayClose) > 0)
-                           {
-                               positiveEMA = (todayClose-yesterdayClose) * factor + (1 - factor) * positiveEMA;
-                               negativeEMA = 0 * factor + (1 - factor) * negativeEMA;
-                           }
-                           else
-                           {
-                               positiveEMA = 0 * factor + (1 - factor) * positiveEMA;
-                               negativeEMA = Math.Abs(todayClose - yesterdayClose) * factor + (1 - factor) * negativeEMA;
-                           }
-                           todayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA)));
-                           if ((yesterdayRSI < 30) && (todayRSI > 30)) outputRSI = 1.0;
-                           else if ((yesterdayRSI > 70) && (todayRSI < 70)) outputRSI = -1.0;
-                       }
-                       
-                       //Save positive and negative EMA for the next iteration
-                       RSIPositiveCache[currentInstr.dynamicNode] = positiveEMA;
-                       RSINegativeCache[currentInstr.dynamicNode] = negativeEMA;
-                       RSICache[currentInstr.dynamicNode] = todayRSI;
-                       RSIOutputCache[currentInstr.dynamicNode] = outputRSI;   
-                       
-                       return outputRSI;
-                    }
-                
+                                }
+                            }
+                            else
+                            {
+                                string todayCloseString = dataset.GetValue(row, 2);
+                                string yesterdayCloseString = dataset.GetValue((row - 1), 2);
+                                double todayClose = Convert.ToDouble(todayCloseString);
+                                double yesterdayClose = Convert.ToDouble(yesterdayCloseString);
+
+                                //Calculating EMA
+                                if ((todayClose - yesterdayClose) > 0)
+                                {
+                                    positiveEMA = (todayClose - yesterdayClose) * factor + (1 - factor) * positiveEMA;
+                                    negativeEMA = 0 * factor + (1 - factor) * negativeEMA;
+                                }
+                                else
+                                {
+                                    positiveEMA = 0 * factor + (1 - factor) * positiveEMA;
+                                    negativeEMA = Math.Abs(todayClose - yesterdayClose) * factor + (1 - factor) * negativeEMA;
+                                }
+                                todayRSI = 100 - (100 / (1 + (positiveEMA / negativeEMA)));
+                                if ((yesterdayRSI < 30) && (todayRSI > 30)) outputRSI = 1.0;
+                                else if ((yesterdayRSI > 70) && (todayRSI < 70)) outputRSI = -1.0;
+                            }
+
+                            //Save positive and negative EMA for the next iteration
+                            RSIPositiveCache[currentInstr.dynamicNode] = positiveEMA;
+                            RSINegativeCache[currentInstr.dynamicNode] = negativeEMA;
+                            RSICache[currentInstr.dynamicNode] = todayRSI;
+                            RSIOutputCache[currentInstr.dynamicNode] = outputRSI;
+                           
+                        
+                        return outputRSI;
+                    }
+
                 default: throw new NotSupportedException();
             }
@@ -598,5 +586,5 @@
         {
             if (CheckExpressionsWithIntervalArithmetic.Value)
-            throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
+                throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
             EvaluatedSolutions.Value++; // increment the evaluated solutions counter
             var compiler = new SymbolicExpressionTreeCompiler();
@@ -614,5 +602,4 @@
             }
 
-
             if (signalCache == null) signalCache = new Dictionary<ISymbolicExpressionTreeNode, double>();
             if (firstEMACache == null) firstEMACache = new Dictionary<ISymbolicExpressionTreeNode, double>();
@@ -622,18 +609,18 @@
             if (RSICache == null) RSICache = new Dictionary<ISymbolicExpressionTreeNode, double>();
             if (RSIOutputCache == null) RSIOutputCache = new Dictionary<ISymbolicExpressionTreeNode, double>();
-                                 
-                                       
-                                        var state = new InterpreterState(code, necessaryArgStackSize);
-                                        //Evaluate each row of the datase
-                                        foreach (var rowEnum in rows)
-                                        {
-                                            int row = rowEnum;
-                                            state.Reset();
-                                            if (row < initialTraining) yield return -1;
-                                            else yield return Evaluate(dataset, ref row, state);
-                                        }
-                }
-        }
-
+
+
+            var state = new InterpreterState(code, necessaryArgStackSize);
+            //Evaluate each row of the datase
+            foreach (var rowEnum in rows)
+            {
+                int row = rowEnum;
+                state.Reset();
+                if (row < initialTraining) yield return -1;
+                else yield return Evaluate(dataset, ref row, state);
+            }
+        }
     }
 
+}
+
Index: /branches/sluengo/HeuristicLab.Problems.TradeRules/Symbols/MACDTreeNode.cs
===================================================================
--- /branches/sluengo/HeuristicLab.Problems.TradeRules/Symbols/MACDTreeNode.cs	(revision 9324)
+++ /branches/sluengo/HeuristicLab.Problems.TradeRules/Symbols/MACDTreeNode.cs	(revision 9325)
@@ -6,4 +6,5 @@
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
 using HeuristicLab.Common;
+using HeuristicLab.Core;
 
 namespace HeuristicLab.Problems.TradeRules.Symbols
@@ -11,7 +12,17 @@
     public sealed class  MACDTreeNode : SymbolicExpressionTreeNode
     {
-      public new MACD Symbol {
-      get { return (MACD)base.Symbol;}
-    }
+
+        public new MACD Symbol
+        {
+            get { return (MACD)base.Symbol; }
+        }
+        
+        [Storable]
+        private double idMACD;
+        public double ID
+        {
+            get {return idMACD; }
+            set { idMACD = value; }
+        }
 
     [StorableConstructor]
@@ -20,5 +31,5 @@
     private MACDTreeNode(MACDTreeNode original, Cloner cloner)
       : base(original, cloner) {
-      
+          idMACD = original.idMACD;
     }
 
@@ -31,4 +42,11 @@
     }
 
+    public override void ResetLocalParameters(IRandom random)
+    {
+        base.ResetLocalParameters(random);
+
+        idMACD = random.NextDouble();
+    }
+
     public override IDeepCloneable Clone(Cloner cloner) {
       return new MACDTreeNode(this, cloner);
