Skip to content

Latest commit

 

History

History
271 lines (190 loc) · 9.19 KB

高杠杆防止追加保证金头寸管理策略Leveraged-Position-Sizing-with-Margin-Call-Risk-Management-Strategy.md

File metadata and controls

271 lines (190 loc) · 9.19 KB

Name

高杠杆防止追加保证金头寸管理策略Leveraged-Position-Sizing-with-Margin-Call-Risk-Management-Strategy

Author

ChaoZhang

Strategy Description

IMG [trans]

概述

该策略通过设置高杠杆和追加保证金条件,在市场大幅波动时及时平仓,实现防止追加保证金的风险管理。

策略原理

  1. 设置高杠杆操作,如杠杆比例为4倍
  2. 设置追加保证金线,如$25,000
  3. 当权益低于追加保证金线时,策略停止开仓
  4. 当权益继续下跌触发追加保证金信号时,策略平仓所有头寸

通过上述设置,可在市场大幅波动导致权益快速下跌时,及时止损,防止追加保证金的风险。

优势分析

  1. 可根据个人承受能力灵活设置杠杆比例,控制单笔损失风险
  2. 追加保证金机制可以防止账户爆仓
  3. 在高杠杆操作下,及时止损,最大程度规避风险

风险分析

  1. 高杠杆放大了收益同时也放大了风险
  2. 需要合理设置追加保证金线,与止损线匹配
  3. 止损容易被套,需要优化止损策略

可通过适当调整杠杆比例,设置追加保证金线与止损线匹配,优化止损策略等方法降低风险。

优化方向

  1. 结合趋势指标,避免逆势建仓
  2. 优化止损方式,避免止损被套
  3. 设置无交易区间,避免特定时间段建仓
  4. 结合机器学习算法,动态调整参数

总结

该策略通过高杠杆和追加保证金设置实现风险管理,可以防止账号爆仓。但高杠杆也放大了风险,需要进一步通过趋势判断、止损优化、交易时间控制等方法降低风险。同时可以运用机器学习等更复杂技术对参数进行动态优化,在收益与风险之间寻找最佳平衡。

||

Overview

This strategy manages risk by setting high leverage and margin call conditions to close positions during significant market fluctuations.

Strategy Logic

  1. Set high leverage, e.g. 4x
  2. Define margin call level, e.g. $25,000
  3. Stop opening new trades when equity falls below margin call level
  4. Close all positions when margin call triggered as equity continues dropping

By doing so, the strategy can cut losses in time during drastic market moves to prevent margin call risks.

Advantages Analysis

  1. Flexible leverage customization based on personal risk tolerance
  2. Margin call mechanism prevents account blowups
  3. Timely stop loss with high leverage to mitigate risks

Risk Analysis

  1. Leverage amplifies both profits and risks
  2. Margin call level needs alignment with stop loss
  3. Stop loss subject to slippage risks

Risks can be reduced by adjusting leverage, aligning margin call and stop loss, optimizing stop loss, etc.

Optimization Directions

  1. Add trend filter to avoid counter-trend trades
  2. Optimize stop loss to prevent slippages
  3. Set trading hour filters to avoid trades in certain sessions
  4. Incorporate machine learning models to dynamically tune parameters

Summary

The strategy manages risk with leverage and margin call settings to prevent account blowups. However, high leverage also increases risks. Additional efforts like trend validation, stop loss optimization and trading hour control can help further reduce risks. Complex techniques like machine learning can also be leveraged to dynamically optimize parameters and strike a balance between profitability and risk management.

[/trans]

Strategy Arguments

Argument Default Description
v_input_1 true Use Margin Call?
v_input_2 25000 Margin Value
v_input_3 true Use Leverage
v_input_4 4 Leverage mult (1 for no leverage)
v_input_5 true Use Risk Management?
v_input_6 5 Stop Loss in ticks value
v_input_7 500 Take Profit in ticks value
v_input_8 true [LABEL] DATE
v_input_9 2019 From Year
v_input_10 12 From Month
v_input_11 true From Day
v_input_12 2019 To Year
v_input_13 12 To Month
v_input_14 9 To Day

Source (PineScript)

/*backtest
start: 2023-11-25 00:00:00
end: 2023-12-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
//@author=Daveatt

// Breakout on 2H high/low break Strategy

SystemName = "Leverage Strategy"
TradeId = "?"

InitCapital             = 100000
InitPosition            = 1
UseMarginCall           = input(true, title="Use Margin Call?")
MarginValue             = input(25000, title="Margin Value", type=input.float)
// use 1 for no leverage
// use 0.1 for be underleveraged and bet 1/10th of a pip value
// use any value > 1 for full-degen mode
UseLeverage             = input(true, title="Use Leverage")
LeverageValue           = input(4, title="Leverage mult (1 for no leverage)", minval=0.1, type=input.float)
// Risk Management
UseRiskManagement       = input(true, title="Use Risk Management?")
// ticks = 1/10th of a pip value
StopLoss                = input(5, title="Stop Loss in ticks value", type=input.float)
TakeProfit              = input(500, title="Take Profit in ticks value", type=input.float)

InitCommission = 0.075
InitPyramidMax = 1
CalcOnorderFills = false
CalcOnTick = true
DefaultQtyType = strategy.cash
DefaultQtyValue = strategy.cash
Currency = currency.USD
Precision = 2
Overlay=false
MaxBarsBack=3000

strategy
 (
 title=SystemName, 
 shorttitle=SystemName, 
 overlay=Overlay 
 )

//////////////////////////// UTILITIES ///////////////////////////

f_print(_txt, _condition) =>

    var _lbl = label(na)
    label.delete(_lbl)

    if _condition
        // saving the candle where we got rekt :(
        _index = barssince(_condition)
        _lbl := label.new(bar_index - _index, highest(100), _txt, xloc.bar_index, yloc.price, size = size.normal, style=label.style_labeldown)

//////////////////////////// STRATEGY LOGIC ///////////////////////////

// Date filterigng
_Date       = input(true, title="[LABEL] DATE")
FromYear = input(2019, "From Year", minval=1900),   FromMonth = input(12, "From Month", minval=1, maxval=12),    FromDay = input(1, "From Day", minval=1, maxval=31)
ToYear = input(2019, "To Year", minval=1900),       ToMonth = input(12, "To Month", minval=1, maxval=12),        ToDay = input(9, "To Day", minval=1, maxval=31)
FromDate = timestamp(FromYear, FromMonth, FromDay, 00, 00)     
ToDate = timestamp(ToYear, ToMonth, ToDay, 23, 59)
TradeDateIsAllowed = true

// non-repainting security version
four_hours_H     = security(syminfo.tickerid, '240', high[1], lookahead=true)
four_hours_L     = security(syminfo.tickerid, '240', low[1], lookahead=true)
buy_trigger     = crossover(close, four_hours_H)
sell_trigger    = crossunder(close, four_hours_L)

// trend states
since_buy  = barssince(buy_trigger)
since_sell = barssince(sell_trigger)
buy_trend  = since_sell > since_buy
sell_trend = since_sell < since_buy 

change_trend = (buy_trend and sell_trend[1]) or (sell_trend and buy_trend[1])

// plot(four_hours_H, title="4H High",  linewidth=2, color=#3c91c2, style=plot.style_linebr, transp=0,
//  show_last=1, trackprice=true)
// plot(four_hours_L, title="4H Low",  linewidth=2, color=#3c91c2, style=plot.style_linebr, transp=0,
//  show_last=1, trackprice=true)

plot(strategy.equity, color=color.blue, linewidth=3, title="Strategy Equity")

// get the entry price
entry_price = valuewhen(buy_trigger or sell_trigger, close, 0)

// SL and TP

SL_price    = buy_trend ? entry_price - StopLoss    : entry_price + StopLoss
is_SL_hit   = buy_trend ? crossunder(low, SL_price) : crossover(high, SL_price) 

TP_price    = buy_trend ? entry_price + TakeProfit  : entry_price - TakeProfit
is_TP_hit   = buy_trend ? crossover(high, TP_price) : crossunder(low, TP_price)

//  Account Margin Management:
f_account_margin_call_cross(_amount)=>
    _return = crossunder(strategy.equity, _amount)

f_account_margin_call(_amount)=>
    _return = strategy.equity <= _amount

is_margin_call_cross    = f_account_margin_call_cross(MarginValue)
is_margin_call          = f_account_margin_call(MarginValue)

plot(strategy.equity, title='strategy.equity', transp=0, linewidth=4)
//plot(barssince(is_margin_call ), title='barssince(is_margin_call)', transp=100)

can_trade = iff(UseMarginCall, not is_margin_call, true)
trade_size  = InitPosition * (not UseLeverage ? 1 : LeverageValue)

// We can take the trade if not liquidated/margined called/rekt

buy_final   = can_trade and buy_trigger and TradeDateIsAllowed
sell_final  = can_trade and sell_trigger and TradeDateIsAllowed

close_long  = buy_trend  and 
 (UseRiskManagement and (is_SL_hit or is_TP_hit)) or sell_trigger

close_short = sell_trend and 
 (UseRiskManagement and (is_SL_hit or is_TP_hit)) or buy_trigger

strategy.entry(TradeId + ' B', long=true, qty=trade_size, when=buy_final)
strategy.entry(TradeId + ' S', long=false, qty=trade_size, when=sell_final)
strategy.close(TradeId + ' B', when=close_long)
strategy.close(TradeId + ' S', when=close_short)

// FULL DEGEN MODE ACTIVATED
// Margin called - Broker closing your account
strategy.close_all(when=is_margin_call)

if UseMarginCall and is_margin_call_cross
    f_print("☠️REKT☠️", is_margin_call_cross)

Detail

https://www.fmz.com/strategy/436653

Last Modified

2023-12-26 16:21:58