Exemple #1
0
        public override void OnBar_UserCode(Simulation.Shared.IBarContext context)
        {
            IBar bar          = context.Bar;
            var  seriesValues = context.SeriesValues;
            IInstantValue <double> indicator0 = seriesValues["INDICATOR_0"];
            IInstantValue <double> indicator1 = seriesValues["INDICATOR_1"];
            IInstantValue <double> indicator2 = seriesValues["INDICATOR_2"];
            IInstantValue <double> indicator3 = seriesValues["INDICATOR_3"];
            var values = new double[] {
                indicator0.NormalizedValue,
                indicator1.NormalizedValue,
                indicator2.NormalizedValue,
                indicator3.NormalizedValue,
            };

            double[] output = NeuralNetwork.ComputeOutputs(values);
            Console.WriteLine("{0}, {1}, {2}, {3} => {4}, {5}, {6}",
                              indicator0.NormalizedValue,
                              indicator1.NormalizedValue,
                              indicator2.NormalizedValue,
                              indicator3.NormalizedValue,
                              output[0], output[1], output[2]);
            int       maxIndex  = NeuralNetwork.MaxIndex(output);
            Operation operation = (Operation)maxIndex;
            decimal   intensity = (decimal)output[maxIndex];

            TryToOpenLongPositions(bar, operation, intensity);
            TryToOpenShortPositions(bar, operation, intensity);
            ManageSideways(bar, operation, intensity);
        }
Exemple #2
0
 private void TryToOpenShortPositions(IBar bar, IInstantValue <double> smallEma, IInstantValue <double> bigEma)
 {
     // down trend detected
     if (bigEma.Value > (smallEma.Value + _threshold))
     {
         // is trend change
         if (_trend != Trend.Down)
         {
             _trend = Trend.Down;
             if (_shortEnabled && ShortPositions.Count == 0)
             {
                 CreatePosition(PositionSide.Short, bar.DateTime, bar.Close, 1);
             }
         }
     }
 }
Exemple #3
0
 private void TryToOpenLongPositions(IBar bar, IInstantValue <double> smallEma, IInstantValue <double> bigEma)
 {
     // up trend detected
     if (smallEma.Value > (bigEma.Value + _threshold))
     {
         // is trend change
         if (_trend != Trend.Up)
         {
             _trend = Trend.Up;
             if (_longEnabled && LongPositions.Count == 0)
             {
                 CreatePosition(PositionSide.Long, bar.DateTime, bar.Close, 1);
             }
         }
     }
 }