Strategy · Pine Script v5 · On the chart

2Mars Strategy

by facejungle

A multi-entry strategy combining a moving average cross, Bollinger Band touches and an optional SuperTrend confirmation.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code709
Settings38inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago16 Oct 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

709 lines of Pine Script v5 from 2mars.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

2mars.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © facejungle
// 16.10.2023
//@version=5
strategy('2Mars strategy [OKX]',
     shorttitle         = '2Mars [OKX]', 
     overlay            = true,
     initial_capital    = 10000,
     pyramiding         = 3,
     currency           = currency.USD,
     default_qty_type   = strategy.percent_of_equity,
     default_qty_value  = 5,
     commission_type    = strategy.commission.percent,
     commission_value   = 0.1,
     margin_long        = 100.0,
     margin_short       = 100.0,
     max_bars_back      = 5000,
     calc_on_every_tick = false 
     )

import facejungle/utils/14 as utils

string GENERAL_GRP = 'General'
float priceSource  = input.source(close, 'Source', group=GENERAL_GRP, display = display.none)
int barsConfirm    = input.int(2, 'Bars confirm', minval=1, step=1, display = display.none, group=GENERAL_GRP)

string ST_GRP                     = "SuperTrend"
bool useSuperTrend                = input.bool(true, title='SuperTrend confirm', tooltip = 'Not a required! Uses for - Confirm entry to position. Stop-loss confirm. Stop-loss price.', display = display.none, group=ST_GRP)
float superTrendFactor            = input.float(4, title="Factor", step=0.1, display = display.none, group=ST_GRP)
int superTrendPeriod              = input.int(20, title="Length", display = display.none, group=ST_GRP)
[supertrend, supertrendDirection] = ta.supertrend(superTrendFactor, superTrendPeriod)

string MA_GRP       = "Moving average"
bool useMaStrategy  = input.bool(true, title='Use MA Cross strategy', tooltip = 'Not a required! Uses for - Entry signal to position when signal and basis line cross (MA Cross strategy). When price cross the MA (add. orders #3).', display = display.none, group=MA_GRP)
string maBasisType  = input.string('sma', 'Basis MA type', ['alma', 'ema', 'dema', 'tema', 'sma', 'smma', 'ssma', 'hma', 'rma', 'swma', 'vwma', 'wma', 'linreg', 'median', 'mom', 'high', 'low', 'medianHigh', 'medianLow', 'percentrank'], group=MA_GRP, display = display.none)
string maSignalType = input.string('sma', 'Signal MA type', ['alma', 'ema', 'dema', 'tema', 'sma', 'smma', 'ssma', 'hma', 'rma', 'swma', 'vwma', 'wma', 'linreg', 'median', 'mom', 'high', 'low', 'medianHigh', 'medianLow', 'percentrank'], group=MA_GRP, display = display.none)
float maRatio       = input.float(1.08, 'Ratio', minval=0.01, step=0.02, group=MA_GRP, display = display.none)
int maMultiplier    = input.int(89, 'Multiplier', minval=1, step=1, group=MA_GRP, tooltip = 'Basis length = Ratio * Multiplier, Signal length = Multiplier', display = display.none)
int maBasisLengh    = math.round(maRatio * maMultiplier)
float maBasis       = utils.maCustomseries(priceSource, maBasisType, maBasisLengh)
float maSignal      = utils.maCustomseries(priceSource, maSignalType, maMultiplier)

string BB_GRP      = "Bollinger Bands"
string bbType      = input.string('wma', 'Type', ['alma', 'ema', 'dema', 'tema', 'sma', 'smma', 'ssma', 'hma', 'rma', 'swma', 'vwma', 'wma', 'linreg', 'median', 'mom', 'high', 'low', 'medianHigh', 'medianLow', 'percentrank'], tooltip = 'Not a required! Uses for - Take profit. Additionals orders #1 and #2. If use ATR stop-loss, lower and upper line #3 used for stop-loss price update.', group=BB_GRP, display = display.none)
int bbLength       = input.int(30, 'length', minval=1, step=1, group=BB_GRP, display = display.none)
float bbMultiplier = input.float(3, minval=1, maxval=50, step=0.1, title="StdDev", group=BB_GRP, display = display.none)
string useBBLong   = input.string('lower3', '↗️ Long orders :', ['lower', 'lower2', 'lower3', 'upper', 'upper2', 'upper3', 'off'], inline='Short orders', display = display.none)
string useBBLong2  = input.string('lower2', ' + ', ['lower', 'lower2', 'lower3', 'upper', 'upper2', 'upper3', 'off'], inline='Short orders', display = display.none)
string useBBLong3  = input.string('off', ' + ', ['basis', 'signal', 'off'], inline='Short orders', display = display.none)
string useBBShort  = input.string('upper3', '↘️ Short orders:', ['upper', 'upper2', 'upper3', 'lower', 'lower2', 'lower3', 'off'], inline='Long orders', display = display.none)
string useBBShort2 = input.string('upper2', ' + ', ['upper', 'upper2', 'upper3', 'lower', 'lower2', 'lower3', 'off'], inline='Long orders', display = display.none)
string useBBShort3 = input.string('off', ' + ', ['basis', 'signal', 'off'], inline='Long orders', display = display.none)

fj_stdev(src, length, mult) =>
    float basis = utils.maCustomseries(src, bbType, length)
    float dev   = mult * ta.stdev(src, length)
    float dev2  = (mult * ta.stdev(src, length)) * 0.618
    float dev3  = (mult * ta.stdev(src, length)) * 1.618
    float dev4  = (mult * ta.stdev(src, length)) * 2.618
    [basis, basis + dev2, basis + dev, basis + dev3, basis + dev4, basis - dev2, basis - dev, basis - dev3, basis - dev4]
[bbMiddle, bbUpper, bbUpper2, bbUpper3, bbUpper4, bbLower, bbLower2, bbLower3, bbLower4] = fj_stdev(priceSource, bbLength, bbMultiplier)

string TP_GRP          = "Take-Profit"
bool useTakeProfit     = input.bool(false, title='Use TP orders', tooltip='Take-profit when the Bollinger band 1, 2, 3 crosses', display = display.none, group=TP_GRP)
bool useTakeProfit2    = input.bool(true, title='Use TP orders 2', display = display.none, group=TP_GRP)
bool useTakeProfit3    = input.bool(true, title='Use TP orders 3', display = display.none, group=TP_GRP)
int takeProfitLongQty  = input.int(5, '↗️ Long qty %', minval=0, maxval=100, step=2, inline='takeQty', display = display.none, group=TP_GRP)
int takeProfitShortQty = input.int(5, '↘️ Short qty %', minval=0, maxval=100, step=2, inline='takeQty', display = display.none, group=TP_GRP)

string LO_GRP                    = "Limit-Orders"
bool useLimitOrder               = input.bool(false, title='Use limit orders', tooltip = 'Calculate for before each entry order. Long: low price - ATR * Multiplier, Short: high price + ATR * Multiplier', display = display.none, group=LO_GRP)
int limitOrderPeriod             = input.int(12, 'Length', minval=1, step=1, tooltip = 'ATR', display = display.none, group=LO_GRP)
float limitOrderMultiplier       = input.float(0.1, 'Multiplier', step=0.1, display = display.none, group=LO_GRP)
series float limitOrderAtr       = ta.atr(limitOrderPeriod)
var series float limitOrderPrice = na
float limitOrderPriceLong        = useLimitOrder ? low - (limitOrderAtr * limitOrderMultiplier) : na
float limitOrderPriceShort       = useLimitOrder ? high + (limitOrderAtr * limitOrderMultiplier) : na

string SL_GRP                  = "Stop-Loss"
string stopLossType            = input.string('ATR', 'Stop-loss:', ['off', 'SuperTrend + ATR', 'ATR', 'StdDev'], tooltip = 'Update with each entry order and take profit #3. SuperTrend + ATR: update with each trend change not in our favor. If use "SuperTrend confirm", then the stop loss will require confirmation trend change.', group=SL_GRP, display = display.none)
int SLAtrPeriod                = input.int(12, title="Length", tooltip = 'ATR and StdDev', display = display.none, group=SL_GRP)
float SLAtrMultiplierLong      = input.float(6, title="Long mult.", step=0.1, tooltip = 'ATR: low - ATR * Multiplier / SuperTrend: SuperTrend - ATR * Multiplier / StdDev: low - StdDev - ATR * Multiplier', display = display.none, group=SL_GRP)
float SLAtrMultiplierShort     = input.float(4.3, title="Short mult.", step=0.1, tooltip = 'ATR: high + ATR * Multiplier / SuperTrend: SuperTrend + ATR * Multiplier / StdDev: high + StdDev + ATR * Multiplier', display = display.none, group=SL_GRP)
series float stopLossAtr       = ta.atr(SLAtrPeriod)
series float stopLossStdDev    = ta.stdev(priceSource, SLAtrPeriod)
bool useFlexStopLoss           = input.bool(false, title='Use flex stop-loss for ATR and StdDev', tooltip = 'If the SuperTrend or MA trend changes not in our favor, then adjusting the stop loss.', display = display.none, group=SL_GRP)
float SLFlexMult               = input.float(0, step=0.1, title="Multiplier", tooltip = 'Long: stop-loss price + (ATR * Multiplier) * Mult. Short: stop-loss price - (ATR * Multiplier) * Mult.', display = display.none, group=SL_GRP)
var series float stopLossPriceLong = na
var series float stopLossPriceShort = na

string ALERT_GRP               = "OKX alerts"
bool useOkxAlert               = input.bool(false, title='OKX Alerts', tooltip = 'Not a required! Uses for - OKX alerts.', display = display.none, group=ALERT_GRP)
string okx_signalToken         = input("signal_token", "Signal Token _______________________________", group = ALERT_GRP, display = display.none)
string okx_entryInvestmentType = input.string("percentage_balance", "Investment Type", options = ["margin", "percentage_balance", "percentage_investment"], display = display.none, group = ALERT_GRP)
float okx_amount               = input.float(5, "Amount", minval = 0.01, display = display.none, group = ALERT_GRP)
int okx_pyramiding             = input.int(3, "Pyramiding", minval = 1, display = display.none, group = ALERT_GRP)
string okx_entryType           = useLimitOrder ? 'limit' : 'market'
string okx_entryPriceOffset    = useLimitOrder ? limitOrderPrice < close ? str.tostring(100 - ((limitOrderPrice / close) * 100)) : str.tostring(100 - (((limitOrderPrice / close) * 100) - 100)) : ''
string msgFreq                 = alert.freq_once_per_bar_close

string msgOpenLong = utils.okxAlertMsg(
 action           = 'ENTER_LONG',
 signalToken      = okx_signalToken,
 orderType        = okx_entryType,
 orderPriceOffset = okx_entryPriceOffset,
 investmentType   = okx_entryInvestmentType,
 amount           = str.tostring(okx_amount)
 )
string msgOpenShort = utils.okxAlertMsg(
 action           = 'ENTER_SHORT',
 signalToken      = okx_signalToken,
 orderType        = okx_entryType,
 orderPriceOffset = okx_entryPriceOffset,
 investmentType   = okx_entryInvestmentType,
 amount           = str.tostring(okx_amount)
 )
string msgTakeProfitLong = utils.okxAlertMsg(
 action           = 'EXIT_LONG',
 signalToken      = okx_signalToken,
 orderType        = "market",
 orderPriceOffset = "",
 investmentType   = "percentage_position",
 amount           = str.tostring(takeProfitLongQty)
 )
string msgTakeProfitShort = utils.okxAlertMsg(
 action           = 'EXIT_SHORT',
 signalToken      = okx_signalToken,
 orderType        = "market",
 orderPriceOffset = "",
 investmentType   = "percentage_position",
 amount           = str.tostring(takeProfitShortQty)
 )
string msgStopLossLong = utils.okxAlertMsg(
 action           = 'EXIT_LONG',
 signalToken      = okx_signalToken,
 orderType        = "market",
 orderPriceOffset = "",
 investmentType   = "percentage_position",
 amount           = "100"
 )
string msgStopLossShort = utils.okxAlertMsg(
 action           = 'EXIT_SHORT',
 signalToken      = okx_signalToken,
 orderType        = "market",
 orderPriceOffset = "",
 investmentType   = "percentage_position",
 amount           = "100"
 )

counterEvent(bool enent, bool enent2) =>
    int scount = 0
    scount := enent and enent2 ? nz(scount[1]) + 1 : 0

barCrossoverCounter(float signalPrice, float basePrice) =>
    bool bcond = signalPrice > basePrice
    int bcount = 0
    bcount := bcond ? nz(bcount[1]) + 1 : 0
barCrossunderCounter(float signalPrice, float basePrice) =>
    bool scond = signalPrice < basePrice
    int scount = 0
    scount := scond ? nz(scount[1]) + 1 : 0

condPositionLong   = strategy.position_size > 0
condSuperTrendLong = supertrendDirection < 0
condMaLong         = barsConfirm == barCrossoverCounter(maSignal, maBasis)
condBasisLong      = barsConfirm == barCrossoverCounter(close, maBasis)
condSignalLong     = barsConfirm == barCrossoverCounter(close, maSignal)
condBBLong1        = barsConfirm == barCrossoverCounter(close, bbLower)
condBBLong2        = barsConfirm == barCrossoverCounter(close, bbLower2)
condBBLong3        = barsConfirm == barCrossoverCounter(close, bbLower3)
condBBLong4        = barsConfirm == barCrossoverCounter(close, bbUpper)
condBBLong5        = barsConfirm == barCrossoverCounter(close, bbUpper2)
condBBLong6        = barsConfirm == barCrossoverCounter(close, bbUpper3)

condPositionShort   = strategy.position_size < 0
condSuperTrendShort = supertrendDirection > 0
condMaShort         = barsConfirm == barCrossunderCounter(maSignal, maBasis)
condBasisShort      = barsConfirm == barCrossunderCounter(close, maBasis)
condSignalShort     = barsConfirm == barCrossunderCounter(close, maSignal)
condBBShort1        = barsConfirm == barCrossunderCounter(close, bbUpper)
condBBShort2        = barsConfirm == barCrossunderCounter(close, bbUpper2)
condBBShort3        = barsConfirm == barCrossunderCounter(close, bbUpper3)
condBBShort4        = barsConfirm == barCrossunderCounter(close, bbLower)
condBBShort5        = barsConfirm == barCrossunderCounter(close, bbLower2)
condBBShort6        = barsConfirm == barCrossunderCounter(close, bbLower3)

condTakeLong1 = ta.crossover(high, bbUpper)  and strategy.position_size > 0
condTakeLong2 = ta.crossover(high, bbUpper2) and strategy.position_size > 0
condTakeLong3 = ta.crossover(high, bbUpper3) and strategy.position_size > 0

condTakeShort1 = ta.crossunder(low, bbLower)  and strategy.position_size < 0
condTakeShort2 = ta.crossunder(low, bbLower2) and strategy.position_size < 0
condTakeShort3 = ta.crossunder(low, bbLower3) and strategy.position_size < 0

condStopLong  = close < stopLossPriceLong  and strategy.position_size > 0
condStopShort = close > stopLossPriceShort and strategy.position_size < 0

openOrder(simple string direction, simple string orderComment='comment') =>
    if direction == 'long'
        if strategy.position_size > 0
            strategy.cancel("short") // cancel short orders
            strategy.close("short", qty_percent = 100, comment = "Close short")
            if useOkxAlert
                alert(msgStopLossShort, msgFreq)
        
        strategy.entry(
         "long",
         strategy.long,
         stop    = stopLossType != 'off' ? stopLossPriceLong : na,
         limit   = useLimitOrder ? limitOrderPrice : na,
         comment = orderComment
         )

        if useOkxAlert and strategy.opentrades < okx_pyramiding
            alert(msgOpenLong, msgFreq)
         
    if direction == 'short'
        if strategy.position_size < 0
            strategy.cancel("long") // cancel long orders
            strategy.close("long", qty_percent = 100, comment = "Close long")
            if useOkxAlert
                alert(msgStopLossLong, msgFreq)
            
        strategy.entry(
         "short",
         strategy.short,
         stop    = stopLossType != 'off' ? stopLossPriceShort : na,
         limit   = useLimitOrder ? limitOrderPrice : na,
         comment = orderComment
         )

        if useOkxAlert and strategy.opentrades < okx_pyramiding
            alert(msgOpenShort, msgFreq)


// TRADE LOGIC
if useSuperTrend
    // LONG ORDERS WITH SuperTrend
    //-> Additionals ordrders #1-2
    if useBBLong == 'lower' or useBBLong2 == 'lower'
        if condBBLong1 and condSuperTrendLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross lower')
    if useBBLong == 'lower2' or useBBLong2 == 'lower2'
        if condBBLong2 and condSuperTrendLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross lower')
    if useBBLong == 'lower3' or useBBLong2 == 'lower3'
        if condBBLong3 and condSuperTrendLong
            limitOrderPrice    := limitOrderPriceLong
            stopLossPriceLong  :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross lower')
    if useBBLong == 'upper' or useBBLong2 == 'upper'
        if condBBLong4 and condSuperTrendLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross upper')
    if useBBLong == 'upper2' or useBBLong2 == 'upper2'
        if condBBLong5 and condSuperTrendLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross upper2')
    if useBBLong == 'upper3' or useBBLong2 == 'upper3'
        if condBBLong6 and condSuperTrendLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross upper3')
    //-> Additionals ordrders #3
    if useBBLong3 == 'basis'
        if condBasisLong and condSuperTrendLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross basis')
    if useBBLong3 == 'signal'
        if condSignalLong and condSuperTrendLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross signal')
    //-> cross ma strategy
    if useMaStrategy and condSuperTrendLong and condMaLong
        limitOrderPrice   := limitOrderPriceLong
        stopLossPriceLong :=
         stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
         stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
         stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
         na
        openOrder('long', '[MA] Long')

    // SHORT ORDERS WITH SuperTrend
    //-> Additionals ordrders #1-2
    if useBBShort == 'upper' or useBBShort2 == 'upper'
        if condBBShort1 and condSuperTrendShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross upper')
    if useBBShort == 'upper2' or useBBShort2 == 'upper2'
        if condBBShort2 and condSuperTrendShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross upper2')
    if useBBShort == 'upper3' or useBBShort2 == 'upper3'
        if condBBShort3 and condSuperTrendShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross upper3')
    if useBBShort == 'lower' or useBBShort2 == 'lower'
        if condBBShort4 and condSuperTrendShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross lower')
    if useBBShort == 'lower2' or useBBShort2 == 'lower2'
        if condBBShort5 and condSuperTrendShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross lower2')
    if useBBShort == 'lower3' or useBBShort2 == 'lower3'
        if condBBShort6 and condSuperTrendShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross lower3')
    //-> Additionals ordrders #3
    if useBBShort3 == 'basis'
        if condBasisShort and condSuperTrendShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross basis')
    if useBBShort3 == 'signal'
        if condSignalShort and condSuperTrendShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross signal')
    //-> cross ma strategy
    if useMaStrategy and condSuperTrendShort and condMaShort
        limitOrderPrice    := limitOrderPriceShort
        stopLossPriceShort := 
         stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
         stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
         stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
         na
        openOrder('short', '[MA] Short')
else

    // LONG ORDERS
    //-> Additionals ordrders #1-2
    if useBBLong == 'lower' or useBBLong2 == 'lower'
        if condBBLong1
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross lower')
    if useBBLong == 'lower2' or useBBLong2 == 'lower2'
        if condBBLong2
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross lower')
    if useBBLong == 'lower3' or useBBLong2 == 'lower3'
        if condBBLong3
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross lower')
    if useBBLong == 'upper' or useBBLong2 == 'upper'
        if condBBLong4
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross upper')
    if useBBLong == 'upper2' or useBBLong2 == 'upper2'
        if condBBLong5
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross upper2')
    if useBBLong == 'upper3' or useBBLong2 == 'upper3'
        if condBBLong6
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross upper3')
    //-> Additionals ordrders #3
    if useBBLong3 == 'basis'
        if condBasisLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross basis')
    if useBBLong3 == 'signal'
        if condSignalLong
            limitOrderPrice   := limitOrderPriceLong
            stopLossPriceLong :=
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
             stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
             na
            openOrder('long', 'long, cross signal')
    //-> cross ma strategy
    if useMaStrategy and condMaLong
        limitOrderPrice   := limitOrderPriceLong
        stopLossPriceLong :=
         stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
         stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
         stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
         na
        openOrder('long', '[MA] Long')

    // SHORT ORDERS
    //-> Additionals ordrders #1-2
    if useBBShort == 'upper' or useBBShort2 == 'upper'
        if condBBShort1
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross upper')
    if useBBShort == 'upper2' or useBBShort2 == 'upper2'
        if condBBShort2
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross upper2')
    if useBBShort == 'upper3' or useBBShort2 == 'upper3'
        if condBBShort3
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross upper3')
    if useBBShort == 'lower' or useBBShort2 == 'lower'
        if condBBShort4
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross lower')
    if useBBShort == 'lower2' or useBBShort2 == 'lower2'
        if condBBShort5
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross lower2')
    if useBBShort == 'lower3' or useBBShort2 == 'lower3'
        if condBBShort6
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross lower3')
    //-> Additionals ordrders #3
    if useBBShort3 == 'basis'
        if condBasisShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross basis')
    if useBBShort3 == 'signal'
        if condSignalShort
            limitOrderPrice    := limitOrderPriceShort
            stopLossPriceShort := 
             stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
             stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
             na
            openOrder('short', 'short, cross signal')
    //-> cross ma strategy
    if useMaStrategy and condMaShort
        limitOrderPrice    := limitOrderPriceShort
        stopLossPriceShort := 
         stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
         stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
         stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
         na
        openOrder('short', '[MA] Short')


//TAKEPROFIT LOGIC
if useTakeProfit
    if condTakeLong1
        if useOkxAlert
            alert(msgTakeProfitLong, msgFreq)
        strategy.close("long", qty_percent = takeProfitLongQty, comment = "[TP] long")
    if condTakeShort1
        if useOkxAlert
            alert(msgTakeProfitShort, msgFreq)
        strategy.close("short", qty_percent = takeProfitShortQty, comment = "[TP] short")
if useTakeProfit2
    if condTakeLong2
        if useOkxAlert
            alert(msgTakeProfitLong, msgFreq)
        strategy.close("long", qty_percent = takeProfitLongQty, comment = "[TP] long2")
    if condTakeShort2
        if useOkxAlert
            alert(msgTakeProfitShort, msgFreq)
        strategy.close("short", qty_percent = takeProfitShortQty, comment = "[TP] short2")
if useTakeProfit3
    if condTakeLong3
        if useOkxAlert
            alert(msgTakeProfitLong, msgFreq)
        stopLossPriceLong :=
         stopLossType == 'SuperTrend + ATR' ? supertrend[1] - (stopLossAtr * SLAtrMultiplierLong) :
         stopLossType == 'ATR'              ? low - (stopLossAtr * SLAtrMultiplierLong) :
         stopLossType == 'StdDev'           ? low - stopLossStdDev - (stopLossAtr * SLAtrMultiplierLong) :
         na
        strategy.close("long", qty_percent = takeProfitLongQty, comment = "[TP] long3")
    if condTakeShort3
        if useOkxAlert
            alert(msgTakeProfitShort, msgFreq)
        stopLossPriceShort := 
         stopLossType == 'SuperTrend + ATR' ? supertrend[1] + (stopLossAtr * SLAtrMultiplierShort) :
         stopLossType == 'ATR'              ? high + (stopLossAtr * SLAtrMultiplierShort) :
         stopLossType == 'StdDev'           ? high + stopLossStdDev + (stopLossAtr * SLAtrMultiplierShort) :
         na
        strategy.close("short", qty_percent = takeProfitShortQty, comment = "[TP] short3")

// STOP-LOSS LOGIC
if stopLossType == 'SuperTrend + ATR'
    if barCrossoverCounter(supertrendDirection, 0) == 1 and condPositionLong
        stopLossPriceLong := supertrend[1] - (stopLossAtr * SLAtrMultiplierLong)
    if barCrossunderCounter(supertrendDirection, 0) == 1 and condPositionShort
        stopLossPriceShort := supertrend[1] + (stopLossAtr * SLAtrMultiplierShort)

if useFlexStopLoss
    if stopLossType == 'ATR' or stopLossType == 'StdDev'
        if counterEvent(condPositionLong, condSuperTrendShort) == 1
            stopLossPriceLong := stopLossPriceLong + (stopLossAtr * SLAtrMultiplierLong) * SLFlexMult
        if counterEvent(condPositionLong, condMaShort) == 1
            stopLossPriceLong := stopLossPriceLong + (stopLossAtr * SLAtrMultiplierLong) * SLFlexMult
            
        if counterEvent(condPositionShort, condSuperTrendLong) == 1
            stopLossPriceShort := stopLossPriceShort - (stopLossAtr * SLAtrMultiplierShort) * SLFlexMult
        if counterEvent(condPositionShort, condMaLong) == 1
            stopLossPriceShort := stopLossPriceShort - (stopLossAtr * SLAtrMultiplierShort) * SLFlexMult

if stopLossType != 'off'
    if useSuperTrend
        if condStopLong and condSuperTrendShort
            strategy.cancel("long") // cancel long orders
            strategy.close("long", qty_percent = 100, comment = "[SL] long")
            if useOkxAlert
                alert(msgStopLossLong, msgFreq)
        if condStopShort and condSuperTrendLong
            strategy.cancel("short") // cancel short orders
            strategy.close("short", qty_percent = 100, comment = "[SL] short")
            if useOkxAlert
                alert(msgStopLossShort, msgFreq)
    else
        if condStopLong
            strategy.cancel("long") // cancel long orders
            strategy.close("long", qty_percent = 100, comment = "[SL] long")
            if useOkxAlert
                alert(msgStopLossLong, msgFreq)
        if condStopShort
            strategy.cancel("short") // cancel short orders
            strategy.close("short", qty_percent = 100, comment = "[SL] short")
            if useOkxAlert
                alert(msgStopLossShort, msgFreq)


// PLOT
colorGreen   = #00ff08cc
colorGreen2  = #00ff0863
colorRed     = #ff0000d4
colorRed2    = #ff000071
colorPurple  = #8400ff23
colorPurple2 = #8400ff6e
colorPurple3 = #8400ff09
colorOrange  = #f57b00c7

// SuperTrend
plot(condSuperTrendLong ? supertrend : na, "[SuperTrend] Up direction", color=colorGreen2, linewidth=3, style=plot.style_steplinebr, display=useSuperTrend ? display.pane : display.none)
plot(condSuperTrendShort ? supertrend : na, "[SuperTrend] Down direction", color=colorRed2, linewidth=3, style=plot.style_steplinebr, display=useSuperTrend ? display.pane : display.none)

// Moving Averages
basis = plot(maBasis, "[MA] Basis", color = maSignal > maBasis ? colorGreen2 : colorRed2, linewidth=1, style=plot.style_line, display=display.pane)
signal = plot(maSignal, "[MA] Signal", color = maSignal > maBasis ? colorGreen2 : colorRed2, linewidth=1, style=plot.style_line, display=display.pane)
plot(ta.crossover(maSignal, maBasis) ? maBasis : na, "[MA] Long signal", color=colorGreen, style = plot.style_circles, linewidth = 4, display=display.pane)
plot(ta.crossunder(maSignal, maBasis) ? maBasis : na, "[MA] Short signal", color=colorRed, style = plot.style_circles, linewidth = 4, display=display.pane)
fill(basis, signal, title = "[MA] Background", color = maSignal > maBasis ? colorGreen2 : colorRed2, display = display.all)

// stoploss
bool plotCondStopLossLong = useSuperTrend ? condPositionLong and condSuperTrendShort : condPositionLong
bool plotCondStopLossShort = useSuperTrend ? condPositionShort and condSuperTrendLong : condPositionShort
plot(condPositionLong? stopLossPriceLong : na, "Stop-loss price: Long", color=plotCondStopLossLong ? colorRed : colorOrange, style = plot.style_linebr, linewidth = 2, display=stopLossType == 'off' ? display.none : display.pane)
plot(condPositionShort? stopLossPriceShort : na, "Stop-loss price: Short", color=plotCondStopLossShort ? colorRed : colorOrange, style = plot.style_linebr, linewidth = 2, display=stopLossType == 'off' ? display.none : display.pane)

// Bollinger bands
u1 = plot(bbUpper, "[BB] Upper", color=colorPurple, display = display.pane)
l1 = plot(bbLower, "[BB] Lower", color=colorPurple, display = display.pane)
u2 = plot(bbUpper2, "[BB] Upper 2", color=colorPurple, display = display.pane)
l2 = plot(bbLower2, "[BB] Lower 2", color=colorPurple, display = display.pane)
u3 = plot(bbUpper3, "[BB] Upper 2", color=colorPurple, display = display.pane)
l3 = plot(bbLower3, "[BB] Lower 2", color=colorPurple, display = display.pane)
fill(u1, l1, title = "[BB] Background 1-1", color=colorPurple3, display = display.all)
fill(u2, l2, title = "[BB] Background 2-2", color=colorPurple3, display = display.all)
fill(u3, l3, title = "[BB] Background 3-3", color=colorPurple3, display = display.all)

var currentPosition = 'flat'
currentPosition := strategy.position_size > 0 ? 'long' : 'short'
if strategy.position_size == 0
    currentPosition := 'flat'
var positionTable = table.new(position = position.top_right, columns = 2, rows = 2)
table.cell(table_id = positionTable, column = 0, row = 0, text = "Position:", bgcolor=colorPurple2, text_color=color.white)
table.cell(table_id = positionTable, column = 1, row = 0, text = currentPosition, bgcolor=strategy.opentrades == 0 ? colorPurple2 : strategy.position_size < 0 ? colorRed2 : colorGreen, text_color=color.white)
table.cell(table_id = positionTable, column = 0, row = 1, text = "Amount:", bgcolor=colorPurple2, text_color=color.white)
table.cell(table_id = positionTable, column = 1, row = 1, text =str.tostring(strategy.position_size), bgcolor=colorPurple2, text_color=color.white)

Overview

Extra orders can open when price reaches chosen outer bands, up to three entries in the same direction. Take-profit levels use standard deviation multiples, and the stop loss is based on ATR or SuperTrend plus ATR. Limit-order entries are optional. Settings cover MA types and lengths, band type and width, take-profit sizes and stop multipliers. It draws on the price chart and uses 5 percent of equity per order by default.

Details

Published by

facejungle on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Volatility & bands, Moving averages

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
SourcesourceclosepriceSource
Bars confirmint2barsConfirm
SuperTrend confirmbooltrueuseSuperTrend
Factorfloat4superTrendFactor
Lengthint20superTrendPeriod
Use MA Cross strategybooltrueuseMaStrategy
Basis MA typestringsmamaBasisType
Signal MA typestringsmamaSignalType
Ratiofloat1.08maRatio
Multiplierint89maMultiplier
TypestringwmabbType
lengthint30bbLength
Show all 38 settings
SettingTypeDefaultVariable
StdDevfloat3bbMultiplier
↗️ Long orders :stringlower3useBBLong
+ stringlower2useBBLong2
+ stringoffuseBBLong3
↘️ Short orders:stringupper3useBBShort
+ stringupper2useBBShort2
+ stringoffuseBBShort3
Use TP ordersboolfalseuseTakeProfit
Use TP orders 2booltrueuseTakeProfit2
Use TP orders 3booltrueuseTakeProfit3
↗️ Long qty %int5takeProfitLongQty
↘️ Short qty %int5takeProfitShortQty
Use limit ordersboolfalseuseLimitOrder
Lengthint12limitOrderPeriod
Multiplierfloat0.1limitOrderMultiplier
Stop-loss:stringATRstopLossType
Lengthint12SLAtrPeriod
Long mult.float6SLAtrMultiplierLong
Short mult.float4.3SLAtrMultiplierShort
Use flex stop-loss for ATR and StdDevboolfalseuseFlexStopLoss
Multiplierfloat0SLFlexMult
OKX AlertsboolfalseuseOkxAlert
Signal Token _______________________________stringsignal_tokenokx_signalToken
Investment Typestringpercentage_balanceokx_entryInvestmentType
Amountfloat5okx_amount
Pyramidingint3okx_pyramiding
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce
106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy
104 stars

This overlay strategy combines a Chandelier Exit with a zero-lag least squares moving average. Although the header mentions Heikin Ashi candles, the calculations use ordinary closes. An ATR trailing stop sets long and short levels, and direction flips when pri

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of Chandelier Exit & ZLSMA Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers