Pine Script v5 · Strategy
3ngine Global Boilerplate
A Pine Script v5 strategy built on Highest (high) and Lowest (low). It has 8 order rules and no entry of its own. Exits use a stop loss and a profit target. Each trade is one contract and pays 0.035% commission. 25 settings; defaults include Starting ladering in at 0, set stop loss at 0 and Cancel Unfiller Orders After 10.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does 3ngine Global Boilerplate repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- Does 3ngine Global Boilerplate run in Pine Script v6?
- Not tested
- The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L5:C0: no source was supplied for the library 'jordanfray/threengine_global_automation_library/10'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download.
- Does 3ngine Global Boilerplate use a stop loss?
- Yes
- strategy.exit sets a stop on line 165, 167, 189, 191.
- Does 3ngine Global Boilerplate run in Zeal Terminal?
- No
- Not yet: it imports the library jordanfray/threengine_global_automation_library/10, whose source is not available here, so it does not run here
Review
What a careful reader of this script would point out, found by checking the source.
-
Check
2 settings do nothing
“Cancel Unfiller Orders After”, “Stop Loss (%)” are declared but never read.
-
Note
1 setting has no label
In the settings dialog adxMaximum (line 70) shows an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Strategy Settings | |||
| Starting ladering in at Select where you want to start laddering in from. | 0 | price | StrategyEntryPrice side Ladder Start Line |
| set stop loss atSelect where you want your stop loss to be. | 0 | price | side longStopLoss shortStopLoss Stop Loss Line |
| Cancel Unfiller Orders AfterWhen the position reaches a certain percent profit, you can cancel any unfiller orders. | 10 | float | unused |
| Show Strategy Status Box | true | bool | line 261 |
| Filters | |||
| Use EMA Filter | false | bool | closeAboveEmaMacroFilter closeBelowEmaMacroFilter EMA Macro Filter |
| indent+"Timeframe" | 240 | timeframe | macroEma |
| indent+"Length" | 100 | int · min 1 · step 10 | macroEma |
| indent+"Type" | EMA | string · options ["EMA", "SMA", "RMA", "WMA"] | macroEma |
| indent+"Source" | close | source | macroEma |
| Use ADX Filter | false | bool | adxInRange |
| indent+"DI Length" | 14 | int | adx |
| indent+"ADX Smoothing" | 14 | int | adx |
| indent+"ADX Must Be Between"+" " | 30 | int | adxInRange |
| Adx Maximum (no label in the script) | 100 | int | adxInRange |
| Use Time Session Filter | false | bool | withTime |
| indent+"Only Take Trades Between" | 0800-1700 | session | withTime |
| indent+"Strategy Start" | timestamp("01 Jan 2022 00:00") | time | beyondStartTime startTimeLine |
| Entry Settings | |||
| Ladder In RungsWhen the criteria for entering a strategy is met, the order can placed using a single order or split across multiple ladder orders. Select 1 to place a single order. | 2 | int · min 1 · max 6 · step 1 | longEntryPrices longEntryContractCounts longEntryOrderNames shortEntryPrices shortEntryContractCounts shortEntryOrderNames line 145 line 169 line 276 line 291 line 305 line 318 line 331 line 344 line 358 line 372 line 386 line 399 line 412 line 425 |
| Ladder In Step Spacing (%)The percent distance between the orders. Ex: If the strategy produces an entry signal to buy at $20,000 and the strategy is configured to ladder into the position across 4 steps, setting the Ladder In Step Spacing to 1% would split the entry into 4 orders at $20,000, $19,800, $19,600, and $19,400. | 2 | float · step .25 | longEntryPrices longEntryContractCounts longEntryOrderNames shortEntryPrices shortEntryContractCounts shortEntryOrderNames |
| Exit Settings | |||
| Ladder Out RungsWhen the criteria for exiting a strategy is met, the order can placed using a single order or split across multiple ladder orders. Select 1 to place a single order. | 2 | int · min 1 · max 6 · step 1 | longExitPrices longExitQuantities longExitOrderNames shortExitPrices shortExitQuantities shortExitOrderNames ladderOutQty exit ladderOutID exit ladderOutID exit ladderOutID exit ladderOutID line 159 line 164 line 183 line 188 line 478 line 491 line 504 line 516 line 528 line 540 line 553 line 566 line 579 line 591 line 603 line 615 |
| Ladder Out Step Spacing (%)The percent distance between the orders. Ex: If the strategy produces an exit signal to sell at $21,000 and the strategy is configured to ladder out of the position across 2 steps, setting the Ladder Out Step Spacing to 1% would split the entry into 2 orders at $21,000, $21,210. | 2 | float · step .25 | longExitPrices longExitQuantities longExitOrderNames shortExitPrices shortExitQuantities shortExitOrderNames |
| Take Profit (%) | 20 | float · step 0.25 | longProfitTarget shortProfitTarget |
| Stop Loss (%) | 10 | float · step 0.25 | unused |
| Start Trailing After (%) | 10 | float · step 0.25 | longTrailingTrigger shortTrailingTrigger |
| Trail Behind (%) | 10 | float · step 0.25 | longStopLoss shortStopLoss |
What it calculates
- Highesthigh, bar_index == 0 ? 5000 : barsSinceEntry
longRunUp · line 124 - Lowestlow, bar_index == 0 ? 5000 : barsSinceEntry
shortRunDown · line 128
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
The script has 95 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| order ladderID long | ladderInCriteria | On | 153 |
| cancel ladderID | cancelUnfilledLongEntries | On | 156 |
| Exit ladderOutID stop and limit | x == ladderOutSteps - 1 | On | 165 |
| Exit ladderOutID stop and limit | x == ladderOutSteps - 1 | On | 167 |
| order ladderID short | ladderInCriteria | On | 177 |
| cancel ladderID | cancelUnfilledShortEntries | On | 180 |
| Exit ladderOutID stop and limit | x == ladderOutSteps - 1 | On | 189 |
| Exit ladderOutID stop and limit | x == ladderOutSteps - 1 | On | 191 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.
- ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationreads realtime-only state. Live values can differ from history.
- ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Similar scripts
Indicators and strategies built from the same calculations.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Alex Days HiLo Rajib by 14rajib | highest lowest | v4 strategy | No trades on this market | ||
| Donchian Strat EXMO by pskoroplas | highest lowest | v4 strategy | +12.1% | 22 | 68.0% |
| Average Highest High and Lowest Low Swinger Strategy by exlux99 | lowest highest | v4 strategy | +6.4% | 20 | 49.6% |
| Highest High and Lowest Low Channel Strategy by ceyhun | highest lowest | v5 strategy | −3.7% | 26 | 7.9% |
| Donchian Channels System [racer8] by racer8 | highest lowest | v4 strategy | −3.2% | 36 | 43.6% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L5:C0: no source was supplied for the library 'jordanfray/threengine_global_automation_library/10'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © jordanfray-//@version=5+//@version=6strategy(title="Boilerplate", overlay=true, max_bars_back=5000, commission_type=strategy.commission.percent, close_entries_rule="ANY", commission_value=0.035, backtest_fill_limits_assumption=0, calc_on_order_fills=true, process_orders_on_close=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | No It imports the library jordanfray/threengine_global_automation_library/10, whose source is not available here, so it does not run here | Not measured | |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 153, 177) so the engine trades the way the script says.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © jordanfray//@version=5strategy(title="Boilerplate", overlay=true, max_bars_back=5000, commission_type=strategy.commission.percent, close_entries_rule="ANY", commission_value=0.035, backtest_fill_limits_assumption=0, calc_on_order_fills=true, process_orders_on_close=true)import jordanfray/threengine_global_automation_library/10 as bot // This is a required library// A B O U T T H E B O I L E R P L A T E// This strategy is desisnged to bring consistency to your strategies. It includes a macro EMA filter for filtering out countertrend trades, // an ADX filter to help filter out chop, a session filter to filter out trades outside of desired timeframe, alert messages setup for automation, // laddering in/out of trades (up to 6 rungs), trailing take profit, and beautiful visuals for each entry. There are comments throughout the // strategy that provide further instructions on how to use the boilerplate strategy. This strategy uses more_margin_trade_automation_library // throughout and must be included at the top of the strategy using import [path to latest version] as bot. This allows you to use dot notation // to access functions in the library - EX: bot.orderCurrentlyExists().// H O W T O U S E T H I S S T R A T E G Y// 1 Add your inputs// 2 Add your calculations// 3 Add your entry criteria// 3.1 Add your criteria to strategySpecificLongConditions (this gets combined with boilerplate conditions in longConditionsMet)// 3.2 Add your criteria to strategySpecificShortConditions (this gets combined with boilerplate conditions in shortConditionsMet)// 3.4 Set your desired entry price (calculated on every bar unless stored as a static variable) to longEntryPrice and shortEntryPrice. // Default is the bar "close". This will be the FIRST ladder if using laddering capabilities. If you pick 1 for "Ladder In Rungs" // this will be the only entry. // 4 Plot anything you want to overlay on the chart in addition to the boilerplate plots and labels. Included in boilerplate: // Average entry price (blue), stop loss (red), trailing stop (red/green), profit target (green).// Indenting Classs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -indent = " "// Colors - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -oceanBlue = color.new(#0C6090,0)skyBlue = color.new(#00A5FF,0)green = color.new(#2DBD85,0)nevisShallows = color.new(#00FFD4,0)red = color.new(#E02A4A,0)lightBlue = color.new(#00A5FF,80)lightGreen = color.new(#2DBD85,80)lightRed = color.new(#E02A4A,80)lightYellow = color.new(#FFF900,80)white = color.new(#ffffff,0)black = color.new(#191B20,0)gray = color.new(#AAAAAA,0)lightGray = color.new(#AAAAAA,90)transparent = color.new(#000000,100)// Input Groups - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -groupOneTitle = "Strategy Settings "groupTwoTitle = "Filters"groupThreeTitle = "Entry Settings"groupFourTitle = "Exit Settings"// Tooltips - This is where all of the tooltips are defined to keep the code clean below - - - - - - - - - - - - - - - - - - - - - - - - - - - -startTip = "Select where you want to start laddering in from."stopLossTip = "Select where you want your stop loss to be."ladderInToolTip = "Enable this to use the laddering settings below."cancelEntryToolTip = "When the position reaches a certain percent profit, you can cancel any unfiller orders."ladderInStepsTip = "When the criteria for entering a strategy is met, the order can placed using a single order or split across multiple ladder orders. Select 1 to place a single order."ladderInStepSpacingTip = "The percent distance between the orders. Ex: If the strategy produces an entry signal to buy at $20,000 and the strategy is configured to ladder into the position across 4 steps, setting the Ladder In Step Spacing to 1% would split the entry into 4 orders at $20,000, $19,800, $19,600, and $19,400."ladderOutStepsTip = "When the criteria for exiting a strategy is met, the order can placed using a single order or split across multiple ladder orders. Select 1 to place a single order."ladderOutStepSpacingTip = "The percent distance between the orders. Ex: If the strategy produces an exit signal to sell at $21,000 and the strategy is configured to ladder out of the position across 2 steps, setting the Ladder Out Step Spacing to 1% would split the entry into 2 orders at $21,000, $21,210."// Strategy Specific Inputs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - start = input.price(defval=0, title="Starting ladering in at ", confirm=true, group=groupOneTitle, tooltip=startTip)stop = input.price(defval=0, title="set stop loss at", confirm=true, group=groupOneTitle, tooltip=stopLossTip) // This strategy uses a price based stop loss. You can use a percent based stop loss as part of the boilerplate settings below.cancelUnfilledOrdersAfter = input.float(defval=10, title="Cancel Unfiller Orders After", confirm=false, group=groupOneTitle, tooltip=cancelEntryToolTip)/100 // This strategy uses a price based stop loss. You can use a percent based stop loss as part of the boilerplate settings below.// Boilerplate Inputs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -showStrategyStatusBox = input.bool(defval=true, title="Show Strategy Status Box", group=groupOneTitle)enableMacroEmaFilter = input.bool(defval=false, title="Use EMA Filter", group=groupTwoTitle)macroEmaTimeframe = input.timeframe(defval="240", title=indent+"Timeframe", group=groupTwoTitle)macroEmaLength = input.int(defval=100, minval=1, step=10, title=indent+"Length", group=groupTwoTitle)macroEmaType = input.string(defval="EMA", options = ["EMA", "SMA", "RMA", "WMA"], title=indent+"Type", group=groupTwoTitle)macroEmaSource = input.source(defval=close, title=indent+"Source", group=groupTwoTitle)enableAdxFilter = input.bool(defval=false, title="Use ADX Filter", group=groupTwoTitle)diLength = input.int(defval=14, title=indent+"DI Length", group=groupTwoTitle)adxSmoothing = input.int(defval=14, title=indent+"ADX Smoothing", group=groupTwoTitle)adxMinumum = input.int(defval=30, title=indent+"ADX Must Be Between"+" ", inline="adxGroup", group=groupTwoTitle)adxMaximum = input.int(defval=100, title="", inline="adxGroup", group=groupTwoTitle)useTimeFilter = input.bool(defval=false, title="Use Time Session Filter", group=groupTwoTitle)timeSession = input.session(defval="0800-1700", title=indent+"Only Take Trades Between", group=groupTwoTitle)startTime = input.time(defval=timestamp("01 Jan 2022 00:00"), confirm=true, title=indent+"Strategy Start", group=groupTwoTitle) // Remove "confirm=true" from this line if you don't want to pick a time when adding the strategy to the chartladderInSteps = input.int(defval=2, minval=1, maxval=6, step=1, title="Ladder In Rungs", group=groupThreeTitle, tooltip=ladderInStepsTip)ladderInStepSpacingPercent = input.float(defval=2, title="Ladder In Step Spacing (%)", step=.25, group=groupThreeTitle, tooltip=ladderInStepSpacingTip)ladderOutSteps = input.int(defval=2, minval=1, maxval=6, step=1, title="Ladder Out Rungs", group=groupFourTitle, tooltip=ladderOutStepsTip)ladderOutStepSpacingPercent = input.float(defval=2, title="Ladder Out Step Spacing (%)", step=.25, group=groupFourTitle, tooltip=ladderOutStepSpacingTip)/100takeProfitVal = input.float(defval=20, title="Take Profit (%)", step=0.25, group=groupFourTitle)/100stopLossVal = input.float(defval=10, title="Stop Loss (%)", step=0.25, group=groupFourTitle)/100 // This sample strategy does not use a percent based stop loss. Instead it uses a price based stop loss above. startTrailingAfter = input.float(defval=10, title="Start Trailing After (%)", step=0.25, group=groupFourTitle)/100trailBehind = input.float(defval=10, title="Trail Behind (%)", step=0.25, group=groupFourTitle)/100// Boilerplate Calculations - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - macroEma = request.security(syminfo.tickerid, macroEmaTimeframe, bot.taGetEma(macroEmaType, macroEmaSource, macroEmaLength)[barstate.isrealtime ? 1 : 0])closeAboveEmaMacroFilter = enableMacroEmaFilter ? close > macroEma : truecloseBelowEmaMacroFilter = enableMacroEmaFilter ? close < macroEma : trueadx = bot.taGetAdx(diLength, adxSmoothing)adxInRange = enableAdxFilter ? adx >= adxMinumum and adx <= adxMaximum : truewithTime = useTimeFilter ? bot.isBetweenTwoTimes(timeSession,"GMT-6") : truebool beyondStartTime = time > startTimecurrentlyInLongPosition = strategy.position_size > 0currentlyInShortPosition = strategy.position_size < 0currentlyInAPosition = strategy.position_size != 0StrategyEntryPrice = start // Set this to the price the strategy should start laddering in at[ladderStartPrice,ladderStartedOnBar] = bot.getLockedLadderStart(StrategyEntryPrice)barsSinceEntry = currentlyInAPosition ? bar_index - ladderStartedOnBar + 1 : 1avgPrice = bot.getAveragePriceOfFilledLadders()// Boilerplate Entry CriteriaboilerplateLongConditionsMet = beyondStartTime and closeAboveEmaMacroFilter and adxInRange and withTime and not currentlyInShortPositionboilerplateShortConditionsMet = beyondStartTime and closeAboveEmaMacroFilter and adxInRange and withTime and not currentlyInLongPosition// Strategy Specific Calculations - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var string side = start > stop ? "buy" : "sell"// Strategy Specific Entry CriteriaalreadyClosedTrades = strategy.closedtrades > 0strategySpecificLongConditions = side == "buy" and not alreadyClosedTradesstrategySpecificShortConditions = side == "sell" and not alreadyClosedTrades// Combined Entry Conditions Array ConstructionlongConditionsMet = strategySpecificLongConditions and boilerplateLongConditionsMetshortConditionsMet = strategySpecificShortConditions and boilerplateShortConditionsMetlongLadder1Criteria = not bot.orderCurrentlyExists("Long - 1") and strategy.opentrades == 0 and longConditionsMetlongLadder2Criteria = not bot.orderCurrentlyExists("Long - 2") and strategy.opentrades == 1 and longConditionsMetlongLadder3Criteria = not bot.orderCurrentlyExists("Long - 3") and strategy.opentrades == 2 and longConditionsMetlongLadder4Criteria = not bot.orderCurrentlyExists("Long - 4") and strategy.opentrades == 3 and longConditionsMetlongLadder5Criteria = not bot.orderCurrentlyExists("Long - 5") and strategy.opentrades == 4 and longConditionsMetlongLadder6Criteria = not bot.orderCurrentlyExists("Long - 6") and strategy.opentrades == 5 and longConditionsMetbool[] longLadderInCriterias = array.from(longLadder1Criteria,longLadder2Criteria,longLadder3Criteria, longLadder4Criteria, longLadder5Criteria, longLadder6Criteria)shortLadder1Criteria = not bot.orderCurrentlyExists("Short - 1") and strategy.opentrades == 0 and shortConditionsMetshortLadder2Criteria = not bot.orderCurrentlyExists("Short - 2") and strategy.opentrades == 1 and shortConditionsMetshortLadder3Criteria = not bot.orderCurrentlyExists("Short - 3") and strategy.opentrades == 2 and shortConditionsMetshortLadder4Criteria = not bot.orderCurrentlyExists("Short - 4") and strategy.opentrades == 3 and shortConditionsMetshortLadder5Criteria = not bot.orderCurrentlyExists("Short - 5") and strategy.opentrades == 4 and shortConditionsMetshortLadder6Criteria = not bot.orderCurrentlyExists("Short - 6") and strategy.opentrades == 5 and shortConditionsMetbool[] shortLadderInCriterias = array.from(shortLadder1Criteria,shortLadder2Criteria,shortLadder3Criteria, shortLadder4Criteria, shortLadder5Criteria, shortLadder6Criteria)// Stop Criteria - "When" orders will exit due to hitting stop loss or trailing stop - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -longRunUp = ta.highest(high, bar_index == 0 ? 5000 : barsSinceEntry)longTrailingTrigger = avgPrice + (avgPrice * startTrailingAfter)// longStopLoss = currentlyInLongPosition and longRunUp > longTrailingTrigger ? longRunUp - (longRunUp * trailBehind) : strategy.position_avg_price * (1.0 - stopLossVal) // Use this for a percent based stop losslongStopLoss = currentlyInLongPosition and longRunUp > longTrailingTrigger ? longRunUp - (longRunUp * trailBehind) : stopshortRunDown = ta.lowest(low, bar_index == 0 ? 5000 : barsSinceEntry)shortTrailingTrigger = avgPrice - (avgPrice * startTrailingAfter)// shortStopLoss = currentlyInShortPosition and shortRunDown < shortTrailingTrigger ? shortRunDown + (shortRunDown * trailBehind) : strategy.position_avg_price * (1 + stopLossVal) // Use this for a percent based stop lossshortStopLoss = currentlyInShortPosition and shortRunDown < shortTrailingTrigger ? shortRunDown + (shortRunDown * trailBehind) : stop // Use this for a price based stop loss// Take Profit - The point in which the first ladder entry will take profit based on average entry price - - - - - - - - - - - - - - - - - - - - - - - - - -float longProfitTarget = avgPrice * (1 + takeProfitVal)float shortProfitTarget = avgPrice * (1 - takeProfitVal)takeProfitConditions = strategy.openprofit > 0// Criteria for Canceling unfilled orderscancelUnfilledLongEntries = false // close > strategy.position_avg_price + (strategy.position_avg_price * cancelUnfilledOrdersAfter)cancelUnfilledShortEntries = false // close < strategy.position_avg_price - (strategy.position_avg_price * cancelUnfilledOrdersAfter)// Orders - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -[longEntryPrices, longEntryContractCounts, longEntryOrderNames] = bot.getLadderInSteps(side="buy", amount="10000", ladderRungs=ladderInSteps, ladderStart=ladderStartPrice, ladderStop=na, stepSpacingPercent=ladderInStepSpacingPercent)[shortEntryPrices, shortEntryContractCounts, shortEntryOrderNames] = bot.getLadderInSteps(side="sell", amount="10000", ladderRungs=ladderInSteps, ladderStart=ladderStartPrice, ladderStop=na, stepSpacingPercent=ladderInStepSpacingPercent)[longExitPrices, longExitQuantities, longExitOrderNames] = bot.getLadderOutSteps("sell", longProfitTarget, ladderOutSteps, ladderOutStepSpacingPercent)[shortExitPrices, shortExitQuantities, shortExitOrderNames] = bot.getLadderOutSteps("buy", shortProfitTarget, ladderOutSteps, ladderOutStepSpacingPercent)// Long Laddersfor i = 0 to ladderInSteps - 1 by 1 ladderPrice = array.get(longEntryPrices,i) ladderQty = array.get(longEntryContractCounts,i) ladderID = array.get(longEntryOrderNames,i) ladderInCriteria = array.get(longLadderInCriterias,i) ladderAlertMessage = bot.getStrategyAlertMessage("MM1", bot.getChartSymbol(), bot.getBaseCurrency(), "buy", ladderPrice, ladderPrice, str.tostring(ladderQty), longProfitTarget, longProfitTarget, longStopLoss, longStopLoss, false) if ladderInCriteria strategy.order(id=ladderID, direction=strategy.long, limit=ladderPrice, qty=ladderQty, alert_message=ladderAlertMessage) if cancelUnfilledLongEntries strategy.cancel(id=ladderID) if currentlyInLongPosition for x = 0 to ladderOutSteps - 1 by 1 ladderOutID = ladderID + " | Exit " + str.tostring(x + 1) ladderOutPrice = array.get(longExitPrices,x) ladderOutQty = ladderQty / ladderOutSteps if x == ladderOutSteps - 1 strategy.exit(id=ladderOutID, from_entry=ladderID, qty_percent=100, limit=ladderOutPrice, stop=longStopLoss) else strategy.exit(id=ladderOutID, from_entry=ladderID, qty=ladderOutQty, limit=ladderOutPrice, stop=longStopLoss)// Short Laddersfor i = 0 to ladderInSteps - 1 by 1 ladderPrice = array.get(shortEntryPrices,i) ladderQty = array.get(shortEntryContractCounts,i) ladderID = array.get(shortEntryOrderNames,i) ladderInCriteria = array.get(shortLadderInCriterias,i) ladderAlertMessage = bot.getStrategyAlertMessage("MM1", bot.getChartSymbol(), bot.getBaseCurrency(), "sell", ladderPrice, ladderPrice, str.tostring(ladderQty), longProfitTarget, longProfitTarget, longStopLoss, longStopLoss, false) if ladderInCriteria strategy.order(id=ladderID, direction=strategy.short, limit=ladderPrice, qty=ladderQty, alert_message=ladderAlertMessage) if cancelUnfilledShortEntries strategy.cancel(id=ladderID) if currentlyInShortPosition for x = 0 to ladderOutSteps - 1 by 1 ladderOutID = ladderID + " | Exit " + str.tostring(x + 1) ladderOutPrice = array.get(shortExitPrices,x) ladderOutQty = ladderQty / ladderOutSteps if x == ladderOutSteps - 1 strategy.exit(id=ladderOutID, from_entry=ladderID, qty_percent=100, limit=ladderOutPrice, stop=shortStopLoss) else strategy.exit(id=ladderOutID, from_entry=ladderID, qty=ladderOutQty, limit=ladderOutPrice, stop=shortStopLoss)// Strategy Plots, Lines, and LabelsstartLine = plot(series=start, title="Ladder Start Line", color=currentlyInLongPosition ? transparent : green, linewidth=1, editable=false)stopLinep = plot(series=stop, title="Stop Loss Line", color=currentlyInLongPosition ? transparent : red, linewidth=1, editable=false)var line startTimeLine = navar line stopTimeLine = naline.delete(startTimeLine)line.delete(stopTimeLine)stopTime = strategy.closedtrades.exit_time(0)stopBarIndex = strategy.closedtrades.exit_bar_index(0)startTimeLine := line.new(x1=startTime, y1=0, x2=startTime, y2=10000000, color=gray, width=1, xloc=xloc.bar_time)// Boilerplate Plots, Lines, and LabelsadxPlot = plot(adx, title="ADX", editable=false, color=nevisShallows)macroEmaPlot = plot(enableMacroEmaFilter ? macroEma: na, title="EMA Macro Filter", linewidth=2, color=white, editable=false)float ladderIn1Price = currentlyInLongPosition ? array.get(longEntryPrices,0) : array.get(shortEntryPrices,0)float ladderIn2Price = currentlyInLongPosition ? array.get(longEntryPrices,1) : array.get(shortEntryPrices,1)float ladderIn3Price = currentlyInLongPosition ? array.get(longEntryPrices,2) : array.get(shortEntryPrices,2)float ladderIn4Price = currentlyInLongPosition ? array.get(longEntryPrices,3) : array.get(shortEntryPrices,3)float ladderIn5Price = currentlyInLongPosition ? array.get(longEntryPrices,4) : array.get(shortEntryPrices,4)float ladderIn6Price = currentlyInLongPosition ? array.get(longEntryPrices,5) : array.get(shortEntryPrices,5)ladderInLineColor = currentlyInAPosition ? oceanBlue : transparentladderIn1PriceLine = plot(series=ladderIn1Price, style=plot.style_stepline, color=ladderInLineColor, linewidth=1, editable=false)ladderIn2PriceLine = plot(series=ladderIn2Price, style=plot.style_stepline, color=ladderInLineColor, linewidth=1, editable=false)ladderIn3PriceLine = plot(series=ladderIn3Price, style=plot.style_stepline, color=ladderInLineColor, linewidth=1, editable=false)ladderIn4PriceLine = plot(series=ladderIn4Price, style=plot.style_stepline, color=ladderInLineColor, linewidth=1, editable=false)ladderIn5PriceLine = plot(series=ladderIn5Price, style=plot.style_stepline, color=ladderInLineColor, linewidth=1, editable=false)ladderIn6PriceLine = plot(series=ladderIn6Price, style=plot.style_stepline, color=ladderInLineColor, linewidth=1, editable=false)float ladderOut1Price = currentlyInLongPosition ? array.get(longExitPrices,0) : array.get(shortExitPrices,0)float ladderOut2Price = currentlyInLongPosition ? array.get(longExitPrices,1) : array.get(shortExitPrices,1)float ladderOut3Price = currentlyInLongPosition ? array.get(longExitPrices,2) : array.get(shortExitPrices,2)float ladderOut4Price = currentlyInLongPosition ? array.get(longExitPrices,3) : array.get(shortExitPrices,3)float ladderOut5Price = currentlyInLongPosition ? array.get(longExitPrices,4) : array.get(shortExitPrices,4)float ladderOut6Price = currentlyInLongPosition ? array.get(longExitPrices,5) : array.get(shortExitPrices,5)ladderOutLineColor = currentlyInAPosition ? green : transparentladderOut1PriceLine = plot(series=ladderOut1Price, style=plot.style_stepline_diamond, color=ladderOutLineColor, linewidth=1, editable=false)ladderOut2PriceLine = plot(series=ladderOut2Price, style=plot.style_stepline_diamond, color=ladderOutLineColor, linewidth=1, editable=false)ladderOut3PriceLine = plot(series=ladderOut3Price, style=plot.style_stepline_diamond, color=ladderOutLineColor, linewidth=1, editable=false)ladderOut4PriceLine = plot(series=ladderOut4Price, style=plot.style_stepline_diamond, color=ladderOutLineColor, linewidth=1, editable=false)ladderOut5PriceLine = plot(series=ladderOut5Price, style=plot.style_stepline_diamond, color=ladderOutLineColor, linewidth=1, editable=false)ladderOut6PriceLine = plot(series=ladderOut6Price, style=plot.style_stepline_diamond, color=ladderOutLineColor, linewidth=1, editable=false)averageEntryLine = plot(series=avgPrice, title="Average Entry Price", style=plot.style_stepline_diamond, linewidth=1, color=currentlyInAPosition ? skyBlue : transparent, editable=false)longTrailingStopLine = plot(longStopLoss, title="Long Trailing Stop", style=plot.style_stepline_diamond, editable=false, linewidth=1, color=currentlyInLongPosition ? longStopLoss > strategy.position_avg_price ? green : red : transparent)shortTrailingStopLine = plot(shortStopLoss, title="Short Trailing Stop", style=plot.style_stepline_diamond, editable=false, linewidth=1, color=currentlyInShortPosition ? shortStopLoss < strategy.position_avg_price ? green : red : transparent)//shortRunDownLine = plot(shortRunDown, style=plot.style_stepline, editable=false, linewidth=2, color=currentlyInShortPosition ? green : transparent)//longRunUpLine = plot(longRunUp, style=plot.style_stepline, editable=false, linewidth=2, color=currentlyInLongPosition ? green : transparent)// Strategy Dashboard Panel - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -long1LadderFilled = bot.orderCurrentlyExists("Long - 1")long2LadderFilled = bot.orderCurrentlyExists("Long - 2")long3LadderFilled = bot.orderCurrentlyExists("Long - 3")long4LadderFilled = bot.orderCurrentlyExists("Long - 4")long5LadderFilled = bot.orderCurrentlyExists("Long - 5")long6LadderFilled = bot.orderCurrentlyExists("Long - 6")short1LadderFilled = bot.orderCurrentlyExists("Short - 1")short2LadderFilled = bot.orderCurrentlyExists("Short - 2")short3LadderFilled = bot.orderCurrentlyExists("Short - 3")short4LadderFilled = bot.orderCurrentlyExists("Short - 4")short5LadderFilled = bot.orderCurrentlyExists("Short - 5")short6LadderFilled = bot.orderCurrentlyExists("Short - 6")longTP1Hit = bot.orderAlreadyClosedSince("Long - 1 | Exit 1", barsSinceEntry)longTP2Hit = bot.orderAlreadyClosedSince("Long - 1 | Exit 2", barsSinceEntry)longTP3Hit = bot.orderAlreadyClosedSince("Long - 1 | Exit 3", barsSinceEntry)longTP4Hit = bot.orderAlreadyClosedSince("Long - 1 | Exit 4", barsSinceEntry)longTP5Hit = bot.orderAlreadyClosedSince("Long - 1 | Exit 5", barsSinceEntry)longTP6Hit = bot.orderAlreadyClosedSince("Long - 1 | Exit 6", barsSinceEntry)shortTP1Hit = bot.orderAlreadyClosedSince("Short - 1 | Exit 1", barsSinceEntry)shortTP2Hit = bot.orderAlreadyClosedSince("Short - 1 | Exit 2", barsSinceEntry)shortTP3Hit = bot.orderAlreadyClosedSince("Short - 1 | Exit 3", barsSinceEntry)shortTP4Hit = bot.orderAlreadyClosedSince("Short - 1 | Exit 4", barsSinceEntry)shortTP5Hit = bot.orderAlreadyClosedSince("Short - 1 | Exit 5", barsSinceEntry)shortTP6Hit = bot.orderAlreadyClosedSince("Short - 1 | Exit 6", barsSinceEntry)if showStrategyStatusBox and longConditionsMet or shortConditionsMet // Global Dashboard Settings var string checkMark = " ✓" var string fontSize = size.normal cellBgColor = lightGray var float quantityOfAllFilledOrders = 0 var table panel = table.new(position=position.bottom_right, columns=3, rows=100, bgcolor=cellBgColor, border_color=lightGray, border_width=1) rowCount = 0 table.cell(panel, 0, rowCount, text=" " + "Ladder In", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text="Price", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text="Contracts" + " ", text_color=black, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Long Ladder 1 if currentlyInLongPosition and ladderInSteps >= 1 int ladderArrayPosition = 0 string entryID = long1LadderFilled ? str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(longEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(longEntryContractCounts,ladderArrayPosition)) color = long1LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Long Ladder 2 if currentlyInLongPosition and ladderInSteps >= 2 int ladderArrayPosition = 1 string entryID = long2LadderFilled ? str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(longEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(longEntryContractCounts,ladderArrayPosition)) color = long2LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Long Ladder 3 if currentlyInLongPosition and ladderInSteps >= 3 int ladderArrayPosition = 2 string entryID = long3LadderFilled ? str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(longEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(longEntryContractCounts,ladderArrayPosition)) color = long3LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Long Ladder 4 if currentlyInLongPosition and ladderInSteps >= 4 int ladderArrayPosition = 3 string entryID = long4LadderFilled ? str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(longEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(longEntryContractCounts,ladderArrayPosition)) color = long4LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Long Ladder 5 if currentlyInLongPosition and ladderInSteps >= 5 int ladderArrayPosition = 4 string entryID = long5LadderFilled ? str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(longEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(longEntryContractCounts,ladderArrayPosition)) color = long5LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Long Ladder 6 if currentlyInLongPosition and ladderInSteps >= 6 int ladderArrayPosition = 5 string entryID = long6LadderFilled ? str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(longEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(longEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(longEntryContractCounts,ladderArrayPosition)) color = long6LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Short Ladder 1 if currentlyInShortPosition and ladderInSteps >= 1 int ladderArrayPosition = 0 string entryID = short1LadderFilled ? str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(shortEntryContractCounts,ladderArrayPosition)) table.cell(panel, 0, rowCount, text=" " + entryID, text_color=short1LadderFilled ? green : black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=short1LadderFilled ? green : black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=short1LadderFilled ? green : black, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Short Ladder 2 if currentlyInShortPosition and ladderInSteps >= 2 int ladderArrayPosition = 1 string entryID = short2LadderFilled ? str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(shortEntryContractCounts,ladderArrayPosition)) color = short2LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Short Ladder 3 if currentlyInShortPosition and ladderInSteps >= 3 int ladderArrayPosition = 2 string entryID = short3LadderFilled ? str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(shortEntryContractCounts,ladderArrayPosition)) color = short3LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Short Ladder 4 if currentlyInShortPosition and ladderInSteps >= 4 int ladderArrayPosition = 3 string entryID = short4LadderFilled ? str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(shortEntryContractCounts,ladderArrayPosition)) color = short4LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Short Ladder 5 if currentlyInShortPosition and ladderInSteps >= 5 int ladderArrayPosition = 4 string entryID = short5LadderFilled ? str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(shortEntryContractCounts,ladderArrayPosition)) color = short5LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Short Ladder 6 if currentlyInShortPosition and ladderInSteps >= 6 int ladderArrayPosition = 5 string entryID = short6LadderFilled ? str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) + checkMark : str.tostring(array.get(shortEntryOrderNames,ladderArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortEntryPrices,ladderArrayPosition)) string quantity = str.format("{0,number,#.#####}", array.get(shortEntryContractCounts,ladderArrayPosition)) color = short6LadderFilled ? green : black table.cell(panel, 0, rowCount, text=" " + entryID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) quantityOfAllFilledOrders += array.get(longEntryContractCounts,ladderArrayPosition) rowCount += 1 // Average Entry Price if currentlyInAPosition table.cell(panel, 0, rowCount, text=" " + "", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=size.tiny) table.cell(panel, 1, rowCount, text="", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=size.tiny) table.cell(panel, 2, rowCount, text=" ", text_color=black, text_halign=text.align_right, bgcolor=cellBgColor, text_size=size.tiny) rowCount += 1 string avgPriceString = str.format("{0,number,currency}", strategy.position_avg_price) table.cell(panel, 0, rowCount, text=" " + "Avg Price", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text="", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=avgPriceString + " ", text_color=black, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Total Contracts // if currentlyInAPosition // string totalContracts = str.format("{0,number,#.#####}", quantityOfAllFilledOrders) // table.cell(panel, 0, rowCount, text=" " + "Total Contracts", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) // table.cell(panel, 1, rowCount, text="", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) // table.cell(panel, 2, rowCount, text=strategy.open + " ", text_color=black, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) // rowCount += 1 if currentlyInAPosition table.cell(panel, 0, rowCount, text=" " + "", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=size.tiny) table.cell(panel, 1, rowCount, text="", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=size.tiny) table.cell(panel, 2, rowCount, text=" ", text_color=black, text_halign=text.align_right, bgcolor=cellBgColor, text_size=size.tiny) rowCount += 1 table.cell(panel, 0, rowCount, text=" " + "Ladder Out", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text="Price", text_color=black, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text="% of Order" + " ", text_color=black, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Long Ladder Out 1 if currentlyInLongPosition and ladderOutSteps >= 1 int ladderOutArrayPosition = 0 string exitID = str.tostring(array.get(longExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(longExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(longExitQuantities,ladderOutArrayPosition)/100) color = longTP1Hit ? green : black table.cell(panel, 0, rowCount, text=longTP1Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Long Ladder Out 2 if currentlyInLongPosition and ladderOutSteps >= 2 int ladderOutArrayPosition = 1 string exitID = str.tostring(array.get(longExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(longExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(longExitQuantities,ladderOutArrayPosition)/100) color = longTP2Hit ? green : black table.cell(panel, 0, rowCount, text=longTP2Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Long Ladder Out 3 if currentlyInLongPosition and ladderOutSteps >= 3 int ladderOutArrayPosition = 2 string exitID = str.tostring(array.get(longExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(longExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(longExitQuantities,ladderOutArrayPosition)/100) color = longTP3Hit ? green : black table.cell(panel, 0, rowCount, text=longTP3Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Long Ladder Out 4 if currentlyInLongPosition and ladderOutSteps >= 4 int ladderOutArrayPosition = 3 string exitID = str.tostring(array.get(longExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(longExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(longExitQuantities,ladderOutArrayPosition)/100) color = longTP4Hit ? green : black table.cell(panel, 0, rowCount, text=longTP4Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Long Ladder Out 5 if currentlyInLongPosition and ladderOutSteps >= 5 int ladderOutArrayPosition = 4 string exitID = str.tostring(array.get(longExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(longExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(longExitQuantities,ladderOutArrayPosition)/100) color = longTP5Hit ? green : black table.cell(panel, 0, rowCount, text=longTP5Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Long Ladder Out 6 if currentlyInLongPosition and ladderOutSteps >= 6 int ladderOutArrayPosition = 5 string exitID = str.tostring(array.get(longExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(longExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(longExitQuantities,ladderOutArrayPosition)/100) color = longTP6Hit ? green : black table.cell(panel, 0, rowCount, text=longTP6Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Short Ladder Out 1 if currentlyInShortPosition and ladderOutSteps >= 1 int ladderOutArrayPosition = 0 string exitID = str.tostring(array.get(shortExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(shortExitQuantities,ladderOutArrayPosition)/100) color = shortTP1Hit ? green : black table.cell(panel, 0, rowCount, text=longTP1Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Short Ladder Out 2 if currentlyInShortPosition and ladderOutSteps >= 2 int ladderOutArrayPosition = 1 string exitID = str.tostring(array.get(shortExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(shortExitQuantities,ladderOutArrayPosition)/100) color = shortTP2Hit ? green : black table.cell(panel, 0, rowCount, text=longTP2Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Short Ladder Out 3 if currentlyInShortPosition and ladderOutSteps >= 3 int ladderOutArrayPosition = 2 string exitID = str.tostring(array.get(shortExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(shortExitQuantities,ladderOutArrayPosition)/100) color = shortTP3Hit ? green : black table.cell(panel, 0, rowCount, text=longTP3Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Short Ladder Out 4 if currentlyInShortPosition and ladderOutSteps >= 4 int ladderOutArrayPosition = 3 string exitID = str.tostring(array.get(shortExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(shortExitQuantities,ladderOutArrayPosition)/100) color = shortTP4Hit ? green : black table.cell(panel, 0, rowCount, text=longTP4Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Short Ladder Out 5 if currentlyInShortPosition and ladderOutSteps >= 5 int ladderOutArrayPosition = 4 string exitID = str.tostring(array.get(shortExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(shortExitQuantities,ladderOutArrayPosition)/100) color = shortTP5Hit ? green : black table.cell(panel, 0, rowCount, text=longTP5Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1 // Short Ladder Out 6 if currentlyInShortPosition and ladderOutSteps >= 6 int ladderOutArrayPosition = 5 string exitID = str.tostring(array.get(shortExitOrderNames,ladderOutArrayPosition)) string price = str.format("{0,number,currency}", array.get(shortExitPrices,ladderOutArrayPosition)) string quantity = str.format("{0,number,percent}", array.get(shortExitQuantities,ladderOutArrayPosition)/100) color = shortTP6Hit ? green : black table.cell(panel, 0, rowCount, text=longTP6Hit ? " " + exitID + checkMark : " " + exitID, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 1, rowCount, text=price, text_color=color, text_halign=text.align_left, bgcolor=cellBgColor, text_size=fontSize) table.cell(panel, 2, rowCount, text=quantity + " ", text_color=color, text_halign=text.align_right, bgcolor=cellBgColor, text_size=fontSize) rowCount += 1