present
注册即可在首次购物时获得 $50 优惠
Trading product for E7 BBKG NumSharp Sample cBot AI, image 1
E7 BBKG NumSharp Sample
cBot
306 下载
版本 1.0, Feb 2025
Windows 版、Mac 版, Mobile, Web
Trading product for E7 BBKG NumSharp Sample cBot AI, image 2
注册日期 18/12/2024
2
销售
4.66K
免费安装

说明

应许多人的要求,我们现在正在努力提供一些机器学习代码和包的示例。

TensorFlow、PyTorch、Keras、Numpy、Pandas 以及更多 .NET 包,可在 cTrader 内使用。

我们的使命是让每个人都能更轻松地在 cTrader 中使用机器学习。

祝你狩猎愉快!

*** 此代码不进行任何交易(仅打印数据等)。它只是示例代码,展示如何使用我们的机器学习包开始创建自己的 AI 模型。

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

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("版本 1.01", DefaultValue = "版本 1.01")]
        public string Version { get; set; }

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

        [Parameter("所需柱数", DefaultValue = 50, MinValue = 1, MaxValue = 10000, Step = 1)]
        public int BarsRequired { get; set; }

        [Parameter("方法名称", DefaultValue = MethodName.DataSplitPrints)]
        public MethodName Mode { get; set; }
        public enum MethodName
        {
            DataSplitPrints,
            PandasPrints,
            NDArrayPrints
        }
        
        protected override void OnStart()
        {
            // 初始化任何指标
        }

        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($"错误: {ex.Message}");
                if (ex.InnerException != null)
                {
                    Print($"内部异常: {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 数据拆分打印
        public void DataSplitPrints()
        {
            // 重塑输入数据以匹配模型预期的输入形状
            //var inputShape = new Shape(-1, BarsRequired, 5);
            NDArray inputData = np.array<float>(GetDataSet());
            Print("输入 NDarray: " + string.Join(", ", inputData));
            
            // 重塑目标数据以匹配模型预期的目标形状
            //var targetShape = new Shape(-1, 5);
            NDArray targetData = np.array<float>(GetTargetDataSet());
            Print("目标 NDarray: " + string.Join(", ", targetData));
            
            // 将数据拆分为训练集和测试集
            int testSize = (int)(0.2 * inputData.shape[0]); // 20% 用于测试
            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 数据: " + string.Join(", ", x_train));
            Print("X_test 数据: " + string.Join(", ", x_test));
            Print("Y_train 数据: " + string.Join(", ", y_train));
            Print("Y_test 数据: " + string.Join(", ", y_test));
        }
        
        /// PandasNet 打印
        public void PandasPrints()
        {
            // 将 float[,] 转换为 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()));
            }
            
            // 创建数据框
            DataFrame inputDataFrame = new DataFrame(inputSeriesList);
            DataFrame targetDataFrame = new DataFrame(targetSeriesList);
            
            Print("输入数据框: " + inputDataFrame);
            Print("目标数据框: " + targetDataFrame);
            
            //Print("输入数据框: " + string.Join(", ", inputDataFrame));
            //Print("目标数据框: " + string.Join(", ", targetDataFrame));
        }
        
        /// 简单的 NumSharp NDArray 打印
        public void NDArrayPrints()
        {
            if (Bars.ClosePrices.Count < BarsRequired)
                return;

            try
            {
                // 调用你的输入数据 float[,]
                float[,] inputData = GetDataSet();

                // 转换为 NDArray 并重塑为 (BarsRequired, 5)
                NDArray inputNDArray = np.array(inputData);   // NumSharp
                Print("输入 NumSharp NDarray 数据 : " + string.Join(", ", inputNDArray));
                Print("输入 NumSharp NDarray 形状: " + string.Join(", ", inputNDArray.shape));
                
                int expectedLength = BarsRequired * 5;
                Print($"预期 NumSharp NDarray 长度: {expectedLength}");
                Print($"输入 NumSharp NDarray 大小: {inputNDArray.size}");

                if (inputNDArray.size != expectedLength)
                {
                    Print($"长度不匹配: 预期长度 {expectedLength}, 但得到大小 {inputNDArray.size}");
                    return;
                }
            }
            catch (Exception ex)
            {
                Print("异常: " + ex.Message);
                Print("堆栈跟踪: " + ex.StackTrace);

                Exception innerException = ex.InnerException;
                while (innerException != null)
                {
                    Print("内部异常: " + innerException.Message);
                    Print("内部异常堆栈跟踪: " + innerException.StackTrace);
                    innerException = innerException.InnerException;
                }
            }
        }
    }
}

摘要

AI summary
E7 BBKG NumSharp Sample is a cTrader robot providing sample code to demonstrate integration of machine learning libraries within the cTrader environment. It includes examples using .NET packages such as TensorFlow, PyTorch, Keras, NumSharp, and PandasNet. The robot does not execute trades but prints out processed data to illustrate how users can start building AI models for trading analysis.

Key functionalities include:
- Data extraction from market bars (open, high, low, close prices, and tick volumes) over a configurable number of bars.
- Conversion of this data into formats compatible with machine learning workflows, including NumSharp NDArrays and Pandas DataFrames.
- Methods to split data into training and testing sets, and to print these datasets for inspection.
- Three operational modes selectable via parameters: DataSplitPrints, PandasPrints, and NDArrayPrints, each demonstrating different data handling approaches.

This sample code aims to facilitate machine learning development inside cTrader by providing foundational examples of data preparation and manipulation using popular ML libraries in a .NET context.
交易概览

客户评价

0.0
评价:0
客户评价
该产品尚无评价。已经试过了?抢先告诉其他人!

讨论

常见问答

AI
cTrader Store 提供的所有产品,包括交易机器人、指标和插件,均由第三方开发者提供,仅供信息参考和技术访问之用。cTrader Store 并非经纪商,不提供投资建议、个人推荐或任何未来业绩保证。

该作者的其他作品

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

猜您喜欢

cBot
EMA
Balanced
+4
AUD CAD PHAROH TRADING BOT Back tested 6 YEARS TICK DATA
1.64
盈利系数
cBot
Forex
EURUSD
+2
Amazing Gold Quantum TRIAL DAY 15
cBot
AI
ATR
+21
A price-action-first algorithm to trade Breakout, Approach, and Return around prior High/Low levels—with Prop-style risk
cBot
Scalping
ICT Framework cBot – Advanced Trading Automation for Any Pair & Timeframe
cBot
AI
Forex
+4
Trend Following Strategy with adjustment Risk Management PLEASE ENJOY!!
10.9%
投资 回报率
3.2
盈利系数
cBot
EMA
Balanced
+2
Pharaoh Trading Bot Uno with fourteen Years intensive Back Testing on Tick Data
1.64
盈利系数
cBot
ATR
Forex
+4
Automate SL & Trailing for manual trades. Independent Buy/Sell logic. Chandelier Exit & ATR support.
cBot
Forex
EURUSD
Easy Trade, Just Plug and Play!
cBot
ATR
Simple and Effective Trading Panel with On-Screen Statistics and Trade Management Options.
cBot
NZDUSD
// AUD/NZD - 2MIN TIMEFRAME // 5 YEARS BACKTEST, PROFIT 1500 USD, DRAWDOWN ABOUT 50 USD (RISKY TRADES - NO SL)
cBot
ATR
Grid
+3
QuantumLimit - XAUUSD/BTCUSD - up to 100 000 %+ cumulative ROI
cBot
Forex
Scalping
Special H1-Version of UltimateScalper for EUR/GBP ... win rate 100% ... ROI 830%
cBot
ATR
Aggressive
+1
Agressive griding bot
136%
投资 回报率
1.38
盈利系数
cBot
ATR
Grid Recovery
+2
Modern griding bot with ATR features.
136%
投资 回报率
2.36
盈利系数
cBot
ATR
Channel
+5
GoldBreakout Pro: H1 ATR breakout for XAUUSD; long+short, SL/TP at entry, filters noise, risk-based sizing.
13.8%
投资 回报率
4.87
盈利系数
cBot
AI
ATR
+8
AI Trading that you can adjust to your own strategy, this AI will do a work for you, Adjust to suit your own strategy
cBot
Indices
DAX BOT FOR INTRADAY TRADING
cBot
AI
MACD
+5
World First AI Trading now with Fibonacci Strategy Please ENJOY!! Adjust to suit your own strategy and risk management
9%
投资 回报率
3.9
盈利系数

价格

注册日期 18/12/2024
2
销售
4.66K
免费安装