pixcelo / mt5-using-python

metaTrader5 using python
0 stars 0 forks source link

損切りの設定(ストップロス・トレーリングストップ) #10

Open pixcelo opened 12 months ago

pixcelo commented 12 months ago

逆行しても損はしない保守的な取引ができる

# 一定の値幅が取れていれば、ストップを建値に移動する
def update_stop_loss(self, position, current_price, entry_price, stop_loss, threshold=10):
    if position == "long":
        pips = current_price - entry_price
    elif position == "short":
        pips = entry_price - current_price

    if pips >= threshold:
        return entry_price

    return stop_loss
pixcelo commented 12 months ago

ダウ理論に基づき、優位性のある位置にストップを移動する

# 一定の値幅が取れていれば、ロングの場合はストップを直近安値に移動する。ショートの場合はストップを直近高値に移動する。
def update_stop_loss(self, position, current_price, entry_price, stop_loss, threshold=10):
    if position == "long":  
        pips = current_price - entry_price
        if pips >= threshold:
            if self.last_pivots_low[-1] > stop_loss:
                return self.last_pivots_low[-1]
            return entry_price

    elif position == "short":
        pips = entry_price - current_price
        if pips >= threshold:
            if self.last_pivots_high[-1] < stop_loss:
                return self.last_pivots_high[-1]
            return entry_price

    return stop_loss