hans123 日中の突破戦略

作者: リン・ハーン優しさ, 作成日:2020年8月12日11時38分39秒 更新日:2023年10月10日21時15分02秒

img

前言

HANS123戦略は,最初に主に外為市場に適用された.その取引方法は比較的シンプルで,トレンドブレークスルーシステムに属している.この取引方法はトレンドが形成されるとすぐに市場に参入できるため,多くのトレーダーが好む.これまで,HANS123は多くのバージョンを拡大した.一緒にHANS123戦略を理解して展開しよう.

img

戦略 の 原則

ある人々は,朝の市場開通が市場が最大の差異を持つ時間であると信じています. 約30分後,市場は一晩間のあらゆる情報を完全に消化し,価格傾向は合理的で正常に戻る傾向にあります. 言い換えれば:最初の30分間の市場の傾向は,基本的に今日の全体的な取引パターンを構成します.

  • 上線:開店から30分以内の最高価格
  • 下線:開店から30分以内に最低価格

この時点で生成される相対的な高値と低値は,ダウ理論の有効高値と低値を形成し,HANS123戦略は,これによって確立された取引論理である.国内先物市場では,市場は午前9時00分にオープンし,午前9時30分には,今日のロングかショートかを判断することができます.価格が高値を突破すると,価格は容易に上昇し続けます.価格が低値を突破すると,価格は簡単に下落し続けます.

  • ロングポジション開設:現在,ホールディングポジションがないし,価格は上線を超えて割れている.
  • ショートポジション開設:現在,ホールディングポジションはなく,価格は下線を下回る.

突破戦略は,トレンドが形成されるとすぐに市場に参入することができる.しかし,この利点は双刃の剣でもあります.敏感なエントリーの結果,価格突破は失敗しました.したがってストップロスを設定する必要があります.同時に,勝利と敗北の戦略論理を達成するために,利益を得ることを設定する必要があります.

  • ロングポジションストップ損失:現在のロングポジションが損失額に達した
  • ショートポジションストップ損失:現在のショートポジションが損失額に達した
  • ロングポジションから利益を得て,ロングポジションを保持し,利益額に達する
  • ショートポジションから利益を得,ショートポジションを保持し,利益額に達する

戦略の書き込み

順番に開きますfmz.comサイト> ログイン > ダッシュボード > 戦略ライブラリ > 新しい戦略 > 右上角にあるドロップダウンメニューをクリックして Python 言語を選択して戦略を書き始めます. 下のコードのコメントに注意してください.

ステップ1: 戦略の枠組みを書き出す

# Strategy main function
def onTick():
    pass


# Program entry
def main():
    while True: # enter infinite loop mode
        onTick() # execute strategy main function
        Sleep(1000) # Sleep for 1 second

戦略の枠組みを書き,これは前章で学びました,onTick機能,そしてもう一つはmain機能として,onTick実行される.main function.

ステップ2: グローバル変数を定義する

up_line = 0 # upper rail
down_line = 0 # lower rail
trade_count = 0 # Number of transactions on the day

上と下のレールが9時30分にのみカウントされ,残りの時間には統計は行われないため,これらの2つの変数をループの外に書き込む必要があります. さらに,日取引の取引数を制限するために,trade_countこの2つのグローバル変数をループの主要な関数に使う前にonTick戦略としてglobalキーワードを参照する

ステップ3:データを取得

exchange.SetContractType("rb888") # Subscribe to futures varieties
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: # If less than 50 k line bars
    return # Return to continue waiting for data

データを取得するには,まずSetContractTypeフューチャー株のサブスクリプションをするために,その後,GetRecordsまた,K線配列に指定する文字を入れることができます.PERIOD_M11試行錯誤を防ぐためにGetRecords function.

次のステップは,現在の価格と上下レールの位置関係を決定するために使用される最新の価格を取得することです.同時に,購入または販売関数を使用してオーダーを行うとき,指定された価格を入力する必要があります.さらに,k ラインバーの数をフィルターすることを忘れないでください.k ラインバーの数が少ない場合,計算できないエラーが発生します.

ステップ4: 処理時間関数

def current_time():
    current_time = bar_arr[-1]['Time'] # Get current K-line timestamp
    time_local = time.localtime(current_time / 1000) # Processing timestamp
    hour = time.strftime("%H", time_local) # Format the timestamp and get the hour
    minute = time.strftime("%M", time_local) # Format the timestamp and get the minute
    if len(minute) == 1:
        minute = "0" + minute
    return int(hour + minute)

上下線を計算し,オーダーを出すとき,現在の時間が我々によって指定された取引時間と一致するかどうかを判断する必要があります.

ステップ 5: 上部と下部のレールを計算する

global up_line, down_line, trade_count # Introduce global variables
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 of the first 30 k line bars
    down_line = TA.Lowest(bar_arr, 30,'Low')-count # The lowest price of the first 30 ke line bars
    trade_count = 0 # Reset the number of transactions to 0

ステップ 6: ポジションを取得

position_arr = _C(exchange.GetPosition) # Get position array
if len(position_arr) > 0: # If the position array length is greater than 0
    position_arr = position_arr[0] # Get position dictionary data
    if position_arr['ContractType'] =='rb888': # If the position symbol is equal to the subscription symbol
        if position_arr['Type']% 2 == 0: # If it is a long position
            position = position_arr['Amount'] # The number of assigned positions is a positive number
        else:
            position = -position_arr['Amount'] # Assign a negative number of positions
        profit = position_arr['Profit'] # Get position profit and loss
else:
    position = 0 # The number of assigned positions is 0
    profit = 0 # Assign position profit and loss to 0

ポジションステータスには戦略論理が含まれます. 私たちの最初の10レッスンは常に仮想保有ポジションを使用しましたが,実際の取引環境では,GetPositionポジションの方向性,ポジションの利益と損失,ポジションの数などを含む実際のポジション情報を取得する機能

ステップ7 注文する

# If it is close to market closing or reach taking profit and stopping loss
if current_time > 1450 or profit > stop * 3 or profit < -stop:
    if position > 0: # If holding a long position
        exchange.SetDirection("closebuy") # Set transaction direction and type
        exchange.Sell(current_close-1, 1) # Close long order
    elif position <0: # If holding an empty order
        exchange.SetDirection("closesell") # Set transaction direction and type
        exchange.Buy(current_close + 1, 1) # Close short order
# If there is no current position, and it is less than the specified number of transactions, and within the specified trading time
if position == 0 and trade_count < 2 and 930 < current_time < 1450:
    if current_close > up_line: # If the price is greater than the upper line
        exchange.SetDirection("buy") # Set transaction direction and type
        exchange.Buy(current_close + 1, 1) # Open long order
        trade_count = trade_count + 1 # Increase the number of transactions
    elif current_close < down_line: # If the price is less than the lower line
        exchange.SetDirection("sell") # Set transaction direction and type
        exchange.Sell(current_close-1, 1) # Open a short order
        trade_count = trade_count + 1 # Increase the number of transactions

戦略における論理エラーを避けるために,開設ポジション論理の前に閉じるポジション論理を書くのが最善です.この戦略では,ポジションを開くとき,まず現在のポジションの状態を特定し,指定された取引時間内にあり,その後の現在の価格と上下線との関係を決定します.ポジションを閉じるには,まず市場の閉店に近づいているかどうかを決定するか,または利益を得て損失を停止する条件に達したかどうかを決定します.

HANS123は,非常に典型的で非常に効果的な自動取引戦略である.その基本原理は,一定の期間以内に以前の市場の最高または最低価格を突破することです.このシステムは,安定した収益性を持つほぼすべての外為商品に適用できます.これは適切なフィルタリング技術を持つ早期入場取引モードでもあり,または勝つ確率を改善することができます.

完全な戦略

完全な戦略ソースコードをコピーするにはクリックします.https://www.fmz.com/strategy/179805バックテスト 設定なし

終わり

上記は,HANS123戦略の原則とコード分析です. 実際,HANS123戦略は,市場に参入するより良い時間を提供します.また,市場の理解と取引の理解に応じて,または多様性の変動に応じて,出口時間を改善することができます. より良い結果を達成するために,利益と損失を停止するなどのパラメータを最適化するために.


関連性

もっと