//@version=6 indicator("TradingRanch | CPI Target Pad", shorttitle="TR CPI Pad", overlay=true, max_lines_count=7, max_labels_count=7) // Based on the supplied OSOK Protection Pad v2.2. // A manual, one-trade futures scenario calculator. No orders or account connection. // All money inputs/outputs are USD. Defaults are examples, not prop-firm rules. // Not financial advice. Starting/current balances are entered manually. const string G_TRADE = "01 | THE SETUP" const string G_VALUE = "02 | CONTRACT VALUE & COSTS" const string G_STYLE = "03 | TRADINGRANCH STYLE" const string G_A = "04 | ACCOUNT SETUP" units = input.string("Points", "Distances in", options=["Points", "Ticks"], group=G_TRADE, display=display.none) padInput = input.float(21.0, "Protection pad", minval=0, group=G_TRADE, display=display.none) tpInput = input.float(30.0, "Take profit FROM PAD ENTRY", minval=0.000001, group=G_TRADE, display=display.none) slInput = input.float(30.0, "Stop loss FROM PAD ENTRY", minval=0.000001, group=G_TRADE, display=display.none) anchorMode = input.string("Follow price", "Reference price", options=["Follow price", "Fixed price"], group=G_TRADE, tooltip="Follow price moves the entire plan with the latest chart price. Fixed price holds the plan at the price you enter; it does not detect a trade or automatically lock at CPI.", display=display.none) fixedPrice = input.price(0.0, "Fixed reference price", group=G_TRADE, tooltip="The center between the two pads, not your fill price. Set protection pad to zero to use this as an entry price.", display=display.none) side = input.string("Both", "Show levels", options=["Both", "Long", "Short"], group=G_TRADE, display=display.none) quantityMode = input.string("Target minimum", "Modeled quantity", options=["Target minimum", "Firm maximum"], group=G_TRADE, tooltip="Target minimum models the contracts needed, capped at your entered firm maximum. Firm maximum models that entire maximum. NEED always shows the uncapped mathematical requirement. Neither mode submits trades.", display=display.none) valueMode = input.string("Chart futures (USD)", "Point value source", options=["Chart futures (USD)", "Custom USD value"], group=G_VALUE, display=display.none) customPointValue = input.float(20.0, "Custom USD per 1.0 price point / contract", minval=0.000001, group=G_VALUE, tooltip="Used only in Custom USD value mode. The traded contract must use the chart's price scale and tick size. For example, do not use a mini contract's dollar value when sizing micros.", display=display.none) customName = input.string("Custom contract", "Custom contract label", group=G_VALUE, display=display.none) fees = input.float(5.0, "Round-trip fees / contract (USD)", minval=0, group=G_VALUE, tooltip="Combined entry + exit commissions and exchange/platform fees for ONE contract. The result is a per-account quantity. A copier operates separately; this indicator has no copied-account count limit. Recalculate for accounts with different balances, costs or limits.", display=display.none) slippageTicks = input.int(4, "Total adverse slippage / round trip (ticks)", minval=0, group=G_VALUE, tooltip="Combined entry + exit allowance, charged once per contract. Subtracted from TP profit and added to SL loss. An estimate, not a bound on CPI fills.", display=display.none) showPanel = input.bool(true, "Show ranch dashboard", group=G_STYLE, display=display.none) showLines = input.bool(true, "Show price levels", group=G_STYLE, display=display.none) showLabels = input.bool(true, "Show level labels", group=G_STYLE, display=display.none) panelPosition = input.string("Top right", "Dashboard position", options=["Top right", "Top left", "Bottom right", "Bottom left"], group=G_STYLE, display=display.none) fontInput = input.string("Small", "Dashboard / label size", options=["Tiny", "Small", "Normal"], group=G_STYLE, display=display.none) labelOffset = input.int(8, "Labels ahead (bars)", minval=1, maxval=100, group=G_STYLE, display=display.none) lookback = input.int(30, "Line length behind price (bars)", minval=1, maxval=1000, group=G_STYLE, display=display.none) lineWidth = input.int(2, "Pad line width", minval=1, maxval=4, group=G_STYLE, display=display.none) gold = input.color(#D5AE66, "Ranch gold", group=G_STYLE, display=display.none) bull = input.color(#4FB991, "Long / target green", group=G_STYLE, display=display.none) bear = input.color(#E27B72, "Short / loss red", group=G_STYLE, display=display.none) background = input.color(#171B1A, "Charcoal background", group=G_STYLE, display=display.none) aName = input.string("Ranch setup", "Setup name", group=G_A, display=display.none) aTarget = input.float(3000, "Total profit target (USD)", minval=0, group=G_A, display=display.none) aStart = input.float(50000, "Starting account balance (USD)", minval=0, group=G_A, tooltip="Account balance when this evaluation began. The balance target is this starting amount plus Total profit target. If funding or adjustments changed the balance, use a comparable adjusted starting amount; cash transfers are not trading profit.", display=display.none) aBalance = input.float(50000, "Current account balance (USD)", group=G_A, tooltip="Enter the latest settled balance after posted trading fees. Update manually while flat. This is not read from your broker and does not include open P&L. Use the same basis as your firm's evaluation target.", display=display.none) aMax = input.int(5, "Firm max contracts per account", minval=0, group=G_A, tooltip="Enter the permitted number of contracts PER ACCOUNT for this instrument. This is not a limit on the number of copied accounts. Mini/micro conversion is not inferred. Zero means no contracts allowed.", display=display.none) aCheck = input.bool(false, "Check remaining loss room", group=G_A, tooltip="A simple check against the loss room you enter. It does not simulate trailing drawdown, other positions, margin or firm rules.", display=display.none) aRoom = input.float(2000, "Remaining loss room (USD)", minval=0, group=G_A, tooltip="Current room to the tightest applicable loss threshold after other exposure. Zero is treated as no room when the check is enabled. Touching the threshold is flagged.", display=display.none) // Effective distances are rounded to whole ticks. Lines and money use these same distances. float tick = syminfo.mintick float pointValue = valueMode == "Custom USD value" ? customPointValue : syminfo.pointvalue bool symbolOK = valueMode == "Custom USD value" or (syminfo.type == "futures" and syminfo.currency == "USD") bool metadataOK = not na(tick) and tick > 0 and not na(pointValue) and pointValue > 0 float unitsToTicks = units == "Ticks" ? 1.0 : (metadataOK ? 1.0 / tick : na) int padTicks = int(math.round(padInput * unitsToTicks)) int tpTicks = int(math.round(tpInput * unitsToTicks)) int slTicks = int(math.round(slInput * unitsToTicks)) float padDist = padTicks * tick float tpDist = tpTicks * tick float slDist = slTicks * tick float tickValue = tick * pointValue float costPerContract = fees + slippageTicks * tickValue float netPerContract = tpTicks * tickValue - costPerContract float lossPerContract = slTicks * tickValue + costPerContract bool distancesOK = not na(tpTicks) and tpTicks >= 1 and not na(slTicks) and slTicks >= 1 bool valid = symbolOK and metadataOK and distancesOK and netPerContract > 0 string issue = not symbolOK ? "USE USD FUTURES OR SET CUSTOM USD VALUE" : not metadataOK ? "INVALID TICK / POINT VALUE" : not distancesOK ? "TP AND SL MUST ROUND TO AT LEAST 1 TICK" : netPerContract <= 0 ? "TP DOES NOT COVER COSTS" : "" string contractName = valueMode == "Custom USD value" ? customName : syminfo.ticker string textSize = fontInput == "Tiny" ? size.tiny : fontInput == "Normal" ? size.normal : size.small string tablePosition = panelPosition == "Top left" ? position.top_left : panelPosition == "Bottom right" ? position.bottom_right : panelPosition == "Bottom left" ? position.bottom_left : position.top_right color ink = #F3EBDD color muted = #AAAFA8 money(float value) => na(value) ? "--" : "$" + str.tostring(value, "#,##0.00") number(int value) => na(value) ? "--" : str.tostring(value) calculate(float target, float startBalance, float currentBalance, int firmMax, bool checkRoom, float room) => float targetBalance = startBalance + target float remaining = math.max(targetBalance - currentBalance, 0.0) int needed = remaining <= 0 ? 0 : valid ? int(math.ceil(remaining / netPerContract)) : na // Pine comparisons round floats to nine decimals: avoid an extra contract // when subtraction/division puts an exact dollar boundary just above an integer. if needed > 1 and (needed - 1) * netPerContract >= remaining needed -= 1 int modeled = remaining <= 0 ? 0 : valid ? (quantityMode == "Firm maximum" ? firmMax : math.min(needed, firmMax)) : na float tpNet = modeled == 0 ? 0.0 : modeled * netPerContract float slLoss = modeled == 0 ? 0.0 : modeled * lossPerContract float shortfall = math.max(remaining - tpNet, 0.0) bool lossHit = checkRoom and modeled > 0 and slLoss >= room bool capped = not na(needed) and needed > firmMax string status = remaining <= 0 ? "TARGET MET*" : not valid ? "CHECK SETUP" : capped ? "CAP / SHORT" : "TP COVERS TARGET" status += remaining > 0 and valid ? (lossHit ? " / LOSS LIMIT" : not checkRoom ? " / ROOM ?" : "") : "" color statusColor = remaining <= 0 ? gold : not valid or lossHit ? bear : capped or not checkRoom ? gold : bull [remaining, needed, modeled, tpNet, slLoss, shortfall, status, statusColor] cell(table panel, int column, int row, string content, color foreground, color fill, string tip) => table.cell(panel, column, row, content, text_color=foreground, bgcolor=fill, text_size=textSize, tooltip=tip) // Allocate only seven objects of each kind; mutate them only on the last chart bar. level(line ln, label lb, float price, string caption, color col, string style, int width, bool visible) => float y = visible ? price : na line.set_xy1(ln, math.max(0, bar_index - lookback), y) line.set_xy2(ln, bar_index + labelOffset, y) line.set_color(ln, col) line.set_style(ln, style) line.set_width(ln, width) label.set_xy(lb, bar_index + labelOffset, showLabels ? y : na) label.set_text(lb, caption + " | " + str.tostring(price, format.mintick)) label.set_color(lb, color.new(background, 6)) label.set_textcolor(lb, col) label.set_size(lb, textSize) var array lines = array.new() var array