Trước đây tôi đã sử dụng thông điệp chỉ số.
Cách thực hiện là viết OpenLong, OpenShort trong mỗi cài đặt tin nhắn của cảnh báo, sau đó gửi đến robot FMZ để thực hiện.
Không sao đâu.
Và bây giờ, hãy sử dụng chiến lược để gửi tin nhắn.
TradingView có mã:
// 警报消息
var string Message_open_long = input.string('OpenLong', '开多消息', group = '===================exit警报=======================', tooltip = '如果“创建警报”对话框的“消息”字段包含{{strategy.order.alert_message}}占位符,则警报消息将用此文本替换占位符。')
var string Message_open_short = input.string('OpenShort', '开空消息', group = '===================exit警报=======================', tooltip = '如果“创建警报”对话框的“消息”字段包含{{strategy.order.alert_message}}占位符,则警报消息将用此文本替换占位符。')
var string Message_close_long = input.string('CloseLong', '平多消息', group = '===================exit警报=======================', tooltip = '如果“创建警报”对话框的“消息”字段包含{{strategy.order.alert_message}}占位符,则警报消息将用此文本替换占位符。')
var string Message_close_short = input.string('CloseShort', '平空消息', group = '===================exit警报=======================', tooltip = '如果“创建警报”对话框的“消息”字段包含{{strategy.order.alert_message}}占位符,则警报消息将用此文本替换占位符。')
////////========开仓处理==========//////////////
if (Open_long or Open_short) and barstate.isconfirmed
Trade_vol := Trade_type == '合约' ? 1000 : 1000 / close // 设定交易量
// 开多
if Open_long
strategy.entry('Long'
, strategy.long
, qty = Trade_vol
, alert_message = Message_open_long // 订单成交时发送的警报内容
)
State_position := 1
// 开空
if Open_short
strategy.entry('Short'
, strategy.short
, qty = Trade_vol
, alert_message = Message_open_short // 订单成交时发送的警报内容
)
State_position := 0
Sau đó sử dụng phương pháp {{strategy.order.alert_message}} trong thiết lập cảnh báo
FMZ nhận được tin nhắn nhưng không trả tiền

Xin vui lòng cho tôi biết nguyên nhân của vấn đề này và làm thế nào để giải quyết nó?
Đây là mã FMZ.
switch (command) {
case 'OpenLong': // 开多单
_OpenPositions(1, 0, positions, account, ticker);
break;
case 'OpenShort': // 开空单
_OpenPositions(0, 1, positions, account, ticker);
break;
case 'CloseLong': // TV信号平多
if (positions.length > 0) {
if (positions[0].Type === PD_LONG) {
_Cover_1(); // 快速平仓
_ResetVariables(); // 重置运算变量
_CalculateProfit(positions, account, ticker); // 统计收益
} else {
Log('当前持有空头仓位');
}
}
else {
Log('没有持仓,无法平多');
}
break;
case 'CloseShort': //TV信号平空
if (positions.length > 0) {
if (positions[0].Type === PD_SHORT) {
_Cover_1(); // 快速平仓
_ResetVariables(); // 重置运算变量
_CalculateProfit(positions, account, ticker); // 统计收益
} else {
Log('当前持有多头持仓');
}
} else {
Log('没有持仓,无法平空');
}
break;
default:
break;
}
您好,看您的截图中日志收到消息,策略不执行,应该和您的策略(FMZ平台上的)设计有关。
检查一下_OpenPositions函数中的代码,写一些Log函数,看这个函数是否执行。
我后来重新处理了,把FMZ和TV的代码全部修改了,TV代码
////////========警报消息========////////
Str_massage_group = '================-----------警报消息-----------================'
var string Message_open_long = input.text_area('{"Action":"OpenLong"}', '开多消息', group = Str_massage_group, tooltip = "如果“创建警报”对话框的“消息”字段包含'{{strategy.order.alert_message}}'占位符,则警报消息将用此文本替换占位符。")
var string Message_open_short = input.text_area('{"Action":"OpenShort"}', '开空消息', group = Str_massage_group, tooltip = "如果“创建警报”对话框的“消息”字段包含'{{strategy.order.alert_message}}'占位符,则警报消息将用此文本替换占位符。")
var string Message_close_long = input.text_area('{"Action":"CloseLong"}', '平多消息', group = Str_massage_group, tooltip = "如果“创建警报”对话框的“消息”字段包含'{{strategy.order.alert_message}}'占位符,则警报消息将用此文本替换占位符。")
var string Message_close_short = input.text_area('{"Action":"CloseShort"}', '平空消息', group = Str_massage_group, tooltip = "如果“创建警报”对话框的“消息”字段包含'{{strategy.order.alert_message}}'占位符,则警报消息将用此文本替换占位符。")
// 多单出场
strategy.exit('E-Long' // 名称
, 'Long' // ID
, stop = Price_SL
, limit = Price_TP
// , loss = Points_SL // 止损点数(通过止损百分比计算出来)
// , profit = Points_TP // 止盈点数
, trail_points = Type_TP == 51 ? Points_trail : na // 追踪止盈开关
, trail_offset = Type_TP == 51 ? Points_trail_offset : na // 追踪止盈点数
, comment_loss = "L-SL" // 止损时绘制的图标名称
, comment_profit = "L-TP" // 止盈时绘制的图标名称
, comment_trailing = "L-TS" // 回调止盈时绘制的图标名称
, alert_message = Message_close_long // 警报消息
)
//// 根据TV消息执行对应的操作
function _RunTVCommand(command)
{
////
var positions = _C(exchange.GetPositions); //获取当前交易所账户的持仓信息,并返回一个包含持仓信息的对象。
var account = _C(exchange.GetAccount); //获取交易所账户信息
var ticker = _C(exchange.GetTicker); //获取当前交易对的市场行情信息
var action = command.Action; //获取要执行的处理
if (positions.length > 1) { ////如果同时持有多空仓位则退出
Log(positions);
throw '同时有多空持仓!无法操作';
}
switch (action) {
case "OpenLong": // 开多单
_OpenPositions(1, 0, positions, account, ticker);
break;
case "OpenShort" : // 开空单
_OpenPositions(0, 1, positions, account, ticker);
break;
case "CloseLong" : // TV信号平多
if (positions.length > 0) {
if (positions[0].Type === PD_LONG) {
_Cover_1(); // 快速平仓
_ResetVariables(); // 重置运算变量
_CalculateProfit(positions, account, ticker); // 统计收益
} else {
Log('当前持有空头仓位');
}
}
else {
Log('没有持仓,无法平多');
}
break;
case "CloseShort" : //TV信号平空
if (positions.length > 0) {
if (positions[0].Type === PD_SHORT) {
_Cover_1(); // 快速平仓
_ResetVariables(); // 重置运算变量
_CalculateProfit(positions, account, ticker); // 统计收益
} else {
Log('当前持有多头持仓');
}
} else {
Log('没有持仓,无法平空');
}
break;
default:
break;
}
}
处理的方法是不在使用之前自己写的openshort这种简单的信号,而是用更接近TV输出的格式。然后在FMZ进行解析。
- 1


