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

说明

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

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
ATR
Prop
+5
Low-frequency XAUUSD trend cBot with adaptive risk, drawdown controls and restart recovery.
2.49
盈利系数
cBot
ATR
EMA
+2
🌞 Smart Anchor Grid Engine for XAUUSD up to +230% in 30 Days🌞
218.1%
投资 回报率
27
盈利系数
cBot
Forex
Stocks
+1
The full version includes access to all features and customization options. It is designed for users who require advance
cBot
Forex
Indices
Trading robot designed to trade the S&P 500 index (or any other instrument) based on the concept of gap closure. 📉📈
cBot
SL Manager
TP Manager
+2
Risk Control App that calculates the lot size according to the risk and automatically places Stop Loss and Take Profit
cBot
Break Even
Risk/Reward
+3
Plan gold trades with basket risk sizing, up to three targets, breakeven and trailing protection.
cBot
AI
Grid
+4
AI Trading & Adviser with ChatGPT, Gemini, DeepSeek, Claude
9.8%
投资 回报率
1
盈利系数
cBot
ATR
Forex
+2
Auto-Breakeven Bot w/ ATR & dual triggers. Works 100% with Risk Reward Guardian. Was Free for early users now -80%
cBot
Prop
Forex
+6
PropFirm Forex trader
cBot
Forex
BTCUSD
+13
Automatically manages Stop Loss and Take Profit using Support & Resistance levels, with intelligent trailing stop protec
cBot
Perfectly optimized to trade XAUUSD. Win rate of about 85 to 90%.
cBot
Prop
Forex
+4
cBot designed to assist traders in managing position risk effectively.
cBot
Forex
BTCUSD
+11
BoletaProfit - Advanced Order Ticket full version for cTrader
cBot
Volume
Balanced
+5
An automated utility featuring global drawdown control, basket trailing profit tracking, and custom session filters.
16.4%
投资 回报率
1.55
盈利系数
cBot
ATR
RSI
+4
UltimateAI Trading Robot – Smart Trend & Momentum Trader for cTrader
60.1%
投资 回报率
1.37
盈利系数
cBot
SL Manager
Break Even
+4
FRACTAL STOP LOSS BOT AND RISK MANAGER
cBot
Fixed Lot
TP Manager
+5
Automatically copies trading signals from your channels or groups straight to your cTrader account.
cBot
SL Manager
Trailing Stop
+2
Smart trade management, automatically protects positions, progressively locks in profits as trades move in your favor.

价格

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