Logótipo de "E7 BBKG NumSharp Sample"
cBot
199 transferências
Versão 1.0, Feb 2025
Windows, Mac, Mobile, Web
Imagem carregada de "E7 BBKG NumSharp Sample"
Desde 18/12/2024
2
Vendas
3.86K
Instalações gratuitas

As requested by many of you, we are now working hard to provide examples of some of our machine learning code and packages.

TensorFlow, PyTorch, Keras, Numpy, Pandas and many more .NET packages to get going inside of cTrader.

Our mission is to make Machine Learning inside cTrader easier for everyone.

Happy hunting!

*** This code does not trade anything (it only prints out data etc). It is simply sample code of how you can start creating your own AI models using our Machine Learning packages.

.......................................................

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

using NumSharp;
using np = NumSharp.np;
using Shape = NumSharp.Shape;

using PandasNet;
using static PandasNet.PandasApi;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class E7BBKGNumSharpSample : Robot
    {
        [Parameter("Version 1.01", DefaultValue = "Version 1.01")]
        public string Version { get; set; }

        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Bars Required", DefaultValue = 50, MinValue = 1, MaxValue = 10000, Step = 1)]
        public int BarsRequired { get; set; }

        [Parameter("Method Name", DefaultValue = MethodName.DataSplitPrints)]
        public MethodName Mode { get; set; }
        public enum MethodName
        {
            DataSplitPrints,
            PandasPrints,
            NDArrayPrints
        }
        
        protected override void OnStart()
        {
            // Initialize any indicators
        }

        protected override void OnBar()
        {
            try
            {
                if (Mode == MethodName.DataSplitPrints)
                {
                    DataSplitPrints();
                }
                else if (Mode == MethodName.PandasPrints)
                {
                    PandasPrints();
                }
                else if (Mode == MethodName.NDArrayPrints)
                {
                    NDArrayPrints();
                }
            }
            catch (Exception ex)
            {
                Print($"Error: {ex.Message}");
                if (ex.InnerException != null)
                {
                    Print($"Inner Exception: {ex.InnerException.Message}");
                    throw;
                }
            }
        }

        private float[,] GetDataSet()
        {
            int startBar = Bars.ClosePrices.Count - BarsRequired;
            float[,] inputSignals = new float[BarsRequired, 5];

            for (int i = 0; i < BarsRequired; i++)
            {
                int barIndex = startBar + i;
                inputSignals[i, 0] = (float)Bars.OpenPrices[barIndex];
                inputSignals[i, 1] = (float)Bars.HighPrices[barIndex];
                inputSignals[i, 2] = (float)Bars.LowPrices[barIndex];
                inputSignals[i, 3] = (float)Bars.ClosePrices[barIndex];
                inputSignals[i, 4] = (float)Bars.TickVolumes[barIndex];
            }
            return inputSignals;
        }
        
        private float[,] GetTargetDataSet()
        {
            int startBar = Bars.ClosePrices.Count - BarsRequired;
            float[,] inputSignals = new float[BarsRequired, 5];

            for (int i = 0; i < BarsRequired; i++)
            {
                int barIndex = startBar + i;
                inputSignals[i, 0] = (float)Bars.OpenPrices[barIndex];
                inputSignals[i, 1] = (float)Bars.HighPrices[barIndex];
                inputSignals[i, 2] = (float)Bars.LowPrices[barIndex];
                inputSignals[i, 3] = (float)Bars.ClosePrices[barIndex];
                inputSignals[i, 4] = (float)Bars.TickVolumes[barIndex];
            }
            return inputSignals;
        }
        
        /// NumSharp Data Split Prints
        public void DataSplitPrints()
        {
            // Reshape input data to match the model's expected input shape
            //var inputShape = new Shape(-1, BarsRequired, 5);
            NDArray inputData = np.array<float>(GetDataSet());
            Print("Input NDarray: " + string.Join(", ", inputData));
            
            // Reshape target data to match the target shape expected by the model
            //var targetShape = new Shape(-1, 5);
            NDArray targetData = np.array<float>(GetTargetDataSet());
            Print("Target NDarray: " + string.Join(", ", targetData));
            
            // Split data into training and test sets
            int testSize = (int)(0.2 * inputData.shape[0]); // 20% for testing
            var (x_train, x_test) = (inputData[$":{inputData.shape[0] - testSize}"], inputData[$"{inputData.shape[0] - testSize}:"]);
            var (y_train, y_test) = (targetData[$":{targetData.shape[0] - testSize}"], targetData[$"{targetData.shape[0] - testSize}:"]);
            
            Print("X_train data: " + string.Join(", ", x_train));
            Print("X_test data: " + string.Join(", ", x_test));
            Print("Y_train data: " + string.Join(", ", y_train));
            Print("Y_test data: " + string.Join(", ", y_test));
        }
        
        /// PandasNet Prints
        public void PandasPrints()
        {
            // Convert float[,] to List<Series>
            var inputData = GetDataSet();
            var targetData = GetTargetDataSet();
            
            var inputSeriesList = new List<Series>();
            var targetSeriesList = new List<Series>();
            
            for (int col = 0; col < inputData.GetLength(1); col++)
            {
                List<float> columnData = new List<float>();
                for (int row = 0; row < inputData.GetLength(0); row++)
                {
                    columnData.Add(inputData[row, col]);
                }
                inputSeriesList.Add(new Series(columnData.ToArray()));
            }
            
            for (int col = 0; col < targetData.GetLength(1); col++)
            {
                List<float> columnData = new List<float>();
                for (int row = 0; row < targetData.GetLength(0); row++)
                {
                    columnData.Add(targetData[row, col]);
                }
                targetSeriesList.Add(new Series(columnData.ToArray()));
            }
            
            // Create DataFrames
            DataFrame inputDataFrame = new DataFrame(inputSeriesList);
            DataFrame targetDataFrame = new DataFrame(targetSeriesList);
            
            Print("Input DataFrame: " + inputDataFrame);
            Print("Target DataFrame: " + targetDataFrame);
            
            //Print("Input DataFrame: " + string.Join(", ", inputDataFrame));
            //Print("Target DataFrame: " + string.Join(", ", targetDataFrame));
        }
        
        /// Simple NumSharp NDArrays Prints
        public void NDArrayPrints()
        {
            if (Bars.ClosePrices.Count < BarsRequired)
                return;

            try
            {
                // Calling your Input Data float[,]
                float[,] inputData = GetDataSet();

                // Convert to NDArray and reshape to (BarsRequired, 5)
                NDArray inputNDArray = np.array(inputData);   // NumSharp
                Print("Input NumSharp NDarray Data : " + string.Join(", ", inputNDArray));
                Print("Input NumSharp NDarray Shape: " + string.Join(", ", inputNDArray.shape));
                
                int expectedLength = BarsRequired * 5;
                Print($"Expected NumSharp NDarray Length: {expectedLength}");
                Print($"Input NumSharp NDarray Size: {inputNDArray.size}");

                if (inputNDArray.size != expectedLength)
                {
                    Print($"Length MisMatch: Expected Length {expectedLength}, but got Size {inputNDArray.size}");
                    return;
                }
            }
            catch (Exception ex)
            {
                Print("Exception: " + ex.Message);
                Print("StackTrace: " + ex.StackTrace);

                Exception innerException = ex.InnerException;
                while (innerException != null)
                {
                    Print("Inner Exception: " + innerException.Message);
                    Print("Inner Exception StackTrace: " + innerException.StackTrace);
                    innerException = innerException.InnerException;
                }
            }
        }
    }
}

Perfil de negociação
0.0
Avaliações: 0
Avaliações de clientes
Ainda não há avaliações para este produto. Já o experimentou? Seja o primeiro a contar a outras pessoas!
AI
Os produtos disponíveis através da cTrader Store, incluindo bots de negociação, indicadores e plugins, são fornecidos por programadores terceiros e são disponibilizados apenas para fins informativos e de acesso técnico. A cTrader Store não é um corretor e não fornece aconselhamento em matéria de investimento, recomendações pessoais ou qualquer garantia de desempenho no futuro.

Mais deste autor

Indicador
E7 Volume Profile, more modern look and feel.
Indicador
Prop
E7 BBKG indicator with 80% plus accuracy used to show both, possible reversal and trend.
Indicador
Polynomial Regression Channel which also reflects the volatility of the underlying asset.
Indicador
E7 Harmonic Structures Basic.
Indicador
E7 Correlation Dashboard.
Indicador
Bollinger
Bollinger Band Cloud, Heiken Ashi, Trend Follower and Parabolic SAR.
Indicador
Indices
Option pricing using the BlackScholes model and the Math.Numerics packages
Indicador
Bollinger
ADXR, KDJ, SineWave, Bollinger Band Volatility and AEOscillator.

Também poderá gostar de

cBot
Forex
Indices
+3
FutureTrader is a trendline-based trading bot designed for trending markets. Draw colored trendlines on your chart (blue
cBot
ATR
RSI
+5
Shift from “Price Chasing” to “Price Trapping” using Limit Orders and a Volatility-Based Calculation System
cBot
Forex
Martingale
GBP_PRO FREE TRIAL TILL 16/04/2025 GBP/USD 1MIN.
cBot
AUTOEXIT BOT: SL de Seguridad y Trailing Stop para Trades Manuales, diseñado para gestionar automática de salidas.
cBot
Signal
Create your own custom candlestick patterns with AlgoBuilderX, or choose from a variety of predefined pattern!
cBot
ATR
RSI
+11
proactive swing detection and entry with multiple trade filters..high stable returns,minimal drawdowns
cBot
AI
ATR
+27
Overnight trades? Pc needs shut down? Sleep disruption from alerts? Could have avoided Loss with BE Partial Monitored ?
cBot
Forex
EURUSD
+3
This Version only supports Demo accounts or Backtest Please Download the pro version at https://ctrader.com/products/312
cBot
ATR
Signal
+1
✨ N.B.: Results with an initial invested capital of 100 euros.📈
cBot
AI
ATR
+10
Super USD Trio AI is a smart, multi-symbol Forex trading robot tailored for EURUSD, USDJPY, and GBPUSD.
cBot
US30 Market open; a bracket system during the opening, waiting for the first move with high volatility.
cBot
Grid
Forex
+4
SafeGridBot: simple grid bot with fixed TP/SL and position limit, ignores trend, risky in strong trends.
cBot
ATR
Forex
+2
Zscore Momentum: smart cBot that adapts strategy and risk to market conditions using Z-Score, ATR, and trend.
cBot
Forex
XAUUSD
+2
Trading System che apre le operazioni al cross di una SMA Trading System that opens trades when an SMA crosses.
cBot
Forex
Crypto
+4
Volatility Sniper Breakout Bot (Beta) – Intelligent Breakout Trading for Volatile Markets
cBot
Forex
Most Profitable cAlgo cBot cTrader 2024 for GBPUSD Reach 443450% Net Profit
Desde 18/12/2024
2
Vendas
3.86K
Instalações gratuitas