Logo "E7 BBKG NumSharp Sample"
cBot
229 lượt tải
Phiên bản 1.0, Feb 2025
Windows, Mac, Mobile, Web
Ảnh "E7 BBKG NumSharp Sample" được tải lên
Kể từ 18/12/2024
2
Lượt bán
4.1K
Cài đặt miễn phí

Theo yêu cầu của nhiều bạn, chúng tôi hiện đang làm việc chăm chỉ để cung cấp các ví dụ về một số mã và gói học máy của chúng tôi.

TensorFlow, PyTorch, Keras, Numpy, Pandas và nhiều gói .NET khác để bắt đầu bên trong cTrader.

Sứ mệnh của chúng tôi là làm cho Machine Learning trong cTrader trở nên dễ dàng hơn cho mọi người.

Chúc bạn săn tìm vui vẻ!

*** Mã này không giao dịch gì cả (nó chỉ in ra dữ liệu, v.v.). Đây chỉ là mã mẫu về cách bạn có thể bắt đầu tạo các mô hình AI của riêng mình bằng cách sử dụng các gói Machine Learning của chúng tôi.

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

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("Phiên bản 1.01", DefaultValue = "Version 1.01")]
        public string Version { get; set; }

        [Parameter("Nguồn")]
        public DataSeries Source { get; set; }

        [Parameter("Số lượng Bars cần thiết", DefaultValue = 50, MinValue = 1, MaxValue = 10000, Step = 1)]
        public int BarsRequired { get; set; }

        [Parameter("Tên phương pháp", DefaultValue = MethodName.DataSplitPrints)]
        public MethodName Mode { get; set; }
        public enum MethodName
        {
            DataSplitPrints,
            PandasPrints,
            NDArrayPrints
        }
        
        protected override void OnStart()
        {
            // Khởi tạo bất kỳ chỉ báo nào
        }

        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($"Lỗi: {ex.Message}");
                if (ex.InnerException != null)
                {
                    Print($"Lỗi bên trong: {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;
        }
        
        /// In dữ liệu NumSharp Data Split
        public void DataSplitPrints()
        {
            // Định dạng lại dữ liệu đầu vào để phù hợp với hình dạng đầu vào mong đợi của mô hình
            //var inputShape = new Shape(-1, BarsRequired, 5);
            NDArray inputData = np.array<float>(GetDataSet());
            Print("NDarray đầu vào: " + string.Join(", ", inputData));
            
            // Định dạng lại dữ liệu mục tiêu để phù hợp với hình dạng mục tiêu mong đợi của mô hình
            //var targetShape = new Shape(-1, 5);
            NDArray targetData = np.array<float>(GetTargetDataSet());
            Print("NDarray mục tiêu: " + string.Join(", ", targetData));
            
            // Chia dữ liệu thành tập huấn luyện và kiểm tra
            int testSize = (int)(0.2 * inputData.shape[0]); // 20% cho kiểm tra
            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("Dữ liệu X_train: " + string.Join(", ", x_train));
            Print("Dữ liệu X_test: " + string.Join(", ", x_test));
            Print("Dữ liệu Y_train: " + string.Join(", ", y_train));
            Print("Dữ liệu Y_test: " + string.Join(", ", y_test));
        }
        
        /// In dữ liệu PandasNet
        public void PandasPrints()
        {
            // Chuyển đổi float[,] thành 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()));
            }
            
            // Tạo DataFrames
            DataFrame inputDataFrame = new DataFrame(inputSeriesList);
            DataFrame targetDataFrame = new DataFrame(targetSeriesList);
            
            Print("DataFrame đầu vào: " + inputDataFrame);
            Print("DataFrame mục tiêu: " + targetDataFrame);
            
            //Print("Input DataFrame: " + string.Join(", ", inputDataFrame));
            //Print("Target DataFrame: " + string.Join(", ", targetDataFrame));
        }
        
        /// In dữ liệu NumSharp NDArray đơn giản
        public void NDArrayPrints()
        {
            if (Bars.ClosePrices.Count < BarsRequired)
                return;

            try
            {
                // Gọi dữ liệu đầu vào float[,]
                float[,] inputData = GetDataSet();

                // Chuyển đổi sang NDArray và định dạng lại thành (BarsRequired, 5)
                NDArray inputNDArray = np.array(inputData);   // NumSharp
                Print("Dữ liệu NumSharp NDarray đầu vào : " + string.Join(", ", inputNDArray));
                Print("Hình dạng NumSharp NDarray đầu vào: " + string.Join(", ", inputNDArray.shape));
                
                int expectedLength = BarsRequired * 5;
                Print($"Độ dài NumSharp NDarray mong đợi: {expectedLength}");
                Print($"Kích thước NumSharp NDarray đầu vào: {inputNDArray.size}");

                if (inputNDArray.size != expectedLength)
                {
                    Print($"Không khớp độ dài: Độ dài mong đợi {expectedLength}, nhưng nhận được kích thước {inputNDArray.size}");
                    return;
                }
            }
            catch (Exception ex)
            {
                Print("Ngoại lệ: " + ex.Message);
                Print("Dấu vết ngăn xếp: " + ex.StackTrace);

                Exception innerException = ex.InnerException;
                while (innerException != null)
                {
                    Print("Ngoại lệ bên trong: " + innerException.Message);
                    Print("Dấu vết ngăn xếp ngoại lệ bên trong: " + innerException.StackTrace);
                    innerException = innerException.InnerException;
                }
            }
        }
    }
}

Hồ sơ giao dịch
0.0
Đánh giá: 0
Đánh giá của khách hàng
Sản phẩm này chưa có đánh giá nào. Bạn đã dùng thử chưa? Hãy là người đầu tiên chia sẻ với mọi người!
AI
Các sản phẩm có sẵn trên cTrader Store, bao gồm bot giao dịch, chỉ báo và plugin, được cung cấp bởi các nhà phát triển bên thứ ba và chỉ nhằm mục đích cung cấp thông tin và tiếp cận kỹ thuật. cTrader Store không phải là nhà môi giới và không cung cấp lời khuyên đầu tư, khuyến nghị cá nhân hay bất kỳ đảm bảo nào về hiệu suất trong tương lai.

Sản phẩm khác của tác giả này

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

Bạn cũng có thể thích

cBot
CHOCH
SL Manager
+1
Trade with clarity. Protect your capital. Let Risk Manager enforce the rules.
0%
Mức sụt giảm tối đa
cBot
Key Levels
SL Manager
+4
RISK REWARD VISUALIZER Part of the MACRO ZERO Suite Visualize your active positions, pending orders, and cl
cBot
Prop
Forex
+3
Trade XAUUSD at lightning speed using Stream Deck. One-tap execution for entries, partial closes, break-even, TP & SL.
100%
ROI
2
Hệ số lợi nhuận
5%
Mức sụt giảm tối đa
cBot
ATR
Indices
🚀N.B.: Results with an initial invested capital of 100 euros.
cBot
RSI
Forex
+6
Low drawdown RSI Forex Bot for EURUSD & GBPJPY. Starts from $20 with projected 50%+
cBot
AI
SMC
+18
Quick Trading Panel Cbot allows you to trade faster using a panel in a chart. This includes Trailing Trigger and Locked.
3
Hệ số lợi nhuận
0%
Mức sụt giảm tối đa
cBot
Indices
DAX BOT FOR INTRADAY TRADING
cBot
ADX
ATR
+5
Analyze quarterly cycles and weekly seasonality patterns across multiple instruments with historical bias data
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%
ROI
2.92
Hệ số lợi nhuận
37%
Mức sụt giảm tối đa
cBot
ATR
RSI
Hedging AI
cBot
Key Levels
SL Manager
+4
Multi-symbol dashboard with 3 fixed charts, dynamic position slots ranked by profit, Ratio analysis, MZ phase detection
cBot
ATR
Forex
+3
Trade fearlessly: auto-adjusts stops, manages risk, and locks profits with precision. Free for early users🚀 now -80%
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
ATR
Auto-manages SL, TP, and position size to enforce risk discipline. Never enter a trade without a plan again.
cBot
AI
ATR
+19
FREE Beta Test Version , World First AI Trading Bot , Adjust to suit your own strategy and risk management PLEASE ENJOY!
cBot
// EUR/USD 4H TIMEFRAME // 5 YEARS BACKTEST, PROFIT 176 USD, MAX DRAWDOWN 55 USD
Kể từ 18/12/2024
2
Lượt bán
4.1K
Cài đặt miễn phí