[{"data":1,"prerenderedAt":982},["ShallowReactive",2],{"kscript:strategies/examples-perps":3},{"slug":4,"filePath":5,"frontmatter":6,"rawMarkdown":9,"tree":10},"strategies/examples-perps","strategies/examples-perps.md",{"title":7,"description":8},"Examples: The Five Perps Scenarios","The five canonical perps strategies behind the engine's acceptance battery, covering liquidation on both sides, fee classification, funding erosion, and bankruptcy accounting.","---\ntitle: \"Examples: The Five Perps Scenarios\"\ndescription: The five canonical perps strategies behind the engine's acceptance battery, covering liquidation on both sides, fee classification, funding erosion, and bankruptcy accounting.\n---\n\nThese are reproduction scripts: each one re-derives its pinned numbers on the recorded fixture bars committed beside its probe, which is what makes them verifiable. Run on a live chart they simply enter at that chart's prices (their thresholds are fixture values near 100), so for live experimentation use the chart-adapted `Perps:` templates in the editor's template picker instead.\n\nThese five scripts are the perps module's ground truth. They ship in three places at once: as editor templates (the `Perps:` entries in the template picker), as executed examples in this documentation, and as an acceptance battery inside the engine's test suite where every expected number is derived by hand from the [formulas](perps-and-leverage) and the engine cannot ship unless all five reproduce to the last digit.\n\nEach section names the exact behavior the scenario pins down. The headline numbers live in the [canonical scenarios table](perps-and-leverage#the-five-canonical-scenarios).\n\n## 1. Long liquidation\n\nA 10x long entered at 100 with 0.5% maintenance margin must liquidate at exactly `(100 - 10) / 0.995 = 90.45226130653266`.\n\n```kscript\n//@version=2\nstrategy(title=\"Perps Liquidation Anchor\", position=\"onchart\", axis=true, initialCapital=10000, instrument=\"perps\", leverage=10, maintenanceMarginPercent=0.5, qtyType=\"fixed\", qtyValue=1, slippageBps=0, makerFeePercent=0, takerFeePercent=0, funding=\"off\")\n\ntimeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)\n\nif (barIndex == 0) {\n  strategy.entry(\"L\", \"long\")\n}\n\nplotLine(value=bars.close, width=1, colors=[\"#dc2626\"], label=[\"Close\"], desc=[\"Close price\"])\n```\n\n## 2. Short liquidation with taker fees\n\nThe short side of the same formula, `(100 + 10) / 1.005 = 109.45273631840797`, with a market entry so both the entry fill and the liquidation fill pay `takerFeePercent`.\n\n```kscript\n//@version=2\nstrategy(title=\"Perps 2: Short Liquidation with Taker Fees\", position=\"onchart\", axis=true, initialCapital=10000, qtyType=\"fixed\", qtyValue=1, instrument=\"perps\", leverage=10, maintenanceMarginPercent=0.5, takerFeePercent=0.05, funding=\"off\")\n\ntimeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)\ntimeseries armed = 100.5\n\nif (strategy.positionSize() == 0 && bars.close \u003C armed) {\n  strategy.entry(\"S\", \"short\")\n}\n\nplotLine(value=bars.close, width=1, colors=[\"#94a3b8\"], label=[\"Close\"], desc=[\"Close price\"])\n```\n\n## 3. Maker and taker split\n\nTwo trades, four fills, four fee classifications: a limit entry and its take-profit limit pay maker; a market entry and its protective stop pay taker. Also a guard-design lesson: the script phase runs at bar close, after fills, so entry zones stay disjoint from exit prices or the flat-position guard re-arms on the very bar an exit filled.\n\n```kscript\n//@version=2\nstrategy(title=\"Perps 3: Maker and Taker Split\", position=\"onchart\", axis=true, initialCapital=10000, qtyType=\"fixed\", qtyValue=1, instrument=\"perps\", leverage=5, makerFeePercent=0.01, takerFeePercent=0.05, funding=\"off\")\n\ntimeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)\ntimeseries limitZoneLow = 100.5\ntimeseries limitZoneHigh = 103\ntimeseries marketZone = 110.5\n\nif (strategy.positionSize() == 0 && bars.close > limitZoneLow && bars.close \u003C limitZoneHigh) {\n  strategy.entry(\"LimitIn\", \"long\", limit=95)\n}\nif (strategy.positionSize() == 0 && bars.close > marketZone) {\n  strategy.entry(\"MarketIn\", \"long\")\n}\nif (strategy.positionSize() > 0) {\n  strategy.exit(\"TP\", fromEntry=\"LimitIn\", limit=105)\n  strategy.exit(\"SL\", fromEntry=\"MarketIn\", stop=92)\n}\n\nplotLine(value=bars.close, width=1, colors=[\"#94a3b8\"], label=[\"Close\"], desc=[\"Close price\"])\n```\n\n## 4. Funding erosion\n\nFunding settles against the isolated margin: each settlement debits cash and committed margin together, the liquidation price tightens as margin erodes, and a settlement that depletes margin liquidates the position at that bar's open with zero price pnl.\n\n```kscript\n//@version=2\nstrategy(title=\"Perps 4: Funding Erosion\", position=\"onchart\", axis=true, initialCapital=10000, qtyType=\"fixed\", qtyValue=1, instrument=\"perps\", leverage=10, maintenanceMarginPercent=0.5, funding=\"data\")\n\ntimeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)\ntimeseries armed = 99.5\n\nif (strategy.positionSize() == 0 && bars.close > armed) {\n  strategy.entry(\"L\", \"long\")\n}\n\nplotLine(value=bars.close, width=1, colors=[\"#94a3b8\"], label=[\"Close\"], desc=[\"Close price\"])\n```\n\n## 5. Bankruptcy gap\n\nPrice gaps straight through the liquidation level: the fill is the bar price because it is worse, the loss beyond committed margin is recorded as `bankruptcyDeficit`, and equity floors at exactly zero.\n\n```kscript\n//@version=2\nstrategy(title=\"Perps Bankruptcy Gap\", position=\"onchart\", axis=true, initialCapital=10, instrument=\"perps\", leverage=10, maintenanceMarginPercent=0.5, qtyType=\"fixed\", qtyValue=1, slippageBps=0, makerFeePercent=0, takerFeePercent=0, funding=\"off\")\n\ntimeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)\n\nif (barIndex == 0) {\n  strategy.entry(\"L\", \"long\")\n}\n\nplotLine(value=strategy.equity(), width=1, colors=[\"#7c2d12\"], label=[\"Equity\"], desc=[\"Strategy equity\"])\n```\n",{"type":11,"children":12,"data":975,"position":977},"root",[13,52,54,114,115,155,156,175,176,209,210,311,312,329,330,384,385,485,486,503,504,519,520,698,699,716,717,732,733,831,832,849,850,885,886],{"type":14,"tagName":15,"properties":16,"children":17,"position":49},"element","p",{},[18,28,42],{"type":19,"value":20,"position":21},"text","These are reproduction scripts: each one re-derives its pinned numbers on the recorded fixture bars committed beside its probe, which is what makes them verifiable. Run on a live chart they simply enter at that chart's prices (their thresholds are fixture values near 100), so for live experimentation use the chart-adapted ",{"start":22,"end":25},{"line":23,"column":23,"offset":24},1,0,{"line":23,"column":26,"offset":27},325,324,{"type":14,"tagName":29,"properties":30,"children":31,"position":39},"code",{},[32],{"type":19,"value":33,"position":34},"Perps:",{"start":35,"end":36},{"line":23,"column":26,"offset":27},{"line":23,"column":37,"offset":38},333,332,{"start":40,"end":41},{"line":23,"column":26,"offset":27},{"line":23,"column":37,"offset":38},{"type":19,"value":43,"position":44}," templates in the editor's template picker instead.",{"start":45,"end":46},{"line":23,"column":37,"offset":38},{"line":23,"column":47,"offset":48},384,383,{"start":50,"end":51},{"line":23,"column":23,"offset":24},{"line":23,"column":47,"offset":48},{"type":19,"value":53},"\n",{"type":14,"tagName":15,"properties":55,"children":56,"position":111},{},[57,66,78,85,104],{"type":19,"value":58,"position":59},"These five scripts are the perps module's ground truth. They ship in three places at once: as editor templates (the ",{"start":60,"end":63},{"line":61,"column":23,"offset":62},3,385,{"line":61,"column":64,"offset":65},117,501,{"type":14,"tagName":29,"properties":67,"children":68,"position":75},{},[69],{"type":19,"value":33,"position":70},{"start":71,"end":72},{"line":61,"column":64,"offset":65},{"line":61,"column":73,"offset":74},125,509,{"start":76,"end":77},{"line":61,"column":64,"offset":65},{"line":61,"column":73,"offset":74},{"type":19,"value":79,"position":80}," entries in the template picker), as executed examples in this documentation, and as an acceptance battery inside the engine's test suite where every expected number is derived by hand from the ",{"start":81,"end":82},{"line":61,"column":73,"offset":74},{"line":61,"column":83,"offset":84},319,703,{"type":14,"tagName":86,"properties":87,"children":89,"position":99},"a",{"href":88},"perps-and-leverage",[90],{"type":19,"value":91,"position":92},"formulas",{"start":93,"end":96},{"line":61,"column":94,"offset":95},320,704,{"line":61,"column":97,"offset":98},328,712,{"start":100,"end":101},{"line":61,"column":83,"offset":84},{"line":61,"column":102,"offset":103},349,733,{"type":19,"value":105,"position":106}," and the engine cannot ship unless all five reproduce to the last digit.",{"start":107,"end":108},{"line":61,"column":102,"offset":103},{"line":61,"column":109,"offset":110},421,805,{"start":112,"end":113},{"line":61,"column":23,"offset":62},{"line":61,"column":109,"offset":110},{"type":19,"value":53},{"type":14,"tagName":15,"properties":116,"children":117,"position":152},{},[118,127,145],{"type":19,"value":119,"position":120},"Each section names the exact behavior the scenario pins down. The headline numbers live in the ",{"start":121,"end":124},{"line":122,"column":23,"offset":123},5,807,{"line":122,"column":125,"offset":126},96,902,{"type":14,"tagName":86,"properties":128,"children":130,"position":140},{"href":129},"perps-and-leverage#the-five-canonical-scenarios",[131],{"type":19,"value":132,"position":133},"canonical scenarios table",{"start":134,"end":137},{"line":122,"column":135,"offset":136},97,903,{"line":122,"column":138,"offset":139},122,928,{"start":141,"end":142},{"line":122,"column":125,"offset":126},{"line":122,"column":143,"offset":144},172,978,{"type":19,"value":146,"position":147},".",{"start":148,"end":149},{"line":122,"column":143,"offset":144},{"line":122,"column":150,"offset":151},173,979,{"start":153,"end":154},{"line":122,"column":23,"offset":123},{"line":122,"column":150,"offset":151},{"type":19,"value":53},{"type":14,"tagName":157,"properties":158,"children":160,"position":171},"h2",{"id":159},"1.-long-liquidation",[161],{"type":19,"value":162,"position":163},"1. Long liquidation",{"start":164,"end":168},{"line":165,"column":166,"offset":167},7,4,984,{"line":165,"column":169,"offset":170},23,1003,{"start":172,"end":174},{"line":165,"column":23,"offset":173},981,{"line":165,"column":169,"offset":170},{"type":19,"value":53},{"type":14,"tagName":15,"properties":177,"children":178,"position":206},{},[179,188,200],{"type":19,"value":180,"position":181},"A 10x long entered at 100 with 0.5% maintenance margin must liquidate at exactly ",{"start":182,"end":185},{"line":183,"column":23,"offset":184},9,1005,{"line":183,"column":186,"offset":187},82,1086,{"type":14,"tagName":29,"properties":189,"children":190,"position":197},{},[191],{"type":19,"value":192,"position":193},"(100 - 10) / 0.995 = 90.45226130653266",{"start":194,"end":195},{"line":183,"column":186,"offset":187},{"line":183,"column":138,"offset":196},1126,{"start":198,"end":199},{"line":183,"column":186,"offset":187},{"line":183,"column":138,"offset":196},{"type":19,"value":146,"position":201},{"start":202,"end":203},{"line":183,"column":138,"offset":196},{"line":183,"column":204,"offset":205},123,1127,{"start":207,"end":208},{"line":183,"column":23,"offset":184},{"line":183,"column":204,"offset":205},{"type":19,"value":53},{"type":11,"children":211},[212],{"type":14,"tagName":213,"properties":214,"children":218,"data":-1},"pre",{"class":215,"style":216,"tabindex":217},"shiki shiki-themes github-dark github-light","--shiki-dark:#e1e4e8;--shiki-light:#24292e;--shiki-dark-bg:#24292e;--shiki-light-bg:#fff","0",[219],{"type":14,"tagName":29,"properties":220,"children":221},{},[222,232,233,241,242,250,251,259,260,267,268,276,277,285,286,294,295,302,303],{"type":14,"tagName":223,"properties":224,"children":226},"span",{"class":225},"line",[227],{"type":14,"tagName":223,"properties":228,"children":229},{},[230],{"type":19,"value":231},"//@version=2",{"type":19,"value":53},{"type":14,"tagName":223,"properties":234,"children":235},{"class":225},[236],{"type":14,"tagName":223,"properties":237,"children":238},{},[239],{"type":19,"value":240},"strategy(title=\"Perps Liquidation Anchor\", position=\"onchart\", axis=true, initialCapital=10000, instrument=\"perps\", leverage=10, maintenanceMarginPercent=0.5, qtyType=\"fixed\", qtyValue=1, slippageBps=0, makerFeePercent=0, takerFeePercent=0, funding=\"off\")",{"type":19,"value":53},{"type":14,"tagName":223,"properties":243,"children":244},{"class":225},[245],{"type":14,"tagName":223,"properties":246,"children":247},{},[248],{"type":19,"value":249},"",{"type":19,"value":53},{"type":14,"tagName":223,"properties":252,"children":253},{"class":225},[254],{"type":14,"tagName":223,"properties":255,"children":256},{},[257],{"type":19,"value":258},"timeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)",{"type":19,"value":53},{"type":14,"tagName":223,"properties":261,"children":262},{"class":225},[263],{"type":14,"tagName":223,"properties":264,"children":265},{},[266],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":269,"children":270},{"class":225},[271],{"type":14,"tagName":223,"properties":272,"children":273},{},[274],{"type":19,"value":275},"if (barIndex == 0) {",{"type":19,"value":53},{"type":14,"tagName":223,"properties":278,"children":279},{"class":225},[280],{"type":14,"tagName":223,"properties":281,"children":282},{},[283],{"type":19,"value":284},"  strategy.entry(\"L\", \"long\")",{"type":19,"value":53},{"type":14,"tagName":223,"properties":287,"children":288},{"class":225},[289],{"type":14,"tagName":223,"properties":290,"children":291},{},[292],{"type":19,"value":293},"}",{"type":19,"value":53},{"type":14,"tagName":223,"properties":296,"children":297},{"class":225},[298],{"type":14,"tagName":223,"properties":299,"children":300},{},[301],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":304,"children":305},{"class":225},[306],{"type":14,"tagName":223,"properties":307,"children":308},{},[309],{"type":19,"value":310},"plotLine(value=bars.close, width=1, colors=[\"#dc2626\"], label=[\"Close\"], desc=[\"Close price\"])",{"type":19,"value":53},{"type":14,"tagName":157,"properties":313,"children":315,"position":325},{"id":314},"2.-short-liquidation-with-taker-fees",[316],{"type":19,"value":317,"position":318},"2. Short liquidation with taker fees",{"start":319,"end":322},{"line":320,"column":166,"offset":321},24,1640,{"line":320,"column":323,"offset":324},40,1676,{"start":326,"end":328},{"line":320,"column":23,"offset":327},1637,{"line":320,"column":323,"offset":324},{"type":19,"value":53},{"type":14,"tagName":15,"properties":331,"children":332,"position":381},{},[333,342,355,362,375],{"type":19,"value":334,"position":335},"The short side of the same formula, ",{"start":336,"end":339},{"line":337,"column":23,"offset":338},26,1678,{"line":337,"column":340,"offset":341},37,1714,{"type":14,"tagName":29,"properties":343,"children":344,"position":352},{},[345],{"type":19,"value":346,"position":347},"(100 + 10) / 1.005 = 109.45273631840797",{"start":348,"end":349},{"line":337,"column":340,"offset":341},{"line":337,"column":350,"offset":351},78,1755,{"start":353,"end":354},{"line":337,"column":340,"offset":341},{"line":337,"column":350,"offset":351},{"type":19,"value":356,"position":357},", with a market entry so both the entry fill and the liquidation fill pay ",{"start":358,"end":359},{"line":337,"column":350,"offset":351},{"line":337,"column":360,"offset":361},152,1829,{"type":14,"tagName":29,"properties":363,"children":364,"position":372},{},[365],{"type":19,"value":366,"position":367},"takerFeePercent",{"start":368,"end":369},{"line":337,"column":360,"offset":361},{"line":337,"column":370,"offset":371},169,1846,{"start":373,"end":374},{"line":337,"column":360,"offset":361},{"line":337,"column":370,"offset":371},{"type":19,"value":146,"position":376},{"start":377,"end":378},{"line":337,"column":370,"offset":371},{"line":337,"column":379,"offset":380},170,1847,{"start":382,"end":383},{"line":337,"column":23,"offset":338},{"line":337,"column":379,"offset":380},{"type":19,"value":53},{"type":11,"children":386},[387],{"type":14,"tagName":213,"properties":388,"children":389,"data":-1},{"class":215,"style":216,"tabindex":217},[390],{"type":14,"tagName":29,"properties":391,"children":392},{},[393,400,401,409,410,417,418,425,426,434,435,442,443,451,452,460,461,468,469,476,477],{"type":14,"tagName":223,"properties":394,"children":395},{"class":225},[396],{"type":14,"tagName":223,"properties":397,"children":398},{},[399],{"type":19,"value":231},{"type":19,"value":53},{"type":14,"tagName":223,"properties":402,"children":403},{"class":225},[404],{"type":14,"tagName":223,"properties":405,"children":406},{},[407],{"type":19,"value":408},"strategy(title=\"Perps 2: Short Liquidation with Taker Fees\", position=\"onchart\", axis=true, initialCapital=10000, qtyType=\"fixed\", qtyValue=1, instrument=\"perps\", leverage=10, maintenanceMarginPercent=0.5, takerFeePercent=0.05, funding=\"off\")",{"type":19,"value":53},{"type":14,"tagName":223,"properties":411,"children":412},{"class":225},[413],{"type":14,"tagName":223,"properties":414,"children":415},{},[416],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":419,"children":420},{"class":225},[421],{"type":14,"tagName":223,"properties":422,"children":423},{},[424],{"type":19,"value":258},{"type":19,"value":53},{"type":14,"tagName":223,"properties":427,"children":428},{"class":225},[429],{"type":14,"tagName":223,"properties":430,"children":431},{},[432],{"type":19,"value":433},"timeseries armed = 100.5",{"type":19,"value":53},{"type":14,"tagName":223,"properties":436,"children":437},{"class":225},[438],{"type":14,"tagName":223,"properties":439,"children":440},{},[441],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":444,"children":445},{"class":225},[446],{"type":14,"tagName":223,"properties":447,"children":448},{},[449],{"type":19,"value":450},"if (strategy.positionSize() == 0 && bars.close \u003C armed) {",{"type":19,"value":53},{"type":14,"tagName":223,"properties":453,"children":454},{"class":225},[455],{"type":14,"tagName":223,"properties":456,"children":457},{},[458],{"type":19,"value":459},"  strategy.entry(\"S\", \"short\")",{"type":19,"value":53},{"type":14,"tagName":223,"properties":462,"children":463},{"class":225},[464],{"type":14,"tagName":223,"properties":465,"children":466},{},[467],{"type":19,"value":293},{"type":19,"value":53},{"type":14,"tagName":223,"properties":470,"children":471},{"class":225},[472],{"type":14,"tagName":223,"properties":473,"children":474},{},[475],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":478,"children":479},{"class":225},[480],{"type":14,"tagName":223,"properties":481,"children":482},{},[483],{"type":19,"value":484},"plotLine(value=bars.close, width=1, colors=[\"#94a3b8\"], label=[\"Close\"], desc=[\"Close price\"])",{"type":19,"value":53},{"type":14,"tagName":157,"properties":487,"children":489,"position":499},{"id":488},"3.-maker-and-taker-split",[490],{"type":19,"value":491,"position":492},"3. Maker and taker split",{"start":493,"end":496},{"line":494,"column":166,"offset":495},42,2410,{"line":494,"column":497,"offset":498},28,2434,{"start":500,"end":502},{"line":494,"column":23,"offset":501},2407,{"line":494,"column":497,"offset":498},{"type":19,"value":53},{"type":14,"tagName":15,"properties":505,"children":506,"position":516},{},[507],{"type":19,"value":508,"position":509},"Two trades, four fills, four fee classifications: a limit entry and its take-profit limit pay maker; a market entry and its protective stop pay taker. Also a guard-design lesson: the script phase runs at bar close, after fills, so entry zones stay disjoint from exit prices or the flat-position guard re-arms on the very bar an exit filled.",{"start":510,"end":513},{"line":511,"column":23,"offset":512},44,2436,{"line":511,"column":514,"offset":515},341,2776,{"start":517,"end":518},{"line":511,"column":23,"offset":512},{"line":511,"column":514,"offset":515},{"type":19,"value":53},{"type":11,"children":521},[522],{"type":14,"tagName":213,"properties":523,"children":524,"data":-1},{"class":215,"style":216,"tabindex":217},[525],{"type":14,"tagName":29,"properties":526,"children":527},{},[528,535,536,544,545,552,553,560,561,569,570,578,579,587,588,595,596,604,605,613,614,621,622,630,631,639,640,647,648,656,657,665,666,674,675,682,683,690,691],{"type":14,"tagName":223,"properties":529,"children":530},{"class":225},[531],{"type":14,"tagName":223,"properties":532,"children":533},{},[534],{"type":19,"value":231},{"type":19,"value":53},{"type":14,"tagName":223,"properties":537,"children":538},{"class":225},[539],{"type":14,"tagName":223,"properties":540,"children":541},{},[542],{"type":19,"value":543},"strategy(title=\"Perps 3: Maker and Taker Split\", position=\"onchart\", axis=true, initialCapital=10000, qtyType=\"fixed\", qtyValue=1, instrument=\"perps\", leverage=5, makerFeePercent=0.01, takerFeePercent=0.05, funding=\"off\")",{"type":19,"value":53},{"type":14,"tagName":223,"properties":546,"children":547},{"class":225},[548],{"type":14,"tagName":223,"properties":549,"children":550},{},[551],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":554,"children":555},{"class":225},[556],{"type":14,"tagName":223,"properties":557,"children":558},{},[559],{"type":19,"value":258},{"type":19,"value":53},{"type":14,"tagName":223,"properties":562,"children":563},{"class":225},[564],{"type":14,"tagName":223,"properties":565,"children":566},{},[567],{"type":19,"value":568},"timeseries limitZoneLow = 100.5",{"type":19,"value":53},{"type":14,"tagName":223,"properties":571,"children":572},{"class":225},[573],{"type":14,"tagName":223,"properties":574,"children":575},{},[576],{"type":19,"value":577},"timeseries limitZoneHigh = 103",{"type":19,"value":53},{"type":14,"tagName":223,"properties":580,"children":581},{"class":225},[582],{"type":14,"tagName":223,"properties":583,"children":584},{},[585],{"type":19,"value":586},"timeseries marketZone = 110.5",{"type":19,"value":53},{"type":14,"tagName":223,"properties":589,"children":590},{"class":225},[591],{"type":14,"tagName":223,"properties":592,"children":593},{},[594],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":597,"children":598},{"class":225},[599],{"type":14,"tagName":223,"properties":600,"children":601},{},[602],{"type":19,"value":603},"if (strategy.positionSize() == 0 && bars.close > limitZoneLow && bars.close \u003C limitZoneHigh) {",{"type":19,"value":53},{"type":14,"tagName":223,"properties":606,"children":607},{"class":225},[608],{"type":14,"tagName":223,"properties":609,"children":610},{},[611],{"type":19,"value":612},"  strategy.entry(\"LimitIn\", \"long\", limit=95)",{"type":19,"value":53},{"type":14,"tagName":223,"properties":615,"children":616},{"class":225},[617],{"type":14,"tagName":223,"properties":618,"children":619},{},[620],{"type":19,"value":293},{"type":19,"value":53},{"type":14,"tagName":223,"properties":623,"children":624},{"class":225},[625],{"type":14,"tagName":223,"properties":626,"children":627},{},[628],{"type":19,"value":629},"if (strategy.positionSize() == 0 && bars.close > marketZone) {",{"type":19,"value":53},{"type":14,"tagName":223,"properties":632,"children":633},{"class":225},[634],{"type":14,"tagName":223,"properties":635,"children":636},{},[637],{"type":19,"value":638},"  strategy.entry(\"MarketIn\", \"long\")",{"type":19,"value":53},{"type":14,"tagName":223,"properties":641,"children":642},{"class":225},[643],{"type":14,"tagName":223,"properties":644,"children":645},{},[646],{"type":19,"value":293},{"type":19,"value":53},{"type":14,"tagName":223,"properties":649,"children":650},{"class":225},[651],{"type":14,"tagName":223,"properties":652,"children":653},{},[654],{"type":19,"value":655},"if (strategy.positionSize() > 0) {",{"type":19,"value":53},{"type":14,"tagName":223,"properties":658,"children":659},{"class":225},[660],{"type":14,"tagName":223,"properties":661,"children":662},{},[663],{"type":19,"value":664},"  strategy.exit(\"TP\", fromEntry=\"LimitIn\", limit=105)",{"type":19,"value":53},{"type":14,"tagName":223,"properties":667,"children":668},{"class":225},[669],{"type":14,"tagName":223,"properties":670,"children":671},{},[672],{"type":19,"value":673},"  strategy.exit(\"SL\", fromEntry=\"MarketIn\", stop=92)",{"type":19,"value":53},{"type":14,"tagName":223,"properties":676,"children":677},{"class":225},[678],{"type":14,"tagName":223,"properties":679,"children":680},{},[681],{"type":19,"value":293},{"type":19,"value":53},{"type":14,"tagName":223,"properties":684,"children":685},{"class":225},[686],{"type":14,"tagName":223,"properties":687,"children":688},{},[689],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":692,"children":693},{"class":225},[694],{"type":14,"tagName":223,"properties":695,"children":696},{},[697],{"type":19,"value":484},{"type":19,"value":53},{"type":14,"tagName":157,"properties":700,"children":702,"position":712},{"id":701},"4.-funding-erosion",[703],{"type":19,"value":704,"position":705},"4. Funding erosion",{"start":706,"end":709},{"line":707,"column":166,"offset":708},69,3684,{"line":707,"column":710,"offset":711},22,3702,{"start":713,"end":715},{"line":707,"column":23,"offset":714},3681,{"line":707,"column":710,"offset":711},{"type":19,"value":53},{"type":14,"tagName":15,"properties":718,"children":719,"position":729},{},[720],{"type":19,"value":721,"position":722},"Funding settles against the isolated margin: each settlement debits cash and committed margin together, the liquidation price tightens as margin erodes, and a settlement that depletes margin liquidates the position at that bar's open with zero price pnl.",{"start":723,"end":726},{"line":724,"column":23,"offset":725},71,3704,{"line":724,"column":727,"offset":728},255,3958,{"start":730,"end":731},{"line":724,"column":23,"offset":725},{"line":724,"column":727,"offset":728},{"type":19,"value":53},{"type":11,"children":734},[735],{"type":14,"tagName":213,"properties":736,"children":737,"data":-1},{"class":215,"style":216,"tabindex":217},[738],{"type":14,"tagName":29,"properties":739,"children":740},{},[741,748,749,757,758,765,766,773,774,782,783,790,791,799,800,807,808,815,816,823,824],{"type":14,"tagName":223,"properties":742,"children":743},{"class":225},[744],{"type":14,"tagName":223,"properties":745,"children":746},{},[747],{"type":19,"value":231},{"type":19,"value":53},{"type":14,"tagName":223,"properties":750,"children":751},{"class":225},[752],{"type":14,"tagName":223,"properties":753,"children":754},{},[755],{"type":19,"value":756},"strategy(title=\"Perps 4: Funding Erosion\", position=\"onchart\", axis=true, initialCapital=10000, qtyType=\"fixed\", qtyValue=1, instrument=\"perps\", leverage=10, maintenanceMarginPercent=0.5, funding=\"data\")",{"type":19,"value":53},{"type":14,"tagName":223,"properties":759,"children":760},{"class":225},[761],{"type":14,"tagName":223,"properties":762,"children":763},{},[764],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":767,"children":768},{"class":225},[769],{"type":14,"tagName":223,"properties":770,"children":771},{},[772],{"type":19,"value":258},{"type":19,"value":53},{"type":14,"tagName":223,"properties":775,"children":776},{"class":225},[777],{"type":14,"tagName":223,"properties":778,"children":779},{},[780],{"type":19,"value":781},"timeseries armed = 99.5",{"type":19,"value":53},{"type":14,"tagName":223,"properties":784,"children":785},{"class":225},[786],{"type":14,"tagName":223,"properties":787,"children":788},{},[789],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":792,"children":793},{"class":225},[794],{"type":14,"tagName":223,"properties":795,"children":796},{},[797],{"type":19,"value":798},"if (strategy.positionSize() == 0 && bars.close > armed) {",{"type":19,"value":53},{"type":14,"tagName":223,"properties":801,"children":802},{"class":225},[803],{"type":14,"tagName":223,"properties":804,"children":805},{},[806],{"type":19,"value":284},{"type":19,"value":53},{"type":14,"tagName":223,"properties":809,"children":810},{"class":225},[811],{"type":14,"tagName":223,"properties":812,"children":813},{},[814],{"type":19,"value":293},{"type":19,"value":53},{"type":14,"tagName":223,"properties":817,"children":818},{"class":225},[819],{"type":14,"tagName":223,"properties":820,"children":821},{},[822],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":825,"children":826},{"class":225},[827],{"type":14,"tagName":223,"properties":828,"children":829},{},[830],{"type":19,"value":484},{"type":19,"value":53},{"type":14,"tagName":157,"properties":833,"children":835,"position":845},{"id":834},"5.-bankruptcy-gap",[836],{"type":19,"value":837,"position":838},"5. Bankruptcy gap",{"start":839,"end":842},{"line":840,"column":166,"offset":841},87,4480,{"line":840,"column":843,"offset":844},21,4497,{"start":846,"end":848},{"line":840,"column":23,"offset":847},4477,{"line":840,"column":843,"offset":844},{"type":19,"value":53},{"type":14,"tagName":15,"properties":851,"children":852,"position":882},{},[853,862,875],{"type":19,"value":854,"position":855},"Price gaps straight through the liquidation level: the fill is the bar price because it is worse, the loss beyond committed margin is recorded as ",{"start":856,"end":859},{"line":857,"column":23,"offset":858},89,4499,{"line":857,"column":860,"offset":861},147,4645,{"type":14,"tagName":29,"properties":863,"children":864,"position":872},{},[865],{"type":19,"value":866,"position":867},"bankruptcyDeficit",{"start":868,"end":869},{"line":857,"column":860,"offset":861},{"line":857,"column":870,"offset":871},166,4664,{"start":873,"end":874},{"line":857,"column":860,"offset":861},{"line":857,"column":870,"offset":871},{"type":19,"value":876,"position":877},", and equity floors at exactly zero.",{"start":878,"end":879},{"line":857,"column":870,"offset":871},{"line":857,"column":880,"offset":881},202,4700,{"start":883,"end":884},{"line":857,"column":23,"offset":858},{"line":857,"column":880,"offset":881},{"type":19,"value":53},{"type":11,"children":887},[888],{"type":14,"tagName":213,"properties":889,"children":890,"data":-1},{"class":215,"style":216,"tabindex":217},[891],{"type":14,"tagName":29,"properties":892,"children":893},{},[894,901,902,910,911,918,919,926,927,934,935,942,943,950,951,958,959,966,967],{"type":14,"tagName":223,"properties":895,"children":896},{"class":225},[897],{"type":14,"tagName":223,"properties":898,"children":899},{},[900],{"type":19,"value":231},{"type":19,"value":53},{"type":14,"tagName":223,"properties":903,"children":904},{"class":225},[905],{"type":14,"tagName":223,"properties":906,"children":907},{},[908],{"type":19,"value":909},"strategy(title=\"Perps Bankruptcy Gap\", position=\"onchart\", axis=true, initialCapital=10, instrument=\"perps\", leverage=10, maintenanceMarginPercent=0.5, qtyType=\"fixed\", qtyValue=1, slippageBps=0, makerFeePercent=0, takerFeePercent=0, funding=\"off\")",{"type":19,"value":53},{"type":14,"tagName":223,"properties":912,"children":913},{"class":225},[914],{"type":14,"tagName":223,"properties":915,"children":916},{},[917],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":920,"children":921},{"class":225},[922],{"type":14,"tagName":223,"properties":923,"children":924},{},[925],{"type":19,"value":258},{"type":19,"value":53},{"type":14,"tagName":223,"properties":928,"children":929},{"class":225},[930],{"type":14,"tagName":223,"properties":931,"children":932},{},[933],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":936,"children":937},{"class":225},[938],{"type":14,"tagName":223,"properties":939,"children":940},{},[941],{"type":19,"value":275},{"type":19,"value":53},{"type":14,"tagName":223,"properties":944,"children":945},{"class":225},[946],{"type":14,"tagName":223,"properties":947,"children":948},{},[949],{"type":19,"value":284},{"type":19,"value":53},{"type":14,"tagName":223,"properties":952,"children":953},{"class":225},[954],{"type":14,"tagName":223,"properties":955,"children":956},{},[957],{"type":19,"value":293},{"type":19,"value":53},{"type":14,"tagName":223,"properties":960,"children":961},{"class":225},[962],{"type":14,"tagName":223,"properties":963,"children":964},{},[965],{"type":19,"value":249},{"type":19,"value":53},{"type":14,"tagName":223,"properties":968,"children":969},{"class":225},[970],{"type":14,"tagName":223,"properties":971,"children":972},{},[973],{"type":19,"value":974},"plotLine(value=strategy.equity(), width=1, colors=[\"#7c2d12\"], label=[\"Equity\"], desc=[\"Strategy equity\"])",{"quirksMode":976},false,{"start":978,"end":979},{"line":23,"column":23,"offset":24},{"line":980,"column":23,"offset":981},103,5214,1784888034437]