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

说明

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

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.
指标
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
RSI
Grid
+5
This production version of Dragon Money Forex Pro
cBot
ATR
EMA
+5
We transform trading concepts into fully automated cTrader systems with clearly defined entry, exit, risk-management
1.21
盈利系数
cBot
Channel
SL Manager
+5
cTrader to Discord trade notifier with custom message formats, risk alerts, and an on-chart dashboard.
cBot
ATR
RSI
+5
📊 EMA CROSS COMPLETE BOT - Professional Trading System
2.1
盈利系数
cBot
TP Manager
Fixed Risk %
+5
Professional risk and trade management assistant for precise position sizing, execution and automated trade management.
18.2%
投资 回报率
35
盈利系数
cBot
AI
ATR
+27
TrustGuard - Simple, Smart Account Protection for cTrader
cBot
Prop
Forex
+5
**Quantum King : – Precision Trading for Forex{GBPUSD, EURUSD}, Gold & Oil** The **Quantum King**
cBot
Grid
XAUUSD
+2
🔥 Grid Classic – A Simple Yet Powerful Grid System
cBot
Prop
Forex
+3
FTMO Guardian. Auto-calculates lots by Risk $. Rejects errors & trades w/o SL. Protect your Prop Account
cBot
RSI
Fixed Lot
+2
Donchian breakout trend follower for XAUUSD H1, with RSI divergence entry filters and a 5% daily loss limit.
1.12
盈利系数
cBot
RSI
Forex
+3
Wealthcraft Auto Profit is a smart trading robot with Auto Stop-Loss, Trailing Stop, and maximum profit management
cBot
Volume
Fibonacci
+5
Professional scanning and analysis with automatic target and stop.
5
盈利系数
cBot
Grid
XAUUSD
+3
Demo version of https://ctrader.com/products/315
cBot
NZDUSD
// AUD/NZD - 2MIN TIMEFRAME // 5 YEARS BACKTEST, PROFIT 1500 USD, DRAWDOWN ABOUT 50 USD (RISKY TRADES - NO SL)
cBot
Forex
cTrader Profit Defender: Safeguard Your Gains with Advanced Trailing Stops.
cBot
ATR
EMA
+5
Incorporate EMA, RSI, and ATR to detect strong trends and execute precise entries
cBot
SL Manager
Break Even
+4
FRACTAL STOP LOSS BOT AND RISK MANAGER

价格

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