等级: 新手上路
- 注册:
- 2024-1-25
- 曾用名:
|
编译成功之后为什么回测不了?策略目的是“当期货布林线突破1小时的上轨, 同时满足价格突破两小时中轨 开多,带止损止盈20价位“
这是代码:
from PythonApi import *
def init(context):
context.s1 = "RB2402" # Replace with the actual stock code
def handle_bar(context):
# Retrieve the entire series of OHLC prices
ohlc_prices = pel_history_bars(1, ['open', 'high', 'low', 'close'])
# Loop through each OHLC price tuple
for ohlc_tuple in ohlc_prices:
open_price, high_price, low_price, current_price = ohlc_tuple
hour_1_upper = pel_history_bars(1, 'UpperBand')[-1]
hour_2_middle = pel_history_bars(2, 'MA')[-1]
# Compare the current price with MA and Bollinger Bands
if current_price > hour_1_upper and current_price > hour_2_middle:
# Open long position
buy_open(context.s1, "Market", volume=100,serial_id = 1)
set_stop_loss_price(current_price - 20)
set_take_profit_price(current_price + 20)
elif current_price < hour_1_upper and current_price < hour_2_middle:
# Open short position
sell_open(context.s1, "Market", volume=100,serial_id = 2)
set_stop_loss_price(current_price + 20)
set_take_profit_price(current_price - 20)
def after_trading(context):
pass
求帮忙修改以及指导怎么回测
|
|