Momentum Moving Average.pine
Copy
// 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)
Show all 381 lines