andypartridge47

Heikin Ashi Supertrend

Jan 17th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.58 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © jordanfray
  3.  
  4. //@version=5
  5.  
  6. // About This Indicator
  7. // The default settings for this indicator are for BTC/USDT and intended to be used on the 3D timeframe to identify market trends.
  8. // This indicator does a great job identifying whether the market is bullish, bearish, or consolidating.
  9. // This can also work well on lower time frames to help identify when a trend is strong or when it's reversing.
  10.  
  11. strategy("Heikin Ashi Supertrend", overlay=true, max_bars_back=5000, default_qty_type=strategy.cash, default_qty_value=100, initial_capital=100, commission_type=strategy.commission.percent, close_entries_rule="ANY", commission_value=0.035, backtest_fill_limits_assumption=0, process_orders_on_close=true)
  12. import jordanfray/threengine_global_automation_library/89 as bot
  13. import jordanfray/obvFilter/2 as obv
  14.  
  15. // Colors - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  16. green = color.new(#2DBD85,0)
  17. lightGreen = color.new(#2DBD85,90)
  18. red = color.new(#E02A4A,0)
  19. lightRed = color.new(#E02A4A,90)
  20. yellow = color.new(#FFED00,0)
  21. lightYellow = color.new(#FFED00,90)
  22. purple = color.new(#5A00FF,0)
  23. blue = color.new(#0C6090,0)
  24. oceanBlue = color.new(#0C6090,0)
  25. skyBlue = color.new(#00A5FF,0)
  26. lightBlue = color.new(#00A5FF,80)
  27. black = color.new(#000000,0)
  28. gray = color.new(#AAAAAA,0)
  29. white = color.new(#ffffff,0)
  30. transparent = color.new(#000000,100)
  31.  
  32.  
  33. // Tooltips
  34. alertatronSecretTip = "The key that is configured in Alertatron that selects which exchange integration you want to use."
  35. exchangeTooltip = "Pick the exchange that your Alertatron API Secret is configured to. This is used to get the right divider between the pair and the base currency."
  36. exchangeCurrencyOverrideTip = "If you want to use a different base currency than the current chart, you can override it here. Be sure it matches the exchange base currency. \n \n Do not include the currency/symbol divider in this."
  37. exchangeCurrencySymbolTip = "If you want to use a different symbol than the current chart, you can override it here. Be sure it matches the exchange symbol. \n \n Do not include the currency/symbol divider in this."
  38. moveStopToolTip = "If enabled, the stop loss will be moved to a price relative to the average entry price using a percentange as an offset after the price reaches the 'after' threshold. \n 0 = break even.\n \n Default: .1"
  39.  
  40. // Strategy Settings - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  41. strategyIdentifier = input.string(defval="BTCUSDT", title="Strategy Identifier", group="Strategy Information")
  42.  
  43. supertrendAtrPeriod = input.int(defval = 10, step = 1, title = "ATR Length", group = "Supertrend")
  44. supertrendAtrMultiplier = input.float(defval = 2.7, step = 0.1, title = "ATR Multiplier", group = "Supertrend")
  45.  
  46. lotSize = input.float(defval=100, title="Lot Size", group="Entry Settings")
  47. lotSizeType = input.string(defval="Dollars", title="Lot Size Type", options=["Percent Of Account","Dollars", "Contracts"], group="Entry Settings")
  48.  
  49. profitTargetPercent = input.float(defval = 47.0, title = "Profit Target (%)", step = .25, group="Exit Settings")
  50. stopLimitTrigger = input.float(defval=21, title="Stop Limit Trigger (%)", step=0.25, group="Exit Settings")
  51. stopLimitOffset = input.float(defval=0.10, title="Stop Limit Offset (%)", step=0.01, group="Exit Settings")
  52.  
  53. enableMoveStopToBreakEven = input.bool(defval=true, title="Move Stop Loss", group="Move Stop Loss")
  54. moveTo = input.float(defval=1.0, title="to (%)", tooltip=moveStopToolTip)
  55. moveAfter = input.float(defval=4.0, title="after (%)", tooltip=moveStopToolTip)
  56.  
  57. manuallyCloseTrade = input.bool(defval=false, title="Manullay Close Trade?", group="Manually Close Trade")
  58. dateTimeClosed = input.time(defval=timestamp("01 Jan 2022 00:00"), title="Date/Time When Trade Was Closed", group="Manually Close Trade")
  59. priceClosed = input.price(defval=0.0, title="Price Trade Was Closed At", group="Manually Close Trade")
  60.  
  61. // Trade Automation
  62. enableWebhookMessages = input.bool(defval=false, title="Enable Webook Messages", group="Automation Settings")
  63. tradeAutomationExchange = input.string(defval="Phemex", options=["Phemex", "FTX.us"], title="Exchange", group="Automation Settings", tooltip=exchangeTooltip)
  64. tradeAutomationSecret = input.string(defval="haStEthUsdt", title="Alertatron API Secret", group="Automation Settings", tooltip=alertatronSecretTip)
  65. tradeAutomationLeverage = input.int(defval=1, title="Leverage Amount", group="Automation Settings")
  66. tradeAutomationLeverageType = input.string(defval="Cross", title="Leverage Type", options=["Cross", "Isolated"], group="Automation Settings")
  67. tradeAutomationCurrencyOverride = input.string(defval="", title="Currency Override", group="Automation Settings", tooltip=exchangeCurrencyOverrideTip)
  68. tradeAutomationSymbolOverride = input.string(defval="", title="Symbol Override", group="Automation Settings", tooltip=exchangeCurrencySymbolTip)
  69. exchangeQtyDecimals = input.int(defval=3, title="Order QTY Decimal Rounding", group="Automation Settings")
  70.  
  71. showDebugTable = input.bool(defval=false, title="Show Debug Table", group="Testing")
  72.  
  73. // Position States
  74. currentlyInLongPosition = strategy.position_size > 0
  75. currentlyInShortPosition = strategy.position_size < 0
  76. currentlyInAPosition = strategy.position_size != 0
  77.  
  78. // Heikin Ashi Candles
  79. haOpen = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
  80. haHigh = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
  81. haLow = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
  82. haClose = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
  83.  
  84. plotcandle(haOpen < haClose ? haOpen : na, haHigh, haLow, haClose, title='Green Candles', color=green, wickcolor=green, bordercolor=green, display=display.pane)
  85. plotcandle(haOpen >= haClose ? haOpen : na, haHigh, haLow, haClose, title='Red Candles', color=red, wickcolor=red, bordercolor=red, display=display.pane)
  86.  
  87. plot(display=display.status_line, series=haOpen, color=green)
  88. plot(display=display.status_line, series=haHigh, color=green)
  89. plot(display=display.status_line, series=haLow, color=red)
  90. plot(display=display.status_line, series=haClose, color=red)
  91.  
  92. // HA Supertrend
  93. haTrueRange = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, ta.atr(supertrendAtrPeriod)) // math.max(haHigh - haLow, math.abs(haHigh - haClose[1]), math.abs(haLow - haClose[1]))
  94. haSupertrendUp = ((haHigh + haLow) / 2) - (supertrendAtrMultiplier * haTrueRange)
  95. haSupertrendDown = ((haHigh + haLow) / 2) + (supertrendAtrMultiplier * haTrueRange)
  96.  
  97. float trendingUp = na
  98. float trendingDown = na
  99. direction = 0
  100.  
  101. trendingUp := haClose[1] > trendingUp[1] ? math.max(haSupertrendUp,trendingUp[1]) : haSupertrendUp
  102. trendingDown := haClose[1] < trendingDown[1] ? math.min(haSupertrendDown,trendingDown[1]) : haSupertrendDown
  103. direction := haClose > trendingDown[1] ? 1: haClose < trendingUp[1]? -1: nz(direction[1],1)
  104. supertrend = direction == 1 ? trendingUp : trendingDown
  105.  
  106. supertrendUp = ta.change(direction) < 0
  107. supertrendDown = ta.change(direction) > 0
  108.  
  109. // Average Entry Price
  110. float averageEntryPrice = currentlyInAPosition ? strategy.position_avg_price : close
  111. justClosedPosition = ta.change(averageEntryPrice)
  112. barsSinceOpen = currentlyInAPosition ? (bar_index - strategy.opentrades.entry_bar_index(0)) : 0
  113.  
  114. // Profit and Loss
  115. profitAndLoss = strategy.opentrades.profit(0)
  116. profitAndLossPercent = math.round(((close - averageEntryPrice) / averageEntryPrice) * 100,2)
  117.  
  118. // Profit Target
  119. profitTarget = currentlyInLongPosition ? averageEntryPrice + (averageEntryPrice * (profitTargetPercent/100)) : averageEntryPrice - (averageEntryPrice * (profitTargetPercent/100))
  120.  
  121. // Stop Loss Criteria
  122. float stopLossLimitPrice = currentlyInLongPosition ? math.round(averageEntryPrice - (averageEntryPrice * stopLimitTrigger/100),exchangeQtyDecimals) : currentlyInShortPosition ? math.round(averageEntryPrice + (averageEntryPrice * stopLimitTrigger/100),exchangeQtyDecimals) : na
  123. float stopLossTriggerPrice = currentlyInLongPosition ? math.round(stopLossLimitPrice + (stopLossLimitPrice * stopLimitOffset/100),exchangeQtyDecimals) : currentlyInShortPosition ? math.round(stopLossLimitPrice - (stopLossLimitPrice * stopLimitOffset/100),exchangeQtyDecimals) : na
  124.  
  125. // Move Stop Loss
  126. float moveStopLossAfter = currentlyInLongPosition ? math.round(averageEntryPrice + (averageEntryPrice * (moveAfter/100)),exchangeQtyDecimals) : currentlyInShortPosition ? math.round(averageEntryPrice - (averageEntryPrice * (moveAfter/100)),exchangeQtyDecimals) : na
  127. var bool moveStopTriggered = false
  128.  
  129. moveStopLossTo = currentlyInLongPosition ? math.round(averageEntryPrice + (averageEntryPrice * (moveTo/100)),exchangeQtyDecimals) : currentlyInShortPosition ? math.round(averageEntryPrice - (averageEntryPrice * (moveTo/100)),exchangeQtyDecimals) : na
  130.  
  131. if currentlyInLongPosition and high > moveStopLossAfter and enableMoveStopToBreakEven and moveStopTriggered == false
  132. moveStopTriggered := true
  133.  
  134. if currentlyInShortPosition and low < moveStopLossAfter and enableMoveStopToBreakEven and moveStopTriggered == false
  135. moveStopTriggered := true
  136.  
  137. if enableMoveStopToBreakEven and moveStopTriggered
  138. stopLossLimitPrice := moveStopLossTo
  139. stopLossTriggerPrice := currentlyInLongPosition ? math.round(stopLossLimitPrice + (stopLossLimitPrice * stopLimitOffset/100),exchangeQtyDecimals) : currentlyInShortPosition ? math.round(stopLossLimitPrice - (stopLossLimitPrice * stopLimitOffset/100),exchangeQtyDecimals) : na
  140.  
  141. if not currentlyInAPosition or justClosedPosition
  142. moveStopTriggered := false
  143.  
  144. // Entry/Exit Criteria
  145. bool openLong = supertrendDown
  146. bool openShort = supertrendUp
  147. bool exitLong = currentlyInLongPosition and close > profitTarget
  148. bool exitShort = currentlyInShortPosition and close < profitTarget
  149. bool longStopLoss = currentlyInLongPosition and close < stopLossTriggerPrice and barsSinceOpen > 2
  150. bool shortStopLoss = currentlyInShortPosition and close > stopLossTriggerPrice and barsSinceOpen > 2
  151. bool manuallyCloseShort = currentlyInShortPosition and manuallyCloseTrade and time == dateTimeClosed
  152. bool manuallyCloseLong = currentlyInLongPosition and manuallyCloseTrade and time == dateTimeClosed
  153.  
  154. // Alertatron Webhook Messages - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  155. [symbol,baseCurrency] = bot.getPairOverrides(tradeAutomationSymbolOverride,tradeAutomationCurrencyOverride)
  156. [contractCount,entryAmount] = bot.getLotSize(lotSizeType, lotSize, tradeAutomationLeverage, exchangeQtyDecimals)
  157.  
  158. string enterLongAlertMessage = enableWebhookMessages ? bot.getAlertatronMarketEntryMessage(secret=tradeAutomationSecret, symbol=symbol, baseCurrency=baseCurrency, pairDivider=bot.getPairDividerForExchange(tradeAutomationExchange), side="buy", symbolMaxDecimals=exchangeQtyDecimals, leverage=tradeAutomationLeverage, leverageType=tradeAutomationLeverageType, entryPrice=close, amount=lotSize, amountType=lotSizeType, stopTrigger=stopLimitTrigger, stopTriggerType="percent", stopLimitOffset=stopLimitOffset) : "Webhooks disabled by strategy."
  159. string enterShortAlertMessage = enableWebhookMessages ? bot.getAlertatronMarketEntryMessage(secret=tradeAutomationSecret, symbol=symbol, baseCurrency=baseCurrency, pairDivider=bot.getPairDividerForExchange(tradeAutomationExchange), side="sell", symbolMaxDecimals=exchangeQtyDecimals, leverage=tradeAutomationLeverage, leverageType=tradeAutomationLeverageType, entryPrice=close, amount=lotSize, amountType=lotSizeType, stopTrigger=stopLimitTrigger, stopTriggerType="percent", stopLimitOffset=stopLimitOffset) : "Webhooks disabled by strategy."
  160. string exitLongAlertMessage = enableWebhookMessages ? bot.getAlertatronMarketExitMessage(secret=tradeAutomationSecret, symbol=symbol, baseCurrency=baseCurrency, pairDivider=bot.getPairDividerForExchange(tradeAutomationExchange), side="sell") : "Webhooks disabled by strategy."
  161. string exitShortAlertMessage = enableWebhookMessages ? bot.getAlertatronMarketExitMessage(secret=tradeAutomationSecret, symbol=symbol, baseCurrency=baseCurrency, pairDivider=bot.getPairDividerForExchange(tradeAutomationExchange), side="buy") : "Webhooks disabled by strategy."
  162.  
  163. // Long Entries/Exits - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  164. if openLong
  165. strategy.entry(id="Long", direction=strategy.long, qty=contractCount, alert_message=enterLongAlertMessage)
  166.  
  167. if exitLong
  168. strategy.close(id="Long", qty_percent=100, comment="Exit Long", alert_message=exitLongAlertMessage)
  169.  
  170. if longStopLoss
  171. strategy.exit(id=moveStopTriggered ? "Moved Stop" : "Stop Loss", from_entry="Long", qty_percent=100, stop=stopLossLimitPrice)
  172.  
  173. if manuallyCloseLong
  174. strategy.exit(id="Manually Close Long", from_entry="Long", qty_percent=100, stop=priceClosed)
  175.  
  176. // Short Entries/Exits - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  177. if openShort
  178. strategy.entry(id="Short", direction=strategy.short, qty=contractCount, alert_message=enterShortAlertMessage)
  179.  
  180. if exitShort
  181. strategy.close(id="Short", qty_percent=100, comment="Exit Short", alert_message=exitShortAlertMessage)
  182.  
  183. if shortStopLoss
  184. strategy.exit(id=moveStopTriggered ? "Moved Stop" : "Stop Loss", from_entry="Short", qty_percent=100, stop=stopLossLimitPrice)
  185.  
  186. if manuallyCloseShort
  187. strategy.exit(id="Manually Close Short", from_entry="Short", qty_percent=100, stop=priceClosed)
  188.  
  189. // Plots, Lines, and Labels
  190. bodyMiddle = plot((haOpen + haClose) / 2, display=display.none)
  191. downTrend = plot(direction < 0 ? supertrend : na, "Down Trend", color = red, style=plot.style_linebr)
  192. upTrend = plot(direction < 0? na : supertrend, "Up Trend", color = green, style=plot.style_linebr)
  193.  
  194. fill(bodyMiddle, upTrend, lightGreen, fillgaps=false)
  195. fill(bodyMiddle, downTrend, lightRed, fillgaps=false)
  196.  
  197.  
  198. color stopLossColor = red
  199. color stopLossBackgroundColor = red
  200.  
  201. if currentlyInLongPosition and stopLossLimitPrice > averageEntryPrice
  202. stopLossColor := green
  203. stopLossBackgroundColor := lightGreen
  204. else
  205. if currentlyInShortPosition and stopLossLimitPrice < averageEntryPrice
  206. stopLossColor := green
  207. stopLossBackgroundColor := lightGreen
  208. else
  209. stopLossColor := red
  210. stopLossBackgroundColor := lightRed
  211.  
  212. var label stopLossLabel = na
  213. var label moveStopAfterLabel = na
  214. var label averageEntryLabel = na
  215. var label profitAndLossLabel = na
  216. var label profitTargetLabel = na
  217.  
  218. var line stopLossTriggerLine = na
  219. var line moveStopAfterLine = na
  220. var line stopLossLimitLine = na
  221. var line averageEntryLine = na
  222. var line profitTargetLine = na
  223.  
  224. var linefill stopLossBackground = na
  225. var linefill profitTargetBackground = na
  226.  
  227. label.delete(stopLossLabel)
  228. label.delete(moveStopAfterLabel)
  229. label.delete(averageEntryLabel)
  230. label.delete(profitAndLossLabel)
  231. label.delete(profitTargetLabel)
  232.  
  233. line.delete(stopLossTriggerLine)
  234. line.delete(moveStopAfterLine)
  235. line.delete(stopLossLimitLine)
  236. line.delete(averageEntryLine)
  237. line.delete(profitTargetLine)
  238.  
  239. linefill.delete(stopLossBackground)
  240. linefill.delete(profitTargetBackground)
  241.  
  242. string stopLossLabelText = na
  243.  
  244. if moveStopLossAfter and not moveStopTriggered
  245. stopLossLabelText := " Stop Trigger | " + str.format("{0,number,currency}", stopLossTriggerPrice) + "\n" + " Stop Limit | " + str.format("{0,number,currency}" + " ", stopLossLimitPrice) + "\n" + " Moving to " + str.format("{0,number,currency}", moveStopLossTo) + " after " + str.tostring(moveAfter) + "% "
  246. else
  247. stopLossLabelText := " Stop Trigger | " + str.format("{0,number,currency}", stopLossTriggerPrice) + "\n" + " Stop Limit | " + str.format("{0,number,currency}" + " ", stopLossLimitPrice)
  248.  
  249. xOffset = 2 * timeframe.in_seconds(timeframe.period) * 1000
  250.  
  251. profitAndLossLabel := label.new(x=time + xOffset, xloc=xloc.bar_time, y=close, style=label.style_label_left, size=size.normal, color=profitAndLoss > 0 ? green : red, textcolor=white, text=" P&L | " + str.format("{0,number,currency}", profitAndLoss) + " (" + str.tostring(profitAndLossPercent) + "%) ")
  252. averageEntryLabel := label.new(x=time + xOffset, xloc=xloc.bar_time, y=averageEntryPrice, style=label.style_label_left, size=size.normal, color=oceanBlue, textcolor=white, text=" Entry | " + str.format("{0,number,currency}" + " ", averageEntryPrice))
  253. stopLossLabel := label.new(x=time + xOffset, xloc=xloc.bar_time, y=stopLossLimitPrice, style=label.style_label_left, textalign=text.align_left, size=size.normal, color=stopLossColor, textcolor=white, text=stopLossLabelText)
  254. averageEntryLine := line.new(x1=strategy.opentrades.entry_bar_index(0), y1=averageEntryPrice, x2=bar_index, y2=averageEntryPrice, color=oceanBlue, width=2, xloc=xloc.bar_index, style=line.style_solid)
  255. profitTargetLine := line.new(x1=strategy.opentrades.entry_bar_index(0), y1=profitTarget, x2=bar_index, y2=profitTarget, color=green, width=1, xloc=xloc.bar_index, style=line.style_solid)
  256. profitTargetLabel := label.new(x=time + xOffset, xloc=xloc.bar_time, y=profitTarget, style=label.style_label_left, size=size.normal, color=red, textcolor=white, text=" ProfitTarget | " + str.format("{0,number,currency}" + " ", profitTarget))
  257. stopLossTriggerLine := line.new(x1=strategy.opentrades.entry_bar_index(0), y1=stopLossTriggerPrice, x2=bar_index, y2=stopLossTriggerPrice, color=stopLossColor, width=1, xloc=xloc.bar_index, style=line.style_solid)
  258. stopLossLimitLine := line.new(x1=strategy.opentrades.entry_bar_index(0), y1=stopLossLimitPrice, x2=bar_index, y2=stopLossLimitPrice, color=stopLossColor, width=1, xloc=xloc.bar_index, style=line.style_solid)
  259. stopLossBackground := linefill.new(averageEntryLine, stopLossLimitLine, stopLossBackgroundColor)
  260. profitTargetBackground := linefill.new(averageEntryLine, profitTargetLine, lightGreen)
  261.  
  262. if enableMoveStopToBreakEven
  263. moveStopAfterLabel := label.new(x=time + xOffset, xloc=xloc.bar_time, y=moveStopLossAfter, style=label.style_label_left, size=size.normal, color=purple, textcolor=white, text=" Move Stop After " + str.tostring(moveAfter) + "% | " + str.format("{0,number,currency}" + " ", moveStopLossAfter))
  264. moveStopAfterLine := line.new(x1=strategy.opentrades.entry_bar_index(0), y1=moveStopLossAfter, x2=bar_index, y2=moveStopLossAfter, color=purple, width=1, xloc=xloc.bar_index, style=line.style_solid)
  265.  
  266. stopLimitStatus = plot(stopLossLimitPrice, color=stopLossColor, display=display.price_scale)
  267. stopTriggerStatus = plot(stopLossTriggerPrice, color=stopLossColor, display=display.price_scale)
  268. averageEntryStatus = plot(averageEntryPrice, color=oceanBlue, display=display.price_scale)
  269.  
  270. if not currentlyInAPosition
  271. label.delete(stopLossLabel)
  272. label.delete(moveStopAfterLabel)
  273. label.delete(averageEntryLabel)
  274. label.delete(profitAndLossLabel)
  275. label.delete(profitTargetLabel)
  276.  
  277. line.delete(stopLossTriggerLine)
  278. line.delete(moveStopAfterLine)
  279. line.delete(stopLossLimitLine)
  280. line.delete(averageEntryLine)
  281. line.delete(profitTargetLine)
  282.  
  283. linefill.delete(stopLossBackground)
  284. linefill.delete(profitTargetBackground)
  285.  
  286. // Alertatron Automation Status Message
  287. warning_color = enableWebhookMessages == true ? red : green
  288. var table status = table.new(position=position.top_right, columns=2, rows=100, bgcolor=warning_color, border_color=warning_color, border_width=1)
  289. rowCount2 = 0
  290.  
  291. table.cell(status, 0, rowCount2, text=" " + strategyIdentifier, text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  292. table.cell(status, 1, rowCount2, text=" ", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  293. rowCount2 += 1
  294.  
  295. table.cell(status, 0, rowCount2, text=" " + "Webhook Enabled", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  296. table.cell(status, 1, rowCount2, text=str.tostring(enableWebhookMessages) + " ", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  297. rowCount2 += 1
  298.  
  299. table.cell(status, 0, rowCount2, text=" " + "Exchange", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  300. table.cell(status, 1, rowCount2, text=tradeAutomationExchange + " ", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  301. rowCount2 += 1
  302.  
  303. table.cell(status, 0, rowCount2, text=" " + "Code", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  304. table.cell(status, 1, rowCount2, text=tradeAutomationSecret == "" ? "N/A" : tradeAutomationSecret + " ", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  305. rowCount2 += 1
  306.  
  307. table.cell(status, 0, rowCount2, text=" " + "Leverage", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  308. table.cell(status, 1, rowCount2, text=str.tostring(tradeAutomationLeverageType) + " " + str.tostring(tradeAutomationLeverage) + "x", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  309. rowCount2 += 1
  310.  
  311. table.cell(status, 0, rowCount2, text=" " + "Pair", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  312. table.cell(status, 1, rowCount2, text=str.tostring(symbol) + bot.getPairDividerForExchange(tradeAutomationExchange) + str.tostring(baseCurrency), text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  313. rowCount2 += 1
  314.  
  315. lotSizeDisplay = lotSizeType == "Percent Of Account" ? str.format("{0,number,percent}" + " of account ", lotSize/100): str.format("{0,number,currency}", lotSize)
  316.  
  317. table.cell(status, 0, rowCount2, text=" " + "Lot Size", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  318. table.cell(status, 1, rowCount2, text=lotSizeDisplay + " ", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  319. rowCount2 += 1
  320.  
  321. table.cell(status, 0, rowCount2, text=" " + "Account Size", text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  322. table.cell(status, 1, rowCount2, text=str.format("{0,number,currency}" + " ", strategy.initial_capital), text_color=white, text_halign=text.align_left, bgcolor=warning_color, text_size=size.small)
  323. rowCount2 += 1
  324.  
  325. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  326. // D E B U G M O D E - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  327. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  328. if showDebugTable
  329. var table debug = table.new(position=position.bottom_left, columns=2, rows=100, bgcolor=gray, border_color=gray, border_width=2)
  330.  
  331. rowCount = 0
  332. table.cell(debug, 0, rowCount, text="enterLongAlertMessage: ", text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  333. table.cell(debug, 1, rowCount, text=str.tostring(enterLongAlertMessage), text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  334.  
  335. rowCount += 1
  336. table.cell(debug, 0, rowCount, text="enterShortAlertMessage: ", text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  337. table.cell(debug, 1, rowCount, text=str.tostring(enterShortAlertMessage), text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  338.  
  339. rowCount += 1
  340. table.cell(debug, 0, rowCount, text="exitLongAlertMessage: ", text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  341. table.cell(debug, 1, rowCount, text=str.tostring(exitLongAlertMessage), text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  342.  
  343. rowCount += 1
  344. table.cell(debug, 0, rowCount, text="exitShortAlertMessage: ", text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  345. table.cell(debug, 1, rowCount, text=str.tostring(exitShortAlertMessage), text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  346.  
  347. rowCount += 1
  348. table.cell(debug, 0, rowCount, text="moveStopTriggered: ", text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  349. table.cell(debug, 1, rowCount, text=str.tostring(moveStopTriggered), text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  350.  
  351. rowCount += 1
  352. table.cell(debug, 0, rowCount, text="longStopLoss (stopLossTriggerPrice): ", text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  353. table.cell(debug, 1, rowCount, text=str.tostring(longStopLoss) + " | " + str.tostring(stopLossTriggerPrice), text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  354.  
  355. rowCount += 1
  356. table.cell(debug, 0, rowCount, text="barsSinceOpen", text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
  357. table.cell(debug, 1, rowCount, text=str.tostring(barsSinceOpen), text_color=white, text_halign=text.align_left, bgcolor=gray, text_size=size.small)
Advertisement
Add Comment
Please, Sign In to add comment