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

说明

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

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 摘要
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.
指标
Bollinger
Bollinger Band Cloud, Heiken Ashi, Trend Follower and Parabolic SAR.
指标
E7 Correlation Dashboard.
指标
Indices
Option pricing using the BlackScholes model and the Math.Numerics packages
指标
Bollinger
ADXR, KDJ, SineWave, Bollinger Band Volatility and AEOscillator.

猜您喜欢

cBot
Break & Retest
Drawdown Guard
+2
✨Petra Oil Breakout - Session Box Precision for WTI & Brent. Up to +136% in 30 Days✨
136%
投资 回报率
4.35
盈利系数
cBot
Forex
BTCUSD
+8
RiskPilot is a clean, fast trade panel for cTrader that sizes positions by account risk % in a single click.
cBot
ATR
RSI
+5
Professional Multi-Strategy Grid Trading Bot
cBot
AI
Stocks
+1
Advanced Automated SPX Algorithmic Trading System
4
盈利系数
cBot
Signal
Bollinger
This cBot uses a combination of Heikin Ashi and Bollinger Bands strategies.
cBot
EMA
Balanced
+4
AUD CAD PHAROH TRADING BOT Back tested 6 YEARS TICK DATA
1.64
盈利系数
cBot
ATR
RSI
Hedging AI
cBot
AI Trading
High Frequency
+5
Automated cTrader trade alerts to Telegram and Discord, with real-time trade tracking, risk alerts, and daily reports.
cBot
ATR
RSI
+4
UltimateAI Trading Robot – Smart Trend & Momentum Trader for cTrader
60.1%
投资 回报率
1.37
盈利系数
cBot
Advanced forex trade panel for risk, margin, swaps, and trade control with precision tools.
cBot
AI
Forex
+2
Sophisticated GRADIENTE algorithm , performance 11% per day drawdown 4%
cBot
AI
ATR
+26
Review and User Guide: PROP Account Guardian Pro cBot 🛡️
cBot
RSI
Indices
SALE OFF!!! this innovative bot combines the precision of Fibonacci Retracement, EMA and RSI...
cBot
MACD
Forex
+5
CRT Trading_bot
100%
投资 回报率
2.13
盈利系数
cBot
ATR
Simple and Effective Trading Panel with On-Screen Statistics and Trade Management Options.
cBot
ATR
Fixed Risk %
+5
FREE backtest-only. Reproduce Pegasus Bitcoin's +170.41% in your own cTrader. Same engine, same book. No grid.
1.5
盈利系数
cBot
AI
Grid
+4
Institutional-Grade AI for Retail Traders,Trade Like a Central Bank.
1.7
盈利系数
cBot
Drawdown Guard
Daily Loss Limit
Monitor account-wide loss and stop-loss risk budgets, with optional order cancellation and post-fill closure.

价格

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