Advertisement
andypartridge47

Heikin Ashi Supertrend

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