The resource loading... loading...

[blackcat] L1 MartinGale Scalping Strategy

Author: Zer3192, Date: 2023-10-09 07:06:32
Tags:

The MartinGale strategy is a popular money management strategy commonly used in trading. It is usually used when a trader seeks to recover by increasing the size of a position after each loss. Thus, MartinGale is not a specific strategy, but a generic term for a strategy of buffing, or buffing, positions.

In the Martin Gale strategy, the trader doubles the size of the position after each losing trade. This is done in the hope that a profitable trade will eventually occur to recover the previous loss and generate a profit.

The idea behind the Martin Gale strategy is to use the law of averages. By increasing the size of the position after each loss, the strategy assumes that there will eventually be a profitable trade, which will not only make up for previous losses, but also generate a profit. This may be particularly attractive for traders looking to recover quickly from losses.

However, it is important to note that the Martin Gale strategy carries significant risks. The strategy can result in large losses if the trader experiences a sustained loss phase or lacks sufficient funds. The strategy relies on the assumption that a profitable trade will occur within a certain time frame, which is dangerous because it cannot guarantee that a profitable trade will occur within a certain time frame. Traders considering implementing the Martin Gale strategy should carefully evaluate their risk tolerance and fully understand potential drawbacks. It is important to establish a robust risk management plan to mitigate potential losses. Additionally, traders should be aware that the strategy may not be applicable to all market situations and may need to be adjusted based on market fluctuations.

In summary, the Martin Gale strategy is a money management strategy that involves increasing the size of a position after each loss in an attempt to recover from the loss phase. While it can offer the potential for a quick recovery, there are significant risks that traders should carefully consider before implementing this trading method.

Although not very sympathetic to this transactional view, some people privately said that they were also talking about it, writing a simple 38-line framework, short-line Martin Gale.

The Martin Gale grab-hat strategy is a trading strategy that generates a profit through frequent trading. It uses the intersection of moving averages to generate entry and exit signals. The strategy is implemented using the Pine scripting language of TradingView.

The strategy first defines input variables such as stop-loss and stop-loss levels, and trading patterns ("multi-headed, blank-headed, or two-way"). It then sets a rule that only allows entries when the trading pattern is set to "multi-headed".

The strategy logic uses the cross signal and cross signal definitions of a simple moving average (SMA); it calculates the short-term SMA (SMA3) and the long-term SMA (SMA8), and plots them on a chart. The crossoverSignal and crossunderSignal variables are used to track the occurrence of cross and cross events, while the crossoverState and crossunderState variables determine the state of the cross and cross conditions.

The strategy is executed based on the current holding size. If the holding size is zero (no holding), the strategy checks for a cross and a cross event. If a cross event occurs and the trading pattern allows many heads, then a multi-head position is entered. The entry price, stop-loss price, stop-loss price and stop-loss price are calculated based on the current closing price and the SMA8 value. Similarly, if a cross event occurs and the trading pattern allows a blank head entry, then a blank head position is entered and a corresponding price is held. If there is a multi-head position and the current closing price reaches the stop-loss price or the stop-loss price, and a cross-event occurs, the multi-head position will be leveled. The entry price, stop-loss price, stop-loss price and stop-loss price will be reset to zero.

Similarly, if there is a short position and the current closing price reaches the stop-loss price or the stop-loss price, and a cross event occurs, the short position is leveled and the price variable reset.

The strategy also uses the plotshape function to plot entry and exit points on the chart. It shows an upper triangle pointing to buy entry, a lower triangle pointing to buy exit, a lower triangle pointing to sell entry, and an upper triangle pointing to sell exit.

Overall, the MartinGale shaving strategy aims to capture small profits by taking advantage of the crossover of short-term moving averages. It achieves risk management through stop-loss and stop-loss levels and allows different trading patterns to adapt to different market conditions.


//@version=5
 strategy('[blackcat] L1 MartinGale Scalping Strategy', overlay=true, pyramiding = 5)
 
 // Define input variables
// martingaleMultiplier = input(2, title="加倍倍数")
 takeProfit = input(1.03, title='Take Profit')
 stopLoss = input(0.95, title='Stop Loss')
 inputTradingMode = input.string(defval='Long', options=['Long', 'Short', 'BiDir'], title='Trading Mode')
 
 //The purpose of this rule is to forbid short entries, only long etries will be placed. The rule affects the following function: 'entry'.
strategy.risk.allow_entry_in(inputTradingMode == 'Long' ? strategy.direction.long : inputTradingMode == 'Short' ? strategy.direction.short : strategy.direction.all)

// Define strategy logic 
entryPrice = 0.0
stopPrice = 0.0
takeProfitPrice = 0.0
stopLossPrice = 0.0

// Define SMA crossover and crossunder signals
sma3 = ta.sma(close, 3)
sma8 = ta.sma(close, 8)
plot(sma3, color=color.yellow)
plot(sma8, color=color.fuchsia)
crossoverSignal = ta.crossover(sma3, sma8)
crossunderSignal = ta.crossunder(sma3, sma8)
crossoverState = sma3 > sma8
crossunderState = sma3 < sma8

if strategy.position_size == 0
    if crossoverState
       strategy.entry('Buy',strategy.long)
       entryPrice := close
       stopPrice := close - stopLoss * sma8[1]
       takeProfitPrice := close + takeProfit * sma8[1]
       stopLossPrice := stopPrice
       stopLossPrice
    if crossunderState
        strategy.entry('Sell', strategy.short)
        entryPrice := close
        stopPrice := close + stopLoss *  sma8[1]
        takeProfitPrice := close - takeProfit *  sma8[1]
        stopLossPrice := stopPrice
        stopLossPrice

if strategy.position_size > 0
    if (close > takeProfitPrice or close < stopLossPrice) and crossunderState
        strategy.close('Buy')
        entryPrice := 0.0
        stopPrice := 0.0
        takeProfitPrice := 0.0
        stopLossPrice := 0.0
        stopLossPrice
    else
        strategy.entry('Buy', strategy.long)
        entryPrice := close
        stopPrice := close - stopLoss *  sma8[1]
        takeProfitPrice := close + takeProfit *  sma8[1]
        stopLossPrice := stopPrice
        stopLossPrice

if strategy.position_size < 0
    if (close > takeProfitPrice or close < stopLossPrice) and crossoverState
        strategy.close('Sell')
        entryPrice := 0.0
        stopPrice := 0.0
        takeProfitPrice := 0.0
        stopLossPrice := 0.0
        stopLossPrice
    else
        strategy.entry('Sell', strategy.short)
        entryPrice := close
        stopPrice := close + stopLoss *  sma8[1]
        takeProfitPrice := close - takeProfit *  sma8[1]
        stopLossPrice := stopPrice
        stopLossPrice

// Plot entry and exit points
plotshape(strategy.position_size > 0 and crossoverSignal, 'Buy Entry', shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)
plotshape(strategy.position_size > 0 and (close >= takeProfitPrice or close <= stopLossPrice), 'Buy Exit', shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.small)
plotshape(strategy.position_size < 0 and crossunderSignal, 'Sell Entry', shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.small)
plotshape(strategy.position_size < 0 and (close >= takeProfitPrice or close <= stopLossPrice), 'Sell Exit', shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)

More