Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of HANS123 Policy

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "sample analysis of HANS123 strategy", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "sample analysis of HANS123 strategy".

Preface

HANS123 strategy was first mainly used in the foreign exchange market, and its trading mode is relatively simple, which belongs to the trend breakthrough system. This trading method can enter the market at the first time when the trend is formed, so it is favored by many traders. So far, HANS123 has expanded many versions. Today we will understand the HANS123 strategy together.

Principle of strategy

Some people think that the opening of trading in the morning is the time when the market is the most divided, and it is easy to have unknown price trends and wide shocks. After about 30 minutes, the market has fully digested all kinds of overnight information, and the price trend will tend to be rational and return to normal. That is to say: the market trend in the first 30 minutes or so basically constitutes today's overall trading pattern.

On track: the highest price within 30 minutes of the opening

Lower track: lowest price within 30 minutes of opening

The relative high and low points produced at this time form the so-called effective high and low points in Dow theory, and the HANS123 strategy is the transaction logic based on this. In the domestic futures market, trading opens at 09:00, and you can judge whether it is long or short today by 09:30. When prices rise above highs, it is easy for prices to continue to rise; when prices break through lows, it is easy for prices to continue to fall.

Long opening: there is no position at present, and the price has broken through the track.

Short opening: there is currently no position, and the price breaks through the downward track.

Although the breakthrough strategy can enter the market as soon as the trend is formed. But this advantage is also a double-edged sword, and the result of sensitive entry is that the price breakthrough fails. Therefore, it is very necessary to set stop loss. At the same time, in order to achieve the strategic logic of winning, rushing, losing and shrinking, it is also necessary to set a stop profit.

Long stop loss: currently hold a long order, reaching the amount of loss

Short stop loss: currently holding a short order, reaching the amount of loss

The long end stops the profit, currently holds the multiple order, achieves the profit amount

Short positions stop earning, currently holding short orders, reaching the amount of profit.

Strategy writing

Open: fmz.com website > Log in > Control Center > Policy Library > New Policy > Click the drop-down menu in the upper right corner to select the Python language and start writing the policy. Pay attention to the comments in the code below.

Step 1: write a strategy framework

# Policy main function def onTick (): pass# program entry def main (): while True: # enter infinite loop mode onTick () # execute policy main function Sleep (1000) # hibernate for 1 second

Write a policy framework, which you learned in the previous chapter, one is the onTick function, and the other is the main function, where the onTick function is executed in an infinite loop in the main function.

Step 2: define global variables

Up_line = 0 # upper track down_line = 0 # lower rail trade_count = 0 # number of transactions on the day

Because the upper and lower tracks are counted only at 09:30, and not the rest of the time, we need to write these two variables outside the loop. In addition, in order to limit the number of transactions in intraday trading, the trade_count variable is also written outside the loop. Before using these two global variables within the onTick policy main function, you need to use the global keyword reference.

Step 3: get the data

Exchange.SetContractType ("rb888") # subscription futures variety bar_arr = _ C (exchange.GetRecords, PERIOD_M1) # get 1-minute K-line array current_close = bar_arr [- 1] ['Close'] # get the latest price if len (bar_arr)

< 50: # 如果小于50根K线 return # 返回继续等待数据 要想获取数据,首先要使用发明者量化API中的SetContractType函数订阅期货品种,然后使用GetRecords函数获取K线数组,也可以在使用GetRecords函数时传入指定PERIOD_M11分钟的K线数组。 紧接着就是获取最新的价格,用来判断当前价格与上下轨之间的位置关系,同时在下单交易使用Buy或Sell函数时,需要传入指定的价格。另外别忘了过滤K线数量,因为如果K线过少,就会出现无法计算指标报错。 第4步:处理时间函数 def current_time(): current_time = bar_arr[-1]['Time'] # 获取当前K线时间戳 time_local = time.localtime(current_time / 1000) # 处理时间戳 hour = time.strftime("%H", time_local) # 格式化时间戳,并获取小时 minute = time.strftime("%M", time_local) # 格式化时间戳,并获取分钟 if len(minute) == 1: minute = "0">

When calculating the upper and lower tracks and issuing order transactions, we need to judge whether the current time is in line with our specified trading time, so in order to facilitate judgment, we need to deal with the specific hours and minutes of the current K line.

Step 5: calculate the upper and lower rails

Global up_line, down_line, trade_count # introduce the global variable current_time = current_time () # processing time if current_time = = 930: # if the latest K-line time is 09:30 up_line = TA.Highest (bar_arr, 30, 'High') + count # the highest price for the first 30 K-lines down_line = TA.Lowest (bar_arr, 30 'Low')-count # lowest price for the first 30 K lines trade_count = 0 # reset number of transactions is 0

To calculate the upper and lower tracks, first introduce the global variables we defined earlier, using the global keyword. Imagine that what we need to calculate is the highest price and the lowest price between 09bicycle 09V30, because we are using 1 minute K-line data, that is to say, when the time is 09:30, there are just 30 K-lines, then we can directly calculate the highest and lowest prices of these 30 K-lines.

Step 6: take a position

Position_arr = _ C (exchange.GetPosition) # get position array if len (position_arr) > 0: # if position array length is greater than 0 position_arr = position_arr [0] # obtain position dictionary data if position_arr ['ContractType'] = =' rb888': # if position variety equals subscription variety if position_arr ['Type']% 2 = 0: # as shown in If multiple single position = position_arr ['Amount'] # assigned position is positive else: position =-position_arr [' Amount'] # assigned position number is negative profit = position_arr ['Profit'] # obtain position profit and loss else: position = 0 # assigned position quantity is 0 profit = 0 # assigned position profit or loss is 0

Position status involves strategic logic. We have always used virtual positions in the first ten courses, but in a real trading environment, it is best to use the GetPosition function to obtain real position information, including position direction, position profit and loss, position number, and so on.

Step 7: place an order transaction

# if close or reach stop profit and stop loss if current_time > 1450 or profit > stop * 3 or profit

< -stop: if position >

0: # if you hold multiple single exchange.SetDirection ("closebuy") # set transaction direction and type exchange.Sell (current_close-1,1) # flat multiple single elif position

< 0: # 如果持空单 exchange.SetDirection("closesell") # 设置交易方向和类型 exchange.Buy(current_close + 1, 1) # 平空单# 如果当前无持仓,并且小于指定交易次数,并且在指定交易时间内if position == 0 and trade_count < 2 and 930 < current_time < 1450: if current_close >

Up_line: # if the price is greater than the exchange.SetDirection ("buy") # set the transaction direction and type exchange.Buy (current_close + 1) 1) # multiple orders trade_count = trade_count + 1 # transactions plus one elif current_close < down_line: # if the price is less than the lower track exchange.SetDirection ("sell") # set the transaction direction and type exchange.Sell (current_close-1,1) # empty orders trade_count = trade_count + 1 # transactions plus one

In order to avoid logic errors in the strategy, it is best to write the closing logic before the opening logic. In this strategy, when opening a position, we should first judge the current position, whether it is within the specified trading time, and then judge the relationship between the current price and the up and down tracks. To close the position is to judge whether it is close to the end of the day, or whether it has reached the condition of stopping profit and stop loss.

HANS123 is a very typical and effective automatic trading strategy, its basic principle is to break through the highest or lowest price of the previous market within a certain period of time to go long or short. After optimizing the parameters such as stop loss and profit, this system can be applied to almost all kinds of foreign exchange and make a stable profit. This is also an early entry trading mode, combined with appropriate filtering technology, may improve its chances of success.

The above is all the content of this article "sample Analysis of HANS123 Strategy". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report