E7 BBKG NumSharp Sample
cBot
257 下载
版本 1.0, Feb 2025
Windows 版、Mac 版, Mobile, Web
Trading product for E7 BBKG NumSharp Sample cBot AI, image 2
注册日期 18/12/2024
2
销售
4.23K
免费安装

说明

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

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
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
盈利系数
cBot
CHOCH
SL Manager
+1
Trade with clarity. Protect your capital. Let Risk Manager enforce the rules.
cBot
Prop
Forex
+5
**Quantum King : – Precision Trading for Forex{GBPUSD, EURUSD}, Gold & Oil** The **Quantum King**
cBot
ATR
RSI
+6
Trend-following with deep pullbacks and advanced risk/position management.
cBot
Break Even
Risk/Reward
+5
Automatic position sizing, smart pending orders, loss limits, and one-click trade execution for cTrader.
cBot
Forex
Crypto
+5
Smart position sizing, visual SL/TP lines, risk-based lot calculation, RR display, margin & lot limits, and hotkey trade
cBot
SMC
Forex
+11
💎 ICT Silver Bullet Strategy cBot — liquidity sweep & breakout algorithm with risk control.
cBot
ATR
EMA
+5
Smart Trading Bot with Rich Management Tools for FOREX PAIRS, NASDAQ, GOLD, OIL
14.4%
投资 回报率
1.38
盈利系数
cBot
RSI
This day trading strategy uses RSI and ADX with 4 TP levels, break-even, and customizable position management.
cBot
ATR
EMA
+5
Momentum driven, Compounding. Volatility adaptive EMA BOLLINGER ATR base Strategy
93.4%
投资 回报率
1.31
盈利系数
cBot
RSI
Forex
+13
A robust trend-following cBot
cBot
AI
SMC
+18
RISK SHIELD VERSION 2.0 - Smart Risk Manager for cTrader
cBot
ADX
ATR
+5
Analyze quarterly cycles and weekly seasonality patterns across multiple instruments with historical bias data
cBot
Fibonacci
Fixed Lot
+5
Trading dashboard for fast order execution, position management, risk controls and automatic Fibonacci levels.
1.52
盈利系数
cBot
Prop
Forex
+11
Manage trades visually! Secure profits with Auto Partials & Trailing Shield. Works on all cTrader markets.
35.2%
投资 回报率
4
盈利系数
cBot
AI
Forex
+2
Sophisticated GRADIENTE algorithm , performance 11% per day drawdown 4%
cBot
Prop Firm Fit
Stop Loss (SL) Manager
+1
HTS Strategy Tester - Advanced Multi-Timeframe Trend & Pullback Trading System H1/m1 & H4/m5 WWS 33/144 Start from 100$
90.1%
投资 回报率
2.92
盈利系数

价格

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