我一直在研究可以预测何时在外汇市场上买卖的算法(不是我的,我只是在修改它)。我需要能够打开和关闭订单,动态更新订单参数(例如止损,最大止损等)并接收实时报价数据。
我已经研究了一个多星期,但没有成功。
我设法将DLL导入到Java中并使用了MQL4函数,AccountBalance()但是该函数返回了0.0,但这不是帐户余额,我弄乱了MT4客户端上的代码和设置,但仍然没有运气。
Q0:谁能指出我正确的方向?
我是自动进行外汇交易的新手,但据我了解,某个地方有一个经纪人,带有MT4服务器,并且我使用Windows计算机上的MT4客户端连接到该服务器。
问题1:如果是这种情况,我是否需要使API与服务器端而不是客户端一起工作?
到目前为止,我尝试过的所有这些DLL都已与机器上的MT4客户端软件一起使用。
我也一直在阅读有关FIX协议和ZeroMQ的内容。
Q2:这些可以以任何方式帮助我实现目标(而不是在JAVA和MT4 DLL之间建立一些桥梁)吗?
我有一个小程序,我用于算法股票交易.代码必须在我的8核桌面计算机上循环大约192万亿次.我想租用一台64核机器来运行它,但这不符合成本效益.
这只是代码.但for循环必须在每个要计算的条上循环(大约180万),然后循环检查匹配的列表大约是800k项.
我现在能想到加速它的唯一方法是删除匹配的项目,因为它只发生一次(DateTime).
有没有其他人有办法加快这段代码的速度?这需要我的桌面野兽大约45个小时来完成程序的一次迭代.
基本上我正在做的是计算每个条形图,寻找当前条形DateTime是否与我手工创建的CSV文件中的DateTime相匹配.然后从列表对象中,我抓住交易方向并设置一个bool来占据一个位置.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;
using System.IO;
using System.IO.Compression;
namespace PowerLanguage.Strategy
{
public class Ecal_v1 : SignalObject
{
public List<Trades> tradeList = new List<Trades>();
public List<string> csvList = new List<string>();
public bool exitOn24 = false;
public string ecalPath = @"C:\Users\Skynet\OneDrive\Trading\Economic Calendars\backtest1.csv";
PowerLanguage.Indicator.Bollinger_Bands bb;
public Ecal_v1(object _ctx):base(_ctx){}
//[Input]
//public bool exitOn24 { get; set; }
[Input]
public double bbTopOffset { get; set; }
775
[Input]
public double bbBotOffset { …Run Code Online (Sandbox Code Playgroud) 我有一个数据库表,其中包含一分钟的打开,关闭,高,低,成交量值,以获取证券。我正在使用SQL Server 2017,但是可以选择2019 RC。
我试图找到一个有效的SQL Server查询,可以将这些查询聚合到5分钟的窗口中,其中:
理想情况下,此查询将考虑数据中的差距,即基于日期计算,而不是对前/后行进行计数。
例如说我有(这是6分钟的数据):
| 时间| 开启| 关闭| 高| 低| 数量 | ------------------ | ------ | ------- | ------ | ----- |- ------ | | 2019-10-30 09:30 | 5 | 10 | 15 | 1 | 125000 | | 2019-10-30 09:31 | 10 | 15 | 20 | 5 | 100000 | | 2019-10-30 09:32 | 15 | 20 | 25 | 10 | 120000 | | 2019-10-30 09:33 | 20 …
sql sql-server stockquotes algorithmic-trading window-functions
有没有比我在下面提出的更有效的方法来改变熊猫的多头/空头头寸?
逻辑要点:
np.nan一直持续到有买入 (+1) 或卖出 (-1) 信号。import numpy as np
import pandas as pd
df = pd.DataFrame({
'buy_sell': [np.nan, 1, np.nan, 1, np.nan, np.nan, 1, -1, np.nan, -1, np.nan, 1, np.nan, -1],
'position': np.nan
})
for i, r, in df.iterrows():
buy_sell = r['buy_sell']
# Check if first index
if i != 0:
last_position = df.loc[i-1, 'position']
if np.isnan(buy_sell):
df.loc[i, 'position'] …Run Code Online (Sandbox Code Playgroud) 当通过盈透证券的API方法接收的财务数据打勾tickPrice或tickSize数据将具有下列参数
从任何其他饲料我会期望给我一个滴答
所以我的问题是:我应该保留一个字典,其中tickerId作为键,结构作为包含上述五个属性的值,这样每次提出tick事件时,我都会更新struct的相应属性并将整个struct发送到我的数据库中打勾?理想情况下,我的tick数据库看起来像这样
Date Time Symbol Side Price Quantity
2012-10-31 13:51:13.784 AAPL Bid 25.81 15007
2012-10-31 13:51:14.615 AAPL Bid 25.82 10
2012-10-31 13:51:14.633 AAPL Bid 25.81 13623
2012-10-31 13:51:14.684 AAPL Ask 25.82 2500
2012-10-31 13:52:09.168 AAPL Bid 25.80 12223
Run Code Online (Sandbox Code Playgroud)
从IB API文档:当市场数据发生变化时调用此方法.这是否意味着如果例如更新出价,其他属性将保持不变?
我有一个用 Python 训练的 XGBoost 树结构的转储文件。该结构有 377 棵树,文件大约有 50,000 行。我想将此结构转换为 MQL4 代码,或者可以说是 C 代码。文本文件看起来像这样:
booster[0]:
0:[inp0<6.85417] yes=1,no=2,missing=1
1:[inp10<1.00054] yes=3,no=4,missing=3
3:[inp21<0.974632] yes=7,no=8,missing=7
7:[inp22<1.01021] yes=15,no=16,missing=15
15:[inp15<0.994931] yes=31,no=32,missing=31
31:[inp12<0.999151] yes=63,no=64,missing=63
63:[inp23<0.957624] yes=111,no=112,missing=111
111:leaf=0.163636
112:leaf=-0.36
64:leaf=0.323077
32:[inp19<0.993949] yes=65,no=66,missing=65
65:[inp23<0.931146] yes=113,no=114,missing=113
113:leaf=-0
114:[inp23<0.972193] yes=161,no=162,missing=161
161:leaf=-0.421782
162:leaf=-0.133333
66:[inp2<61] yes=115,no=116,missing=115
115:leaf=0.381818
116:leaf=-0.388235
16:[inp17<0.985065] yes=33,no=34,missing=33
33:leaf=-0.381818
34:[inp23<0.946341] yes=67,no=68,missing=67
67:leaf=-0.36
68:[inp12<1.00121] yes=117,no=118,missing=117
117:[inp19<0.989751] yes=163,no=164,missing=163
163:leaf=0.367742
164:leaf=-0.0666667
118:[inp0<4.29167] yes=165,no=166,missing=165
165:leaf=-0
166:leaf=-0.3
8:[inp11<0.999875] yes=17,no=18,missing=17
17:[inp7<134] yes=35,no=36,missing=35
35:[inp9<62] yes=69,no=70,missing=69
69:[inp8<26] yes=119,no=120,missing=119
119:[inp23<0.993382] yes=167,no=168,missing=167
167:leaf=-0.211765
168:leaf=0.27
120:[inp21<0.989946] yes=169,no=170,missing=169
169:leaf=-0.392308
170:leaf=-0.161421
70:[inp17<0.997] yes=121,no=122,missing=121
121:[inp13<0.999021] yes=171,no=172,missing=171 …Run Code Online (Sandbox Code Playgroud) 我想从我的函数返回一个数组,我该怎么做?
看!
int GetOrdresVente(){
int ordrevente;
int Tabordresvente[];
for(int j = OrdersTotal() - 1; j >= 0 ; j--){
if(OrderSelect( j, SELECT_BY_POS ) == true){
if(OrderSymbol() == Symbol()){
if(OrderType() == OP_SELL ){
ordrevente = OrderTicket();
ArrayResize( Tabordresvente, ArraySize( Tabordresvente ) + 1);
Tabordresvente[ArrayResize( Tabordresvente, ArraySize( Tabordresvente ) - 1 )] = ordrevente;
}
}
}
}
return Tabordresvente;
}
Run Code Online (Sandbox Code Playgroud)
感谢您的回复!
我正在修改策略,仅在达到一定数量的蜡烛后退出交易。
我输入了timeframe(在脚本的输入部分)并在底部设置了退出规则(barssince) - 它在很多时候都在工作,但有些交易仍然会更快结束。无法弄清楚是什么原因造成的。
还需要做什么才能仅在指定的柱数上退出交易?
这是脚本:https: //pastebin.com/8HQyJxa0(已更新)
似乎当设置较长的到期时间时,上涨交易会过早地结束下跌交易,反之亦然。我确实需要两个交易能够同时运行,仅在达到指定的柱数后才平仓timeframe
更新:显然使用strategy.position_size <= 0指定没有股票或借入可以避免它关闭我当前的未平仓头寸 - 但不确定这如何适合当前的脚本。
我在数据框中有 Apple 的 1 分钟股票信息,如下所示:
Local time Open High Low Close Volume
0 2018-04-19 15:00:00 46.707 46.708 46.687 46.687 0.0150
1 2018-04-19 15:01:00 46.688 46.688 46.667 46.688 0.0320
2 2018-04-19 15:02:00 46.687 46.728 46.677 46.728 0.0091
3 2018-04-19 15:03:00 46.727 46.728 46.708 46.717 0.0332
4 2018-04-19 15:04:00 46.708 46.718 46.677 46.677 0.0243
Run Code Online (Sandbox Code Playgroud)
我已使用将“当地时间”列转换为日期时间pd.to_datetime(df['Local time'])。我想单独度过每一天来回测策略。但我不知道如何一次循环遍历由日期更改定义的 df 块。我尝试使用一些 for 循环,但它们不起作用,因为交易的分钟数在某些日子明显不同(不是 390):
index = 390 #Number of traded minutes on most days
rows = 286155 #number of rows in the dataset …Run Code Online (Sandbox Code Playgroud) 我正在使用 unicorn_binance_websocket_api 传输 100 个加密货币和 2 个不同时间范围的价格数据,我想处理这些数据以存储不同加密货币相对于其时间范围的收盘价,然后执行我的策略以查看我需要哪个加密货币和时间范围交易
我将分享关于如何为单个加密货币和单个时间范围编写策略的代码
from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import
BinanceWebSocketApiManager
import json, numpy, talib
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com-futures")
binance_websocket_api_manager.create_stream('kline_1m', 'btcusdt')
closes =[]
RSI_PERIOD = 14
RSI_OVERBOUGHT = 70
RSI_OVERSOLD = 30
while True:
received_stream_data_json = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
if received_stream_data_json:
json_data = json.loads(received_stream_data_json)
candle_data = json_data.get('data',{})
candle = candle_data.get('k', {})
symboll = candle.get('s',{})
timeframe = candle.get('i',{})
close_prices = candle.get('c',{})
open_prices = candle.get('o',{})
is_candle_closed = candle.get('x',{})
if is_candle_closed:
closes.append(float(close_prices))
if len(closes) > RSI_PERIOD:
np_closes = numpy.array(closes)
rsi = talib.RSI(np_closes,RSI_PERIOD)
if (rsi[-1] > …Run Code Online (Sandbox Code Playgroud)