Strategy · Pine Script v5 · On the chart

Momentum Adjusted Moving Average by DGT

by PipC· code credited to dgtrd

Calculates a custom moving average (MaMA) by modifying the source price with price momentum, acceleration, and psychological win-rate probability before applying an EMA or SMA.

View on GitHub

GitHub stars8on the repository
Pine versionv5runs as is
Lines of code381
Settings29inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago20 Aug 2022

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

381 lines of Pine Script v5 from TradingView/Momentum Moving Average.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Momentum Moving Average.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dgtrd

// Moving Average, calculated using Momentum, Acceleration and Probability (Psychological Effect)
//
// Feedback Bands, calculated by applying feedback consept common in Electronics Engineering
//
//@version=5
strategy(title="Momentum adjusted Moving Average by DGT", shorttitle="MaMA by DGT", overlay=true)

// -Input ======================================================================================= //

tradeMaxAmount = input.float(title="Trading Amount", step=1000, defval=10000.0)
stopLossPrecent=input.float(title="Stop Loss Precentage %", step=0.5, defval=5)
stopBelowHMA55=input.bool(title="Stop Below HMA55", defval=true)

displayTableOrTips   = input.string(title="Show Table Or Tips", defval="Tips", options=['Table1', 'Table2','Tips'])

source      = input(close, "Source")
length      = input.int(55,    "Moving Average Length", minval = 1)
exponential = input.bool(true)
mLength     = input.int(34,    "Momentum Length"      , minval = 0)
accelFactor = input.bool(true,  "Acceleration Factor")
pLength     = input.int(13,    "Probability Length"   , minval = 1)
offset      = input.int(1,     "Offset"               , minval =-5, maxval = 5)

displayFB   = input.bool(false, "Display Feedback Bands (Daily TimeFrame)")
fbFactor    = input.float(.1,    "Feedback Factor"      , minval = 0, maxval =.2, step = .01)
displayMA   = input.bool(false, "Add Regular Moving Average")

// -Calculation ================================================================================= //

momentum       = ta.change(source  , mLength)
acceleration   = ta.change(momentum, mLength)
probability    = math.sum(ta.change(source) > 0 ? 1 : 0, pLength) / pLength

adjustedSource = accelFactor ?
     source + (momentum + .5 * acceleration) * probability :
     source +  momentum * probability

MaMA = exponential ? ta.ema(adjustedSource,length) : ta.sma(adjustedSource,length)
MA   = displayMA   ? exponential ? ta.ema(source,length) : ta.sma(source,length) : na

negative = displayFB and timeframe.isdaily ? ta.ema(MaMA / math.abs(1 + fbFactor * adjustedSource / MaMA), 5) : na
positive = displayFB and timeframe.isdaily ? ta.ema(MaMA / math.abs(1 - fbFactor * adjustedSource / MaMA), 5) : na

// -Plot ======================================================================================== //

p0 = plot(MaMA,      "Momentum adjusted Moving Average", color = (source > MaMA ? #006400 : #910000), offset=offset, linewidth = 3)
p1 = plot(negative,  "MaMA - Negative Feedback Effect" , color = #910000, offset=offset)
p2 = plot(positive,  "MaMA - Positive Feedback Effect" , color = #006400, offset=offset)
fill(p0, p1, title = "Lower MaMA Band", transp = 95    , color = #910000)
fill(p0, p2, title = "Upper MaMA Band", transp = 95    , color = #006400)

plot(MA,             "Regular Moving Average")

alarm = ta.cross(source, MaMA)
alertcondition(barstate.islast ? alarm[1] : alarm, title="Trading Opportunity", message="MaMA - Probable Trade Opportunity\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}")

// backtest calculations

isBackTest   = input(true,  "═════════ ═ Backtest On/Off ═ ═════════")

//dasCapital   = input.float(10000, "initial capital")
//stopLoss     = input.float(1.,    "Stop Loss %", step=.1) / 100
lenBckTst    = input.float(10,     "Backtest Period (Year)", step = .25)
srcInOut     = input(close,  "Source : Entry/Exit Price Assumption")
lblInOutSL   = input(true,  "Show Entry/Take Profit(Exit)/Stop Loss Labels")

startBckTst  = time > timenow - lenBckTst * 31556952000

//55 HMA
lenH55 = input.int(55, minval=1, title="HMA #H55")

sma_srcH55H = input(high, title="HMA Source #H55 High")
outH55H = ta.hma(sma_srcH55H, lenH55)
plot55H=plot(stopBelowHMA55 ? outH55H : na, title="SMA #H55H", color=color.new(close >= outH55H ? ( outH55H > outH55H[1] ? color.lime : (close > outH55H ? color.white : color.silver) ) :  color.gray, 50), linewidth = 2, style=plot.style_circles)

sma_srcH55L = input(low, title="HMA Source #H55 Low")
outH55L = ta.hma(sma_srcH55L, lenH55)
plot55L=plot(stopBelowHMA55 ? outH55L : na, title="SMA #H55L", color=color.new(close >= outH55L ? ( outH55L > outH55L[1] ? color.lime : (close > outH55L ? color.white : color.silver) ) :  color.gray, 50), linewidth = 1, style=plot.style_circles)

outH55M=(outH55L+outH55H)/2
fill(plot55L, plot55H, color=color.new(close >=  outH55M ? ( outH55M > outH55M[1] ? color.lime : (close > outH55M ? color.white : color.silver) ) :  color.gray, 90), title='HMA 55 High-Low Fill')
//55 HMA

var inTrade    = false
var entryPrice = 0.
var exitPrice  = 0.

if isBackTest

    //var capital    = dasCapital
    var capital    = 0
    var trades     = 0
    var win        = 0
    var loss       = 0
    var tradeQty   = 0

    crossover      = ta.crossover (source, MaMA)
    crossunder     = ta.crossunder(source, MaMA)

    longCondition  = barstate.islast ? crossover [1] : crossover
    shortCondition = barstate.islast ? crossunder[1] : crossunder

    //stopLossCondition = inTrade ? close < entryPrice * (1 - stopLoss) : 0
    stopLossCondition = inTrade ? close < entryPrice * (1 - stopLossPrecent) : 0

    if startBckTst and longCondition and not inTrade
        entryPrice := srcInOut
        inTrade    := true
        trades     := trades + 1
        tradeQty   := math.round(tradeMaxAmount / entryPrice)
        capital    := math.round(tradeQty * srcInOut)

        if lblInOutSL
            label longLabel = label.new(bar_index, low, text="LE"
             ,tooltip="entry price  : " + str.tostring(entryPrice) + "\nentry value : " + str.tostring(capital, "#.##")
             ,color=color.new(color.green,60), style=label.style_label_up, textcolor=color.new(color.white,50), textalign=text.align_center, size=size.tiny)
            strategy.entry("LE", direction=strategy.long, comment="LE", stop=high+syminfo.mintick, qty=tradeMaxAmount/(high)) //*(100-initStopLossPrecent)/100, qty=tradeMaxAmount/high)

    if (shortCondition or stopLossCondition) and inTrade
        //exitPrice  := stopLossCondition ? entryPrice * (1 - stopLoss)  : srcInOut
        exitPrice  := srcInOut
        inTrade    := false
        tradeQty   := 0
        capital    := math.round(capital * (exitPrice / entryPrice))

        if exitPrice > entryPrice
            win    := win  + 1
        else
            loss   := loss + 1

        if lblInOutSL
            txt = stopLossCondition ? "XX" : "TP"
            label shortLabel = label.new(bar_index, high, text=txt
                 ,tooltip="change .......... : " + str.tostring((exitPrice / entryPrice - 1) * 100, "#.##") + "%\nentry/exit price : " + str.tostring(entryPrice) + " / " + str.tostring(exitPrice) + "\nnew capital ..... : " + str.tostring(capital, "#.##")
                 ,color=color.new(color.red,60), style=label.style_label_down, textcolor=color.new(color.white,50), textalign=text.align_center, size=size.tiny)
            strategy.exit("LX", stop=low)

    var years    = (timenow - time) / 31556952000

    var yearsTxt = ""
    var remarks  = ""

    if years < lenBckTst
        lenBckTst := years
        yearsTxt  := str.tostring(lenBckTst, "#.##") + " Years***"
        remarks   := "\n\n*   trade statistics for longs entries only\n**  final value, if trade active displays estimated final value\n*** max available data for selected timeframe : # of bars - " + str.tostring(bar_index)
    else
        yearsTxt  := str.tostring(lenBckTst, "#.##") + " Year(s)"
        remarks   := "\n\n*   trade statistics for longs entries only\n**  final value, if trade open displies estimated final value"


    inTradeTxt = inTrade ? "InTrade" : "Not InTrade"
    estimated  = inTrade ? capital * (close / entryPrice) : capital
    entryTxt   = inTrade ? str.tostring(entryPrice) : "Not InTrade"
    //lastTrdTxt = inTrade ? ", Gain/Loss " + str.tostring((estimated/capital - 1) * 100, "#.##") + "%, Stop Loss " + str.tostring(entryPrice * (1 - stopLoss)) : ""
    lastTrdTxt = inTrade ? ", Gain/Loss " + str.tostring((estimated/tradeMaxAmount - 1) * 100, "#.##") + "%, Stop Loss " + str.tostring(entryPrice * (1 - stopLossPrecent)) : ""

    tooltipTxt = "entires/exit caclulations\n" +
      "-long entry, when price action cross above MaMA\n" +
      "-take profit, when price action cross under MaMA\n" +
      "-stop loss if last value falls by " + str.tostring(stopLossPrecent) + "% of entry price" + remarks

    tradingDetails="☼☾ Trade Statistics*, Trade Period - " + yearsTxt +
          "\n═══════════════════════════════════════" +
          "\nSuccess Ratio ...... : " + str.tostring((win/trades)*100, "#") + "%" + ", # of Trades - " + str.tostring(trades) + ", Win/Loss - " + str.tostring(win) + "/" + str.tostring(loss) +
          "\nGain/Loss % ........ : " + str.tostring((estimated/tradeMaxAmount - 1) * 100, "#") + "%" + ", Initial/Final Value** - " + str.tostring(tradeMaxAmount) + " / " + str.tostring(estimated, "#") +
          "\n\nStatus - " + inTradeTxt + (inTrade?" (" + str.tostring(tradeQty)  +  " Shares)":"") + lastTrdTxt +
          "\n═══════════════════════════════════════" +
          "\nEntry Price/Value . : " + entryTxt + " / " + str.tostring(capital, "#.##") + " " + inTradeTxt +
          "\nLast Price/Value ... : " + str.tostring(close) + " / " + str.tostring(estimated , "#.##") + " " + inTradeTxt

    boxColor=color.new( inTrade ? estimated/tradeMaxAmount > 1 ? color.teal : color.maroon : color.gray, 20)

    if displayTableOrTips == 'Tips'
        label indiLabel = label.new(time, close
             ,text=tradingDetails
             ,tooltip=tooltipTxt
             ,color=boxColor
             ,xloc=xloc.bar_time, style=label.style_label_left, textcolor=color.white, textalign=text.align_left)
        label.set_size(indiLabel, size.small)
        label.set_x(indiLabel, label.get_x(indiLabel) + math.round(ta.change(time)*2))
        label.delete(indiLabel[1])

    if displayTableOrTips == 'Table1'
        var tbl = table.new(position=position.top_right, columns=1, rows=1, bgcolor=color.new(boxColor,40), border_width = 1, border_color=color.black)
        table.cell(tbl, 0, 0, tradingDetails, bgcolor=color.new(boxColor,40), text_size=size.small, text_halign=text.align_left, text_color=color.white)

    if displayTableOrTips == 'Table2'
        var tbl = table.new(position=position.top_right, columns=6, rows=5, bgcolor=color.new(boxColor,60), border_width = 1, border_color=color.black)
        table.cell(tbl, 0, 0, "Trade Period:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 1, 0, yearsTxt, text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 2, 0, "Success Ratio:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 3, 0, str.tostring((win/trades)*100, "#") + "%", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new((win/trades)>0.5?color.green:color.red,50))

        table.cell(tbl, 0, 1, "Gain/Loss %:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 1, 1, str.tostring((estimated/tradeMaxAmount - 1) * 100, "#") + "%", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new((estimated/tradeMaxAmount - 1)>0?color.green:color.red,50))
        table.cell(tbl, 2, 1, "Win/Loss:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 3, 1, str.tostring(win) + "/" + str.tostring(loss), text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new((win/loss)>0.5?color.green:color.red,50))

        table.cell(tbl, 0, 2, "# of Trades:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 1, 2, str.tostring(trades), text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 2, 2, "Initial/Final Value:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 3, 2, str.tostring(tradeMaxAmount) + " / " + str.tostring(estimated, "#"), text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new((estimated/tradeMaxAmount)>0.5?color.green:color.red,50))

        table.cell(tbl, 0, 3, "Status (Shares):", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 1, 3, inTradeTxt + (inTrade?" (" + str.tostring(tradeQty)  +  ")":""), text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(inTrade?color.lime:color.red,50))
        table.cell(tbl, 2, 3, "MaMA/Stop Price:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 3, 3, str.tostring(MaMA, "#.##") + " / " + str.tostring( ((close-MaMA)/close)*100,"#.#") + "%", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(close>MaMA?color.green:color.red,50))


        table.cell(tbl, 0, 4, "Entry Price/Value:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 1, 4, inTrade?str.tostring(entryPrice)+" / " + str.tostring(capital, "#.##"):"-", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(close>entryPrice?color.green:color.red,50))
        table.cell(tbl, 2, 4, "Last Price/Value:", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(boxColor,40))
        table.cell(tbl, 3, 4,  str.tostring(close) + " / " + str.tostring(estimated , "#") + " ", text_size=size.small, text_halign=text.align_left, text_color=color.white, bgcolor=color.new(close>entryPrice?color.green:color.red,50))


        //"\nEntry Price/Value . : " + entryTxt + " / " + str.tostring(capital, "#.##") + " " + inTradeTxt +
        //  "\nLast Price/Value ... : " + str.tostring(close) + " / " + str.tostring(estimated , "#.##") + " " + inTradeTxt

        // table.cell(tbl, 1, 0, str.tostring(_orderPrice, "$#.##"), bgcolor=color.yellow, text_size=size.small)
        // table.cell(tbl, 0, 1, 'Total Cost', bgcolor=#cccccc, text_size=size.small)
        // table.cell(tbl, 1, 1, str.tostring(_orderSize*_orderPrice, "$#.#"), bgcolor=color.yellow, text_size=size.small)
        // table.cell(tbl, 0, 2, 'Order Size', bgcolor=#cccccc, text_size=size.small)
        // table.cell(tbl, 1, 2, str.tostring(_orderSize, "#.#"), bgcolor=color.white, text_size=size.small)


bgcolor(startBckTst and startBckTst != startBckTst[1] ? color.blue : na, title="Bacttest Starting Bar")
plot(inTrade ? entryPrice : exitPrice > 0 ? exitPrice : na, title="Entry/Exit Price Line", color=inTrade ? color.green : color.red, style = plot.style_circles, linewidth = 1)

var label _laTradePrice = na
label.delete(_laTradePrice)
_laTradePrice := label.new(x=time+1, y=(inTrade ? entryPrice : exitPrice > 0 ? exitPrice : na), text=str.format("{1,number,#.#}% above EntryPrice, ${0,number,#.##}",(inTrade ? entryPrice : exitPrice > 0 ? exitPrice : na),(close-(inTrade ? entryPrice : exitPrice > 0 ? exitPrice : na))/close*100), xloc=xloc.bar_time, yloc=yloc.price, color=color.new(inTrade ? color.green : color.red,80), textcolor=color.white, size=size.small, style=label.style_label_left)
//label.set_x(_laTradePrice, label.get_x(_laTradePrice) + math.round(ta.change(time)*1.5))
//label.delete(_laTradePrice[1])

bgColor = source > MaMA ? color.new(color.lime,95) : color.new(color.red,95)
bgcolor(bgColor)

var _stopLossPrecent = 0.03

var label _laMaMA = na
label.delete(_laMaMA)
_laMaMA := label.new(x=time+1, y=MaMA, text=str.format("{1,number,#.#}% above MaMA, ${0,number,#.##}",MaMA,(close-MaMA)/close*100), xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.yellow,80), textcolor=color.white, size=size.small, style=label.style_label_left)
//label.set_x(_laMaMA, label.get_x(_laMaMA) + math.round(ta.change(time)*1.5))
//label.delete(_laMaMA[1])

_stopLossPrecent := (close-MaMA)/close

//Order Entry

// lenD = input.int(100, minval=1, title="EMA #100")
// ema_srcD = input(close, title="EMA Source #100")
// outD = ta.ema(ema_srcD, lenD)
// plot(outD, title="EMA #100", color=outD >= outD[1] ? color.gray : color.maroon, linewidth = 2)

lenE = input.int(200, minval=1, title="EMA #200")
ema_srcE = input(close, title="EMA Source #200")
outE = ta.ema(ema_srcE, lenE)
plot(outE, title="EMA #200", color=outE >= outE[1] ? color.white : color.yellow, linewidth = 2)

var label _laMA200 = na
label.delete(_laMA200)
_laMA200 := label.new(x=time+1, y=outE, text=str.format("{1,number,#.#}% SMA200 ${0,number,#.##}",outE,(close-outE)/close*100), xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.yellow,30), textcolor=color.black, size=size.small, style=label.style_label_left)
// label.set_x(_laSTP, label.get_x(_laSTP) + math.round(ta.change(time)*2))
// label.delete(_laSTP[1])





//Order Entry

//if ( strategy.opentrades == 0) or true
//if startBckTst and longCondition and not inTrade and lblInOutSL
    //strategy.entry("B1", strategy.long, comment="B1", stop= high + syminfo.mintick, qty=tradeMaxAmount/high)
//    strategy.entry("LE", direction=strategy.long, comment="LE", stop=high+syminfo.mintick, qty=tradeMaxAmount/(high)) //*(100-initStopLossPrecent)/100, qty=tradeMaxAmount/high)

//if lblInOutSL and (strategy.position_size > 0) //or (trend_1 > 0 and trend_2 > 0 and trend_3 > 0)
//    strategy.order("LC", direction=strategy.short, qty=strategy.position_size, when=low < strategy.position_avg_price *(100-stopLossPrecent)/100)

//if (shortCondition or stopLossCondition) and inTrade and lblInOutSL
//    strategy.exit("LX", stop=low)
//    var label _laSELL = na
//    label.delete(_laSELL)
//    _laSELL := label.new(x=time, y=xATRTrailingStop, text=str.format("${0,number,#.#} ~ {1,number,#.##}%",xATRTrailingStop, 100*(1-xATRTrailingStop/high)), xloc=xloc.bar_time, yloc=yloc.price, color=color.new(color.red,80), textcolor=color.red, size=size.small, style=label.style_label_lower_left)

//if stopBelowHMA55 and ( close < outH55L)  // or ((recentHigh - close) / recentHigh) > longStopLossPrecent/100
//    strategy.exit("X55L", stop=outH55L)




ShowTradingTable=input.bool(title="Show Trading Table", defval=true)
TradingAccountTotal = input.float(title="Trading Account Total", step=1000, defval=10000.0)
TradingStopLossAllow=input.float(title="Trading Stop Loss Allowance(%)", step=0.1, defval=3)
TradingTableLayout=input.string(title="Trading Table Layout", defval="2x4", options=["1x8","4x2","2x4"])
TradingTablePosition=input.string(title="Trading Table Position", defval=position.top_right, options=[position.bottom_center, position.bottom_left, position.bottom_right, position.middle_center, position.middle_left, position.middle_right, position.top_center, position.top_left, position.top_right])
TradingTableSize=input.string(title="Trading Table Size", defval=size.normal, options=[size.auto, size.huge, size.large, size.normal, size.small, size.tiny])
if ShowTradingTable
    var label _laTradeSize = na
    label.delete(_laTradeSize)
    var _orderPrice = close
    _orderPrice := close
    var _orderSize = math.round(TradingAccountTotal/_orderPrice,0)
    var _stopLossAllow = TradingStopLossAllow/100
    _orderSize := math.round(TradingAccountTotal*_stopLossAllow/_stopLossPrecent/_orderPrice,0)
    if TradingTableLayout == "4x2"
        var tbl = table.new(position=TradingTablePosition, rows=4, columns=2, border_width = 1)
        table.cell(tbl, 0, 0, 'Entry Price', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 1, 0, str.tostring(_orderPrice, "$#.##"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
        table.cell(tbl, 0, 1, 'Total Cost', bgcolor=#cccccc, text_size=TradingTableSize)
        table.cell(tbl, 1, 1, str.tostring(_orderSize*_orderPrice, "$#.#"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
        table.cell(tbl, 0, 2, 'Order Size', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 1, 2, str.tostring(_orderSize, "#.#"), bgcolor=_orderSize>0?color.white:color.red, text_size=TradingTableSize)
        table.cell(tbl, 0, 3, '⛔️Stop Loss', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 1, 3, str.tostring(TradingAccountTotal*_stopLossAllow, "#.#")+" (STP%"+str.tostring(_stopLossPrecent*100, "#.#")+", AC%"+str.tostring(_stopLossAllow*100, "#.#")+")", bgcolor=color.white, text_size=TradingTableSize)
    if TradingTableLayout == "1x8"
        var tbl = table.new(position=TradingTablePosition, rows=1, columns=8, border_width = 1)
        table.cell(tbl, 0, 0, 'Entry Price', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 1, 0, str.tostring(_orderPrice, "$#.##"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
        table.cell(tbl, 2, 0, 'Total Cost', bgcolor=#cccccc, text_size=TradingTableSize)
        table.cell(tbl, 3, 0, str.tostring(_orderSize*_orderPrice, "$#.#"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
        table.cell(tbl, 4, 0, 'Order Size', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 5, 0, str.tostring(_orderSize, "#.#"), bgcolor=_orderSize>0?color.white:color.red, text_size=TradingTableSize)
        table.cell(tbl, 6, 0, '⛔️Stop Loss', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 7, 0, str.tostring(TradingAccountTotal*_stopLossAllow, "#.#")+" (STP%"+str.tostring(_stopLossPrecent*100, "#.#")+", AC%"+str.tostring(_stopLossAllow*100, "#.#")+")", bgcolor=color.white, text_size=TradingTableSize)
    if TradingTableLayout == "2x4"
        var tbl = table.new(position=TradingTablePosition, rows=2, columns=4, border_width = 1)
        table.cell(tbl, 0, 0, 'Entry Price', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 0, 1, str.tostring(_orderPrice, "$#.##"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
        table.cell(tbl, 1, 0, 'Total Cost', bgcolor=#cccccc, text_size=TradingTableSize)
        table.cell(tbl, 1, 1, str.tostring(_orderSize*_orderPrice, "$#.#"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
        table.cell(tbl, 2, 0, 'Order Size', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 2, 1, str.tostring(_orderSize, "#.#"), bgcolor=_orderSize>0?color.white:color.red, text_size=TradingTableSize)
        table.cell(tbl, 3, 0, '⛔️Stop Loss', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
        table.cell(tbl, 3, 1, str.tostring(TradingAccountTotal*_stopLossAllow, "#.#")+" (STP%"+str.tostring(_stopLossPrecent*100, "#.#")+", AC%"+str.tostring(_stopLossAllow*100, "#.#")+")", bgcolor=color.white, text_size=TradingTableSize)




// showTradingTable=input.bool(title="Show Trading Table", defval=true)
// TradingTableLayout=input.string(title="Trading Table Layout", defval="2x3", options=["1x6","6x2","2x3"])
// TradingTablePosition=input.string(title="Trading Table Position", defval=position.top_right, options=[position.bottom_center, position.bottom_left, position.bottom_right, position.middle_center, position.middle_left, position.middle_right, position.top_center, position.top_left, position.top_right])
// TradingTableSize=input.string(title="Trading Table Size", defval=size.normal, options=[size.auto, size.huge, size.large, size.normal, size.small, size.tiny])
// if showTradingTable
//     var label _laTradeSize = na
//     label.delete(_laTradeSize)
//     var _orderPrice = close
//     _orderPrice := close
//     var _orderSize = math.round(tradeMaxAmount/_orderPrice,0)
//     _orderSize := math.round(tradeMaxAmount/_orderPrice,0)
//     //_laTradeSize := label.new(x=time+1, y=ta.highest(high,20), text=str.format("Order Size {0,number,#} | ${1,number,#.##} / ${2,number,#.##}", _orderSize, _orderSize*_orderPrice, _orderPrice), xloc=xloc.bar_time, yloc=yloc.price, color=color.white, textcolor=color.black, size=size.small, style=label.style_label_lower_left)
//     //label.set_x(_laTradeSize, label.get_x(_laTradeSize) + math.round(ta.change(time)*1.5))
//     //label.delete(_laTradeSize[1])
//     if TradingTableLayout == "6x2"
//         var tbl = table.new(position=TradingTablePosition, rows=6, columns=2, border_width = 1)
//         table.cell(tbl, 0, 0, 'Entry Price', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
//         table.cell(tbl, 1, 0, str.tostring(_orderPrice, "$#.##"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
//         table.cell(tbl, 0, 1, 'Total Cost', bgcolor=#cccccc, text_size=TradingTableSize)
//         table.cell(tbl, 1, 1, str.tostring(_orderSize*_orderPrice, "$#.#"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
//         table.cell(tbl, 0, 2, 'Order Size', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
//         table.cell(tbl, 1, 2, str.tostring(_orderSize, "#.#"), bgcolor=color.white, text_size=TradingTableSize)
//     if TradingTableLayout == "1x6"
//         var tbl = table.new(position=TradingTablePosition, rows=1, columns=6, border_width = 1)
//         table.cell(tbl, 0, 0, 'Entry Price', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
//         table.cell(tbl, 1, 0, str.tostring(_orderPrice, "$#.##"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
//         table.cell(tbl, 2, 0, 'Total Cost', bgcolor=#cccccc, text_size=TradingTableSize)
//         table.cell(tbl, 3, 0, str.tostring(_orderSize*_orderPrice, "$#.#"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
//         table.cell(tbl, 4, 0, 'Order Size', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
//         table.cell(tbl, 5, 0, str.tostring(_orderSize, "#.#"), bgcolor=color.white, text_size=TradingTableSize)
//     if TradingTableLayout == "2x3"
//         var tbl = table.new(position=TradingTablePosition, rows=2, columns=3, border_width = 1)
//         table.cell(tbl, 0, 0, 'Entry Price', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
//         table.cell(tbl, 0, 1, str.tostring(_orderPrice, "$#.##"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
//         table.cell(tbl, 1, 0, 'Total Cost', bgcolor=#cccccc, text_size=TradingTableSize)
//         table.cell(tbl, 1, 1, str.tostring(_orderSize*_orderPrice, "$#.#"), bgcolor=color.new(color.yellow, 20), text_size=TradingTableSize)
//         table.cell(tbl, 2, 0, 'Order Size', bgcolor=color.new(#cccccc, 20), text_size=TradingTableSize)
//         table.cell(tbl, 2, 1, str.tostring(_orderSize, "#.#"), bgcolor=color.white, text_size=TradingTableSize)

Overview

Plots the adjusted moving average directly on the price chart alongside optional regular moving averages and feedback bands. Provides input settings for adjusting momentum length, probability lookback, moving average lengths, stop loss percentages, and backtest timeframe limits. Includes options to display an information dashboard table or trading tips.

Details

Published by

PipC on GitHub

Code credit

dgtrd, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Moving averages, Trend, Screeners & dashboards

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Trading Amountfloat10000.0tradeMaxAmount
Stop Loss Precentage %float5stopLossPrecent
Stop Below HMA55booltruestopBelowHMA55
Show Table Or TipsstringTipsdisplayTableOrTips
Sourcesourceclosesource
Moving Average Lengthint55length
exponentialbooltrueexponential
Momentum Lengthint34mLength
Acceleration FactorbooltrueaccelFactor
Probability Lengthint13pLength
Offsetint1offset
Display Feedback Bands (Daily TimeFrame)boolfalsedisplayFB
Show all 29 settings
SettingTypeDefaultVariable
Feedback Factorfloat.1fbFactor
Add Regular Moving AverageboolfalsedisplayMA
═════════ ═ Backtest On/Off ═ ═════════booltrueisBackTest
Backtest Period (Year)float10lenBckTst
Source : Entry/Exit Price AssumptionsourceclosesrcInOut
Show Entry/Take Profit(Exit)/Stop Loss LabelsbooltruelblInOutSL
HMA #H55int55lenH55
HMA Source #H55 Highsourcehighsma_srcH55H
HMA Source #H55 Lowsourcelowsma_srcH55L
EMA #200int200lenE
EMA Source #200sourcecloseema_srcE
Show Trading TablebooltrueShowTradingTable
Trading Account Totalfloat10000.0TradingAccountTotal
Trading Stop Loss Allowance(%)float3TradingStopLossAllow
Trading Table Layoutstring2x4TradingTableLayout
Trading Table Positionstringposition.top_rightTradingTablePosition
Trading Table Sizestringsize.normalTradingTableSize
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

AC- MY SCRIPT1

by hasnocool
106 stars

This strategy plots an Optimized Trend Tracker and a selectable moving-average support line on the price chart. It builds the average as SMA, EMA, WMA, TMA, VAR, WWMA, ZLEMA, or TSF, then offsets long and short stops by a percent of that average. Optional mark

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of AC- MY SCRIPT1

This long-only trend-following strategy combines Ichimoku Kinko Hyo components with higher timeframe moving average filters. It triggers long entries when price trades above a higher timeframe EMA and a bullish Tenkan-Sen cross above Kijun-Sen occurs under fav

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · MPL-2.0 GitHub repository of Ichimoku Kinko Hyo Momentum Strategy

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted 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