//@version=5 // ============================================================================= // THE BOAT v1.4 - waterfall / keel / rise / NECKLINE break // ----------------------------------------------------------------------------- // v1.4 rebuilds the trigger around James's own sequence. Every earlier version // used the swing high BEFORE the decline as the deck - a level that exists // before the boat does. His words: // // "we are monitoring price in an orderly waterfall down fall. Price finally // starts to level out to form a bottom (the Keel), now when price starts to // rise and forms a neckline ... PRIOR TO HAVING PRICE FORM A NECKLINE WE CAN // NOT HAVE A BOW AND STERN. So when price breaks and holds above the // neckline/Deck is when we want to enter." // // So the DECK IS BUILT BY THE RISE, not by the decline. That single correction // moves the entry much closer to the keel: the old left-rim trigger sat far // above, which is why so many of them tripped the CHASING gate at 2+ ATR from // the EMA. This version enters where he enters. // // THE SEQUENCE, in order, all measured on PRICE: // 1 WATERFALL an orderly decline - it must take at least min_fall bars and // drop at least min_depth. A one-bar crash is not a waterfall. // 2 KEEL a confirmed swing LOW ends the fall and becomes the bottom. // 3 RISE price lifts off the keel. // 4 DECK v1.8, James: "the start of the stern is when price starts to // CONSOLIDATE at a level of the downfall, which may NOT be the // top of the fall." So the deck is a SHELF - the most recent // tight range on the way DOWN, sitting above the keel. Walking // back from the keel low we look for the first window of comp_n // bars whose range is under squeeze x ATR; the high of that // shelf is the deck. This is the same coil idea as the blue box, // applied on the descent instead of after the rise. // Falls back to the local rim if no shelf is found. // 5 EXPANSION the deck breaks, then hold_after MORE bars close beyond it. // 6 NOT NOISE v2.1. v2.0 tried to kill James's "Noise" box by demanding the // keel sit at/below VWAP. WRONG - he pointed out immediately that // a pullback inside a strong trend is well ABOVE VWAP and is // precisely the trade we want. That filter is now OFF by default. // What remains is min_age: the boats he wanted ran 21-34 bars, // the noise ran 7-13. Age is a structure test, not a location one. // // v3.6f TRUE WATERFALL TOP, AND THE STOP REACHES ITS COLUMN. The first // live payload exposed both. Boat.new was handed `bb` as rimBar - // the bar of the highest high over 120 bars, the real top of the // decline - but `rimLoc` as rimPx, the high over only 20 bars, so // the bar and the price described different points and VRTX // reported a "waterfall top" BELOW its own deck. The boat now // carries topPx too, and the payload reports waterfall_top (real) // and local_rim (the 20-bar high the measured move is computed // from) separately. The measured move is deliberately unchanged - // moving it would change which trades fire, which is a rules // decision and not a bug fix. Second, stop_1_atr arrived NULL // because the ingest maps FL's column names; the payload now // sends both, so nothing needs editing on a live ingest that // Fashionably Late depends on. // // v3.6e REAL QUANTITIES, AND ADDS THAT COUNT. The database side is in // place - indicator_alerts has a nullable qty, the live ingest // binds it, and the dashboard FIFO prefers it when present - so // every leg now reports what fraction of the position it is. // Entry 1.0, each add another 1.0 posted as a second ENTRY on the // SAME trade_id, and the exits split the total. Units in equal // units out, so FIFO pairs every leg and prices the add at its // own fill: the database does the blended-average arithmetic and // Pine never has to. The add is also gated now - it fired on // EVERY same-direction signal while a position was open, so it // needs both a minimum bar gap and a genuinely further deck // before it marks a second step. // // v3.6d WEBHOOK EVENTS, on the Fashionably Late contract. James is // moving to FORWARD testing, and he is right to: the backtest // produced two data faults I found - a hard-coded EDT offset // across a DST boundary, and stops measured in fractions of a // cent - and no reason to think those were the last. Live signals // into the database he already runs measure the thing itself. // Field-for-field the same as SMB2 Fashionably Late where the // field exists (indicator, v, trade_id, leg_id, event_type, // direction, sym, tf, ts, ts_ny, entry_px, exit_px, reason, // testing) so the v2-gpt/rt monitor and the /tv/dashboard FIFO // close need no changes. BOAT-specific structure rides alongside // - keel, deck, waterfall top, measured move in R, setup kind, // keel width, bars from the low to the entry, stop percent and // share count - because those are exactly what a later query has // to be able to slice on. Partials post as EXIT legs so FIFO can // pair them, and the final exit carries the rule that fired. // // v3.6c MINIMUM STOP DISTANCE - found in the backtest, fixed here // first because it is a LIVE HAZARD. The stop is the lowest low // since the neckline formed, clamped at the keel. When the // neckline forms on a bar whose low is nearly the entry price, // that lands a fraction of a cent away: one backtested trade had // a 0.58-cent stop on a $38 stock, which at $50 of risk is 8,600 // shares. min_sh only ever guarded the opposite direction. The // stop is now floored at min_stop ATR from the entry, and a hard // share cap is enforced regardless of gate_on - a safety limit is // not a tuning heuristic. Every R in the backtest was divided by // these fractions of a cent, which is how a single trade scored // +285R and why the reported averages were meaningless. // // v3.6b THE STOPS, AND ONLY THE STOPS. James chose to revert to v3.6 // and change how it exits, so nothing from v3.7-v4.8 comes back: // no adds, no vetoes, no room gate, no numbering, no range box. // The neckline-break exit is OFF - it fired on ONE close through // the deck with zero tolerance, cutting a 1R plan at 0.14R and // making every R in the log a fiction, and the bench put it at // ~0.006R so it costs nothing to drop. In its place the PANIC // exit he originally specified, "for when price goes against // EARLY", which unlike a trail does not wait for profit; its // 25-degree threshold comes from the measured angle distribution // (median 11.1, p90 25.8), not from feel. The trail's arm level // is an input at 0.5R instead of a hard-coded 1R. The exit // tooltip names which rule fired. // // v3.6 HOLD COUNTING. James: "I was using the rule of 2 bars after the // break, NOT including the breaking bar." The old code counted the // breaking bar as the first hold, so it entered on the next bar - // two closes above the deck. His rule is three: the break, then // two more, entering on the second. One bar later, and it is his // rule rather than my reading of it. // // v3.5 STOP DISCARDING REAL KEELS. v1.5 cut detection to ONE live boat // per direction, to stop a single move printing four labels. Side // effect James found: a boat that formed early in a decline held // the slot, set a neckline, and the REAL keel that came later was // thrown away - so the setup he circled never became a boat at // all. The ADD logic (v3.3) is the right place to stop double // counting, so detection is permissive again: several boats per // direction, oldest retired when full. // // v3.4 TIMING. James: "we have a compression and break between 10:28 // and 10:38." With a keel at 10:20 the old settings could not // fire before 10:40 - wait 4 bars, 3 more to confirm a swing // high, then 2 closes = 10 bars minimum. Swing strength 3->2 and // keel wait 4->2 brings the earliest entry to 6 bars, inside his // window. And the deck now defaults to WHICHEVER FORMS FIRST - // a confirmed swing high OR a compression - because he described // that break as a compression and the old default ignored coils // entirely. // // v3.3 V-BOTTOM ENTRY. James's 10:26 fill was unreachable: a confirmed // neckline needs 4 bars of keel + 3 to confirm + 2 to hold = 10 // bars after the low, and he was in at 3. That drop and instant // snap is a V, not a base, and a V gives no time to wait. Its // trigger is his own suggestion - the 8-EMA's SLOPE off the // bottom - plus a small breakout, with the stop under the low. // The neckline break on the same boat now prints ADD instead of // opening a second trade, so one move cannot be logged twice. // // v3.2 CAME FROM / CAN GO, after Brian Shannon. The detector judged // the dip in isolation, so a reversal off a bottom and a pause in // an uptrend got the same label. Now the trend INTO the setup is // measured and they are named apart - BOAT for a reversal, COMP // for a continuation - so they can be tested separately rather // than blurred together. And the measured-move target is no // longer read in a vacuum: the nearest prior-day / session / VWAP // level is found and the tooltip says whether the target has // clear air or has to fight through something first. // // v3.1 Dollars on every leg, and a real bug with them: the exit // tooltip still hard-coded 0.40R / 0.80R for the partials. Once // sizes and levels became inputs (v2.9) those numbers were only // right by coincidence. Each leg now reports its actual size, // its actual R and its cash, and they sum to the total. // // v3.0 WIDTH FIX. James: "how are these V-bottoms? they should be boat // entries." Right - the width test counted bars within 0.5 ATR of // the exact low, but a rounded base curves, so only the very // bottom qualified. A 20-bar boat measured 2 bars wide and was // labelled a V. The label even contradicted itself: "width 2b, // to entry 20b". Width is now bars spent in the bottom third of // the HULL, so it scales with the boat rather than with ATR. // // v2.9 PARTIALS SCALE TO THE MEASURED MOVE. James: "we are saying 4R // but this trade risks $50 and makes $60." The arithmetic was // right - 40% at 1R plus 40% at 2R is 1.2R - but on a 4R boat the // ladder only captures 2.0R, because 80% comes off before price // is halfway to the projected target. Partial levels are now a // FRACTION of the measured move by default (33% and 66%), and the // entry tooltip states what the ladder will capture versus what // holding to target would be. // // v2.8 RISK IN DOLLARS. One input (default $50) sizes every trade: // shares = risk / (entry - stop). Tooltips show the share count, // the position value, the cash banked at each partial and the // trade total in dollars. A setup whose stop is so wide that the // size rounds below min_sh is flagged rather than silently taken. // // v2.7 Each leg now reports its P&L. Partial tooltips give the fill // LEVEL (not the bar close - the order goes off at the +1R/+2R // level), the size taken off, what that leg is worth on its own // and what it banks toward the trade. The exit tooltip adds a // full breakdown: P1, P2, runner, and the TRADE TOTAL in R. // // v2.6 Every marker is a LABEL now, not a plotshape - plotshape has no // tooltip, which is why the triangles were silent. Entry tooltips // carry price, ET time, deck, keel, the top of the waterfall, the // MEASURED MOVE and its projected target. V-bottom UP and DOWN // also get their own colours; one purple for both was confusing. // // v2.5 Hulls bounded to hull_max bars before the keel and only the // last few kept - they were drawn from the RIM (up to 120 bars // back) so every boat smeared across the pane and stacked. // Adds a TRADE LOG (time, side, entry, exit, blended R) and // PARTIAL EXITS: P1 at +1R, P2 at +2R, then the final OUT. // // v2.4 Hulls are FILLED and colour-coded (boat up / boat down / V). // Entry and exit triangles now actually draw - the exit shape was // being handed a boolean with location.absolute, so it plotted at // 0/1 and never appeared. And the SKIP GATE IS OFF: it vetoed the // setup before the biggest move, using thresholds measured on the // old left-rim entry which is far more extended by construction. // // NECKLINE v2.3. The deck now defaults to the FIRST SWING HIGH AFTER THE // KEEL - the level the RISE prints. v1.8-2.2 used the shelf from // the way DOWN, which is where the STERN starts, not where you // enter. Symptom James caught: "SKIP V-BOTTOM ... to entry 75b" - // a keel set at 10:20 that only triggered at 12:44, because the // deck sat back at the pre-fall level. // // BOAT vs V v2.2. The old gate counted bars from the LOW TO THE ENTRY - which // includes the entire rise - and demanded 12. That is not a base // width at all, and it was throwing away fast clean boats. James // spotted it: "I see why we are missing the green keels, they are // not matching the minimum bar length." // Now measured properly: KEEL WIDTH = bars sitting within // flat_band ATR of the low. 1-3 = V-bottom, 5+ = a real base. A // boat may be wide AND break its neckline quickly; those are two // independent numbers and both are shown on the label. // V-bottoms are drawn and labelled V rather than dropped, so the // parked V work has something to look at. // STOP lowest low since the neckline formed, plus a buffer. // // HONEST STATUS: the older left-rim version was tested over 2,492 in-play // symbol-days; gross looked positive but a RANDOM-ENTRY control matched it, so // no entry edge was ever demonstrated. THIS trigger has NOT been backtested - it // is new. The two extension measures that did separate monotonically are kept as // the SKIP gate. Treat it as a discipline tool and judge it forward. // ============================================================================= indicator("THE BOAT v3.6j - James 30/50/20 exits", shorttitle="BOAT", overlay=true, max_lines_count=100, max_labels_count=200, max_polylines_count=50) // ---------------------------------------------------------------- inputs g_h = "The boat - all measured on PRICE" piv = input.int(2, "Swing strength (keel + neckline)", minval=1, maxval=10, group=g_h) min_fall = input.int(10, "Waterfall must take at least (bars)", minval=3, group=g_h, tooltip="An ORDERLY decline. A one- or two-bar crash is not a waterfall and does not build a keel.") max_fall = input.int(120, "...and no more than (bars)", minval=20, group=g_h) deck_src = input.string("Whichever forms first", "The deck is", options=["Whichever forms first", "First high after the keel", "Top of a compression", "Shelf on the way down", "Local rim (top of the base)"], group=g_h, tooltip="v1.8 default = SHELF: the level price consolidated at DURING the fall, which is where the stern really starts. LOCAL RIM: simply the highest high near the base. COMPRESSION: the top of a coil after the rise. Flip between them and tell me which draws your line.") deck_lb = input.int(20, "Local rim lookback (bars before the keel)", minval=5, maxval=60, group=g_h, tooltip="How far back to look for the top of the BASE. 20 bars keeps it local. Raise it and the deck climbs toward the top of the whole waterfall, which is what v1.4-1.6 were wrongly doing at 120.") min_depth = input.float(0.8,"Waterfall depth (% of price)", step=0.1, group=g_h) min_keel = input.int(2, "Keel must hold at least (bars) before the rise", minval=1, group=g_h, tooltip="Bars between the keel low and the neckline forming. This is the flat bit of the bottom.") max_wait = input.int(80, "Neckline must break within (bars)", minval=10, group=g_h) min_rise = input.float(25, "Neckline at least this % up off the keel", step=5, group=g_h, tooltip="Measured against the waterfall's depth. Stops a tiny wiggle just off the low counting as a neckline.") comp_n = input.int(8, "Compression window (bars)", minval=3, maxval=30, group=g_h, tooltip="How many bars the tight range is measured over. This is the blue box - price pausing after the rise.") squeeze = input.float(1.8,"Compression: window range under this x ATR", step=0.1, group=g_h, tooltip="A normal 8-bar stretch spans 3-4 ATR. Under about 1.8 means price has genuinely coiled. Raise it to catch looser pauses, lower it to demand a tighter coil.") hold_after= input.int(2, "Bars to hold AFTER the breaking bar", minval=0, maxval=5, group=g_h, tooltip="v3.6, James's actual rule: the bar that BREAKS the deck does not count. Two more bars must close beyond it, and entry is on the second of those. So three closes above the deck in total - one bar later than the old counting, which treated the breaking bar as the first hold.") stop_buf = input.float(0.05,"Stop buffer (ATR beyond the low)", step=0.05, group=g_h) min_stop = input.float(0.50,"MINIMUM stop distance (ATR)", minval=0.0, step=0.05, group=g_h, tooltip="v3.6c, found in the backtest and it is a LIVE HAZARD. The stop is the lowest low since the neckline formed, clamped to the keel - and when the neckline forms on a bar whose low is almost the entry, that lands a fraction of a cent away. One backtested trade had a 0.58-CENT stop on a $38 stock. At $50 of risk that is 8,600 shares, and min_sh only guards the opposite direction. This floors the stop at a sensible distance so the share count can never blow up.") max_sh = input.int(5000, "Maximum shares (hard cap)", minval=1, group=g_h, tooltip="Second belt on the same problem: however tight the structure looks, never size beyond this.") do_short = input.bool(true,"Mirror it for shorts", group=g_h) per_dir = input.int(3, "Live boats allowed per direction", minval=1, maxval=8, group=g_h, tooltip="v3.5. Was effectively 1, which meant a boat formed early in a decline, set its neckline, and the REAL keel that came later got discarded because the slot was taken. The ADD logic stops double-counting now, so detection can be permissive again.") g_n = "Noise filters - v2.0, from James's own markup" min_flat = input.int(5, "Keel WIDTH - bars sitting near the low", minval=1, maxval=30, group=g_n, tooltip="v2.2. THE number that separates a boat from a V. 1-3 bars near the low = V-bottom, one touch and gone. 5+ = a real base formed. This is NOT how long the neckline takes to break - a boat can be wide AND break fast.") flat_frac = input.float(33, "...counted as bars in the bottom X% of the hull", minval=10, maxval=90, step=5, group=g_n, tooltip="v3.0 FIX. Width used to count bars within half an ATR of the exact low. But a rounded base CURVES - only the very bottom sits that close, so a real 20-bar boat measured as 2 bars wide and got called a V. Now it counts bars spent in the bottom third of the hull, which scales with the boat itself instead of with ATR.") flat_band = input.float(0.5,"...but never narrower than this many ATR", step=0.1, group=g_n) show_v = input.bool(true,"Show V-bottoms too (marked V, not BOAT)", group=g_n, tooltip="A V still gets drawn and labelled, just flagged as a V. James parked the V work - this makes them visible so they can be judged rather than silently dropped.") keel_ref = input.string("Off", "Keel must sit near/below", options=["Off", "VWAP", "Slow MA"], group=g_n, tooltip="v2.1: DEFAULT OFF. v2.0 required the keel at/below VWAP and that was WRONG - a pullback inside a strong uptrend sits well above VWAP and is exactly the trade we want. Leaving it on threw away the good ones. Kept only as an optional experiment.") keel_room = input.float(0.5,"...within this many ATR ABOVE it", step=0.25, group=g_n, tooltip="Keel may be below the line freely, but not extended above it. Measured earlier: decks below VWAP +0.251R vs above +0.164R.") slow_min2 = input.int(40, "Slow MA minutes (for the test above)", minval=2, group=g_n) g_vb = "V-Bottom entry" v_on = input.bool(true, "Take V-Bottoms (fast entry off the low)", group=g_vb, tooltip="A V drops hard and turns immediately. Waiting for a confirmed neckline costs 10 bars, by which time the move has gone. This fires on the turn instead.") v_win = input.int(6, "Must fire within this many bars of the low", minval=1, maxval=20, group=g_vb) v_ang = input.float(20, "8-EMA must turn up at least this steeply (deg)", step=5, group=g_vb, tooltip="James's own tell: the fast MA's slope off the bottom. A V snaps it up hard, a boat turns it gently. Angle is ATR-normalised so it means the same on any stock.") v_brk = input.int(3, "...and price takes out this many bars", minval=1, maxval=10, group=g_vb) g_c = "Context - where price came from" ctx_lb = input.int(30, "Look back this many bars before the setup", minval=5, group=g_c, tooltip="The stretch measured to decide whether price was RISING into the setup (a compression that continues) or FALLING into it (a boat that reverses).") ctx_pct = input.float(0.3, "Move needed to call it a trend (% of price)", step=0.1, group=g_c) split_cd = input.bool(true, "Label boats and compressions apart", group=g_c) g_r = "Position sizing" risk_usd = input.float(100.0, "Risk per trade ($)", minval=1, step=5, group=g_r, tooltip="Matched to Adaptive Mean. Shares = risk / |entry-stop|. $100 risk banks $40 at P1 and $80 at P2 on every trade.") riskMode = input.string("$", "Risk mode", options=["$", "%"], group=g_r, tooltip="Same as Adaptive Mean. $ = Risk per trade. % = riskPct of Account $.") acctSize = input.float(25000.0, "Account $ (for % mode)", minval=1, step=1000, group=g_r) riskPct = input.float(0.5, "Risk % per trade", minval=0.05, step=0.05, group=g_r) min_sh = input.int(1, "Minimum shares to bother", minval=1, group=g_r) useStopCap = input.bool(true, "Skip if stop is too wide", group=g_r, tooltip="Same as Adaptive Mean: if |entry-stop| > Max stop x ATR, do not take the boat.") max_stop = input.float(2.0, "Max stop (x ATR)", step=0.25, minval=0.5, group=g_r) skipChop = input.bool(true, "Skip new boats in CHOP", group=g_r, tooltip="Same chop test as Adaptive Mean: low efficiency + repeated crosses of the 50-min EMA (or a flat rail). Blocks NEW entries only; an open trade still manages.") chopLook = input.int(12, "Chop lookback (bars)", minval=6, maxval=40, group=g_r) chopER = input.float(0.28, "Chop if efficiency <", step=0.02, minval=0.05, maxval=0.8, group=g_r) chopMinX = input.int(3, "Chop if EMA crosses >=", minval=2, maxval=10, group=g_r) // ---- v3.6b: THE STOPS, and only the stops ----------------------------------- use_fail = input.bool(false, "Exit if price closes back through the neckline", group=g_r, tooltip="v3.6b: OFF, at James's call. In v3.6 this fired on ONE close back through the deck with zero tolerance - his CRWD long was cut four cents through 187.67, twenty-nine cents from entry, on a plan whose stated stop was $2.14 away. A 1R plan exiting at 0.14R makes every R in the log a fiction. The bench measured the rule at about 0.006R, so removing it costs nothing measurable and the stated risk finally becomes the real risk.") panic_on = input.bool(true, "PANIC exit on a steep EMA slope against you", group=g_r, tooltip="What James asked for originally: 'this is to be used when price goes against EARLY.' A trail waits for profit first; panic does not. The fast EMA rolling hard the wrong way gets you out whether the trade is up or down.") panic_ang= input.float(25, "...slope that counts as panic (deg)", step=1, group=g_r, tooltip="NOT a guess. The EMA-angle distribution measured for this build: median 11.1 deg, p90 25.8, p95 30.4. 25 sits at about the 90th percentile, so a slope this steep against the position is unusual by construction.") james_x = input.bool(true, "James 30/50/20 exits", group=g_r, tooltip="ON: +1R the 30% lot trails 17-bar EMA on 30-minute; 70% stays at original stop. +2R take the 30%. Close beyond 2R: 50% trails 30m/17 EMA, 20% trails true 5-DMA. Old P1/P2 and EMA-trail ignored while on. PANIC still flattens remaining.") trail_on = input.bool(true, "Also use the EMA trail once in profit", group=g_r) trail_arm= input.float(0.5, "EMA trail arms after this many R", minval=0.1, step=0.1, group=g_r, tooltip="v3.6 hard-coded this at 1R, so a trade that ran half an R and turned had NOTHING between it and the stop - one CRWD short went +0.5R and gave the lot back to -1.00R for -$50.") p_mode = input.string("Fraction of the measured move", "Partial levels", options=["Fraction of the measured move", "Fixed R (1R / 2R)"], group=g_r, tooltip="Fixed 1R/2R partials capture only 2.0R of a 4R structure - 80% of the position comes off before price is halfway to the target the boat projected. Scaling to the measured move keeps the exits proportional to what the setup is actually worth.") p1_frac = input.float(33, "P1 at this % of the measured move", minval=5, maxval=95, step=5, group=g_r) p2_frac = input.float(66, "P2 at this % of the measured move", minval=10, maxval=100, step=5, group=g_r) p1_size = input.float(40, "P1 size (% of position)", minval=0, maxval=90, step=5, group=g_r) p2_size = input.float(40, "P2 size (% of position)", minval=0, maxval=90, step=5, group=g_r) show_usd = input.bool(true, "Show dollars in tooltips", group=g_r) g_f = "Skip gate - what keeps you out" gate_on = input.bool(false, "Enforce the gate", group=g_f, tooltip="v2.4: OFF by default. It was skipping the setup that led to the biggest move. Its numbers were measured on the OLD left-rim entry, which is extended by construction, so they do not transfer to this trigger. Turn on to experiment.") max_ext = input.float(1.5, "Max extension from the fast EMA (ATR)", step=0.1, group=g_f, tooltip="Measured on 9,480 entries: 0-0.5 ATR +0.235R, 0.5-1.5 +0.213R, over 1.5 only +0.088R.") max_ang = input.float(25.0, "Max fast-EMA angle (degrees)", step=1, group=g_f, tooltip="Measured: 0-10 deg +0.240R, 10-25 +0.206R, over 25 only +0.059R.") ema_len = input.int(8, "Fast EMA for the gate", minval=2, group=g_f) rth_only = input.bool(true, "Regular hours only", group=g_f) g_wh = "Export / Webhook" sendEvents = input.bool(true, "Send ENTRY/EXIT events", group=g_wh, tooltip="Fires alert() on every entry, partial and exit so a TradingView webhook can write them to the database. Same contract as SMB2 Fashionably Late, so the v2-gpt/rt monitor and the /tv/dashboard FIFO close work without changes.") eventTag = input.string("SMB_BOAT_EVT", "Webhook tag / indicator name", group=g_wh, tooltip="Lands in the `indicator` column so BOAT rows can be told from Fashionably Late rows.") trade_prefix = input.string("Boat_1", "Trade ID prefix", group=g_wh, tooltip="Makes each running instance unique. Letters, numbers and underscores only - it becomes part of the primary key.") wh_tz = input.string("America/New_York", "Timezone for ts_ny", options=["America/New_York","America/Chicago","America/Denver"], group=g_wh) test_mode = input.bool(false, "Mark events as testing", group=g_wh, tooltip="Adds \"testing\": true so the backend can ignore these while you are still wiring it up.") add_send = input.bool(true, "Send ADDs as a second entry leg", group=g_wh, tooltip="With a real qty column in place, an add can post as another ENTRY on the SAME trade_id. FIFO then pairs every leg and prices the add at its own fill - so the database does the blended-average arithmetic and Pine does not have to.") add_gap = input.int(6, "...minimum bars between adds", minval=1, maxval=40, group=g_wh, tooltip="The add used to fire on EVERY same-direction signal while a position was open - a wall of triangles all marking the same structure. This, plus requiring a genuinely higher deck, makes it mark a real second step.") show_json = input.bool(false, "Log the JSON payload", group=g_wh, tooltip="Prints each payload to the Pine log so it can be checked before the webhook is pointed at production.") g_v = "Visuals" c_up = input.color(#0d9488, "Hull - boat UP", group=g_v) c_dn = input.color(#b45309, "Hull - boat DOWN", group=g_v) c_vbU = input.color(#7c3aed, "Hull - V-bottom UP", group=g_v) c_vbD = input.color(#db2777, "Hull - V-bottom DOWN", group=g_v) c_entL = input.color(#16a34a, "Entry LONG", group=g_v) c_exL = input.color(#065f46, "Exit LONG", group=g_v) c_entS = input.color(#dc2626, "Entry SHORT", group=g_v) c_exS = input.color(#7f1d1d, "Exit SHORT", group=g_v) fill_a = input.int(90, "Hull fill transparency", minval=0, maxval=100, group=g_v) do_fill = input.bool(false, "Fill the hull", group=g_v, tooltip="v2.5.1: OFF. The filled version closed the polyline back along the deck, and with several boats live at once it turned into overlapping blocks rather than the clean hull James draws. Outline only until the fill can be built to look like his.") hull_max = input.int(45, "Hull may reach back this many bars before the keel", minval=10, maxval=150, group=g_v, tooltip="v2.5. The hull used to be drawn from the RIM, up to 120 bars back, so every boat smeared across the chart and they piled on top of each other.") hull_keep= input.int(4, "Keep this many recent hulls", minval=1, maxval=20, group=g_v) show_log = input.bool(true, "Trade log table", group=g_v) c_skip = input.color(#6b7280, "Skipped", group=g_v) hull_w = input.int(2, "Hull width", minval=1, maxval=4, group=g_v) show_panel = input.bool(true, "Status panel (says WHY nothing fired)", group=g_v) show_live = input.bool(false, "SHOW LIVE BOATS - draw the deck it is waiting on", group=g_v, tooltip="OFF by default - live deck/keel tags stack in chop. Turn on to debug a missing entry. Forming count still shows in the status panel.") lblCompact = input.bool(true, "Compact setup labels (details in tooltip)", group=g_v, tooltip="ON: short B UP / B DN / V UP / C UP. Hover for width, risk, deck, keel. SKIP boxes are hidden. OFF: the old three-line boxes.") show_partials = input.bool(false, "Show P1/P2 circles", group=g_v, tooltip="OFF by default - those blue circles are partial-scale marks, not expansion. Turn on to see each scale-out.") tblFont = input.string("Small", "Table font", options=["Tiny", "Small", "Normal", "Large"], group=g_v, tooltip="Pine only has four sizes. Applies to the status panel and the trade log.") // ---------------------------------------------------------------- core e = ta.ema(close, ema_len) atr14 = ta.atr(14) // Chop = Adaptive Mean's test, on the same 50-min rail so both scripts agree on 2m. float tfMinB = math.max(1.0, timeframe.in_seconds() / 60.0) int chopBars = math.max(2, int(math.round(50.0 / tfMinB))) float chopMA = ta.ema(close, chopBars) float chopPath = math.sum(math.abs(close - close[1]), chopLook) float chopNet = math.abs(close - close[chopLook]) float chopEff = chopPath > 0 ? chopNet / chopPath : 1.0 int chopXs = int(math.sum(ta.cross(close, chopMA) ? 1 : 0, chopLook)) bool chopFlat = atr14 > 0 and math.abs(chopMA - chopMA[1]) <= 0.08 * atr14 bool chopRaw = chopEff < chopER and chopXs >= chopMinX var bool isChop = false if chopRaw isChop := true else if chopEff > chopER + 0.12 and chopXs < chopMinX isChop := false bool chopBlock = skipChop and isChop et_h = hour(time, "America/New_York") et_m = minute(time, "America/New_York") rth = (et_h > 9 or (et_h == 9 and et_m >= 30)) and (et_h < 16 or (et_h == 16 and et_m == 0)) ok_time = not rth_only or rth tblSz = tblFont == "Tiny" ? size.tiny : tblFont == "Small" ? size.small : tblFont == "Normal" ? size.normal : size.large tblSzSm = tblFont == "Tiny" ? size.tiny : tblFont == "Small" ? size.tiny : tblFont == "Normal" ? size.small : size.normal f_risk_amt() => riskMode == "%" ? acctSize * riskPct / 100.0 : risk_usd // WHERE PRICE CAME FROM: the move over ctx_lb bars ending at the setup's rim. // Positive = price was rising into it (a compression), negative = falling (a boat). pdh = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on) pdl = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on) dma5 = request.security(syminfo.tickerid, "D", ta.sma(close, 5), lookahead=barmerge.lookahead_off) ma30_17 = request.security(syminfo.tickerid, "30", ta.ema(close, 17), lookahead=barmerge.lookahead_off) var float sesHi = na var float sesLo = na if ta.change(time("D")) != 0 sesHi := high sesLo := low else sesHi := math.max(nz(sesHi, high), high) sesLo := math.min(nz(sesLo, low), low) ema_ang = atr14 > 0 ? math.todegrees(math.atan((e - e[1]) / atr14)) : 0.0 // COMPRESSION: the pause that builds the neckline. A tight range after the rise, // which then EXPANDS through its own high. This is the blue box on James's chart. // ANCHORED VWAP - our own accumulation, not ta.vwap(). ta.vwap() only resets on // the session and cannot be anchored to a chosen point; James's whole AVWAP // method depends on choosing the anchor, so the sums are kept by hand. av_src = input.source(ohlc4, "AVWAP source", group=g_c, tooltip="OHLC4 by default, matching the All-AVWAPs indicator.") av_anc = input.string("Session", "AVWAP anchor", options=["Session", "2-day", "Week", "Month", "Custom date"], group=g_c) av_cust= input.time(timestamp("01 Jan 2026 09:30"), "Custom anchor", group=g_c) newSess = ta.change(time("D")) != 0 newWk = ta.change(time("W")) != 0 newMo = ta.change(time("M")) != 0 var float av_pv = 0.0 var float av_v = 0.0 var float pd_pv = 0.0 var float pd_v = 0.0 bool av_reset = av_anc == "Session" ? newSess : av_anc == "Week" ? newWk : av_anc == "Month" ? newMo : av_anc == "Custom date" ? (time >= av_cust and time[1] < av_cust) : false if av_anc == "2-day" // roll a two-session window: drop the session that is now 2 back if newSess av_pv := pd_pv av_v := pd_v pd_pv := 0.0 pd_v := 0.0 pd_pv += av_src * volume pd_v += volume av_pv += av_src * volume av_v += volume else if av_reset or na(av_v) av_pv := 0.0 av_v := 0.0 av_pv += av_src * volume av_v += volume vwap_ref = av_v > 0 ? av_pv / av_v : close slow_ref = ta.sma(close, math.max(2, math.round(slow_min2 / math.max(1, timeframe.in_seconds() / 60)))) vbrk_hi = ta.highest(high, v_brk)[1] vbrk_lo = ta.lowest(low, v_brk)[1] comp_hi = ta.highest(high, comp_n) comp_lo = ta.lowest(low, comp_n) comp_rng = comp_hi - comp_lo compressed = atr14 > 0 and comp_rng <= squeeze * atr14 comp_tight = atr14 > 0 ? comp_rng / atr14 : 99.0 // SHELF: walking back from the keel low, the most recent stretch of comp_n bars // whose range is under squeeze x ATR AND which sits clear of the keel. That is // where price stopped falling freely and started to consolidate - the stern. f_shelf(int _keelBar, float _keelPx, bool _up) => float dk = na for j = 0 to deck_lb int endB = _keelBar - j float hi = -1e12 float lo = 1e12 for k = 0 to comp_n - 1 int off = bar_index - (endB - k) if off >= 0 and off < 4999 hi := math.max(hi, high[off]) lo := math.min(lo, low[off]) if hi > -1e11 and atr14 > 0 and (hi - lo) <= squeeze * atr14 bool clear = _up ? (lo > _keelPx) : (hi < _keelPx) if clear dk := _up ? hi : lo break dk // FALLBACK DECK: on a sheer waterfall there is no shelf at all - bars are huge // and nothing is tight. v1.8 then fell back to the HIGHEST HIGH nearby, which on // a gap-down open is the very top of the fall (189 on CRWD) - far above anything // tradeable. v1.9 falls back to the most recent LOWER HIGH instead: the last // place the fall paused, even briefly. That is much closer to where James points. f_lastph(int _keelBar, float _keelPx, bool _up) => float lv = na for j = 1 to deck_lb int b0 = _keelBar - j int off = bar_index - b0 if off >= 2 and off < 4997 bool isph = _up ? (high[off] >= high[off + 1] and high[off] >= high[off + 2] and high[off] >= high[off - 1] and high[off] >= high[off - 2]) : (low[off] <= low[off + 1] and low[off] <= low[off + 2] and low[off] <= low[off - 1] and low[off] <= low[off - 2]) if isph float v = _up ? high[off] : low[off] bool clear = _up ? (v > _keelPx) : (v < _keelPx) if clear lv := v break lv // KEEL WIDTH: how many bars actually sat NEAR the low. This is the boat-vs-V // test. Counted within flat_band ATR of the keel low, scanning both sides of it. f_flat(int _keelBar, float _keelPx, float _deck, bool _up) => // the band is a share of the HULL DEPTH, with an ATR floor so a very shallow // boat cannot collapse it to nothing float band = math.max(math.abs(_deck - _keelPx) * flat_frac / 100.0, flat_band * atr14) int n = 0 for j = -40 to 40 int b0 = _keelBar + j int off = bar_index - b0 if off >= 0 and off < 4999 float v = _up ? low[off] : high[off] if math.abs(v - _keelPx) <= band n += 1 n // ---------------------------------------------------------------- boats // A boat is born at a confirmed swing LOW that ended an orderly waterfall. // It has no deck until the RISE prints a swing high - that is the neckline. type Boat int dir int rimBar float rimPx float topPx int keelBar float keelPx int neckBar float neckPx float lowSince int hold int miss var array boats = array.new() ph = ta.pivothigh(high, piv, piv) pl = ta.pivotlow(low, piv, piv) // --- 1+2: an orderly waterfall ending in a confirmed swing low -------------- if not na(pl) int kb = bar_index - piv float kp = pl float best = kp int bb = kb float rimLoc = kp for k = 1 to max_fall int off = piv + k if off < 4999 and (kb - k) >= 0 if high[off] > best best := high[off] bb := kb - k if k <= deck_lb and high[off] > rimLoc rimLoc := high[off] float shelfL = f_shelf(kb, kp, true) if deck_src == "Shelf on the way down" rimLoc := not na(shelfL) ? shelfL : nz(f_lastph(kb, kp, true), rimLoc) int fall = kb - bb float dep = best > 0 ? (best - kp) / best * 100.0 : 0.0 if fall >= min_fall and dep >= min_depth int nL = 0 int oldestL = -1 if array.size(boats) > 0 for q = 0 to array.size(boats) - 1 if array.get(boats, q).dir == 1 nL += 1 if oldestL < 0 oldestL := q if nL < per_dir array.push(boats, Boat.new(1, bb, rimLoc, best, kb, kp, na, na, na, 0, 0)) else if oldestL >= 0 // full - retire the oldest long boat rather than ignore a fresh keel array.remove(boats, oldestL) array.push(boats, Boat.new(1, bb, rimLoc, best, kb, kp, na, na, na, 0, 0)) if do_short and not na(ph) int kb2 = bar_index - piv float kp2 = ph float wrst = kp2 int bb2 = kb2 float rimLoc2 = kp2 for k = 1 to max_fall int off = piv + k if off < 4999 and (kb2 - k) >= 0 if low[off] < wrst wrst := low[off] bb2 := kb2 - k if k <= deck_lb and low[off] < rimLoc2 rimLoc2 := low[off] float shelfS = f_shelf(kb2, kp2, false) if deck_src == "Shelf on the way down" rimLoc2 := not na(shelfS) ? shelfS : nz(f_lastph(kb2, kp2, false), rimLoc2) int fall2 = kb2 - bb2 float dep2 = kp2 > 0 ? (kp2 - wrst) / kp2 * 100.0 : 0.0 if fall2 >= min_fall and dep2 >= min_depth int nS = 0 int oldestS = -1 if array.size(boats) > 0 for q = 0 to array.size(boats) - 1 if array.get(boats, q).dir == -1 nS += 1 if oldestS < 0 oldestS := q if nS < per_dir array.push(boats, Boat.new(-1, bb2, rimLoc2, wrst, kb2, kp2, na, na, na, 0, 0)) else if oldestS >= 0 array.remove(boats, oldestS) array.push(boats, Boat.new(-1, bb2, rimLoc2, wrst, kb2, kp2, na, na, na, 0, 0)) // at most one boat per direction now, so the cap is a safety net only while array.size(boats) > per_dir * 2 + 2 array.shift(boats) // ---------------------------------------------------------------- walk them bool fired = false int F_dir = 0 float F_entry = na float F_stop = na float F_neck = na float F_keel = na int F_kb = 0 int F_flat = 0 int F_rb = 0 float F_rim = na float F_top = na float F_ctx = 0.0 int live_n = 0 string blocked = "no boat forming" string F_kind = "NECK" if array.size(boats) > 0 for idx = array.size(boats) - 1 to 0 Boat b = array.get(boats, idx) bool up = b.dir > 0 live_n += 1 // --- 3+4: the RISE prints the neckline (first swing high after the keel) // ---- V-BOTTOM: fires off the turn, no neckline needed ------------- int vage = bar_index - b.keelBar if v_on and na(b.neckPx) and not fired and vage >= 1 and vage <= v_win and ok_time bool vsteep = up ? ema_ang >= v_ang : ema_ang <= -v_ang bool vbreak = up ? close > vbrk_hi : close < vbrk_lo if vsteep and vbreak fired := true F_kind := "V" F_dir := b.dir F_entry := close F_neck := up ? vbrk_hi : vbrk_lo F_keel := b.keelPx F_kb := b.keelBar F_rb := b.rimBar F_rim := b.rimPx F_top := b.topPx F_flat := f_flat(b.keelBar, b.keelPx, nz(b.neckPx, b.rimPx), up) float vstop = up ? b.keelPx - stop_buf * atr14 : b.keelPx + stop_buf * atr14 // never closer to the entry than min_stop ATR F_stop := up ? math.min(vstop, close - min_stop * atr14) : math.max(vstop, close + min_stop * atr14) int cbv = bar_index - b.rimBar + ctx_lb F_ctx := (cbv < 4999 and cbv >= 0 and close[cbv] != 0) ? (b.rimPx - close[cbv]) / close[cbv] * 100.0 : 0.0 array.remove(boats, idx) if na(b.neckPx) and not fired bool aged = bar_index > b.keelBar + min_keel float span = math.abs(b.rimPx - b.keelPx) float moved = up ? (close - b.keelPx) : (b.keelPx - close) bool risen = span > 0 and (moved / span * 100.0) >= min_rise bool any_first = deck_src == "Whichever forms first" bool use_rise = any_first or deck_src == "First high after the keel" bool use_rim = deck_src == "Shelf on the way down" or deck_src == "Local rim (top of the base)" bool got_rise = up ? (not na(ph) and (bar_index - piv) > b.keelBar + min_keel) : (not na(pl) and (bar_index - piv) > b.keelBar + min_keel) float rise_px = up ? ph : pl if aged and use_rise and got_rise and (up ? rise_px > b.keelPx : rise_px < b.keelPx) b.neckBar := bar_index - piv b.neckPx := rise_px b.lowSince := up ? low : high b.hold := 0 b.miss := 0 else if aged and any_first and risen and compressed // the coil got there before a swing high could confirm b.neckBar := bar_index b.neckPx := up ? comp_hi : comp_lo b.lowSince := up ? low : high b.hold := 0 b.miss := 0 else if aged and not use_rise and (use_rim or (risen and compressed)) b.neckBar := bar_index b.neckPx := use_rim ? b.rimPx : (up ? comp_hi : comp_lo) b.lowSince := up ? low : high b.hold := 0 b.miss := 0 else if not fired blocked := not aged ? "keel still setting" : not risen ? "waiting for the rise off the keel" : "rise has not compressed yet (" + str.tostring(comp_tight, "0.0") + "x ATR, need " + str.tostring(squeeze, "0.0") + ")" else // --- 5: break and hold above the neckline b.lowSince := up ? math.min(b.lowSince, low) : math.max(b.lowSince, high) // One close back inside the deck does not kill the hold. Two in a row does. b.hold := (up ? close > b.neckPx : close < b.neckPx) ? b.hold + 1 : b.hold b.miss := (up ? close > b.neckPx : close < b.neckPx) ? 0 : b.miss + 1 if b.miss >= 2 b.hold := 0 if bar_index - b.neckBar > max_wait or (up ? close < b.keelPx : close > b.keelPx) array.remove(boats, idx) else if not fired blocked := b.hold > 0 ? "broke it, holding " + str.tostring(b.hold - 1) + "b of " + str.tostring(hold_after) : "coiled - waiting for the expansion" float refpx = keel_ref == "VWAP" ? vwap_ref : slow_ref bool place_ok = keel_ref == "Off" or na(refpx) or (up ? b.keelPx <= refpx + keel_room * atr14 : b.keelPx >= refpx - keel_room * atr14) int flatN = f_flat(b.keelBar, b.keelPx, nz(b.neckPx, b.rimPx), up) bool aged_ok = flatN >= min_flat or show_v if b.hold >= hold_after + 1 and ok_time and not place_ok blocked := "keel is extended past " + keel_ref + " - this is the noise zone" else if b.hold >= hold_after + 1 and ok_time and not aged_ok blocked := "V-bottom (" + str.tostring(flatN) + "b wide, boat needs " + str.tostring(min_flat) + ")" if b.hold >= hold_after + 1 and ok_time and place_ok and aged_ok fired := true F_dir := b.dir F_entry := close F_neck := b.neckPx F_keel := b.keelPx F_kb := b.keelBar F_kind := "NECK" F_flat := flatN F_rb := b.rimBar F_rim := b.rimPx F_top := b.topPx int cb = bar_index - b.rimBar + ctx_lb F_ctx := (cb < 4999 and cb >= 0 and close[cb] != 0) ? (b.rimPx - close[cb]) / close[cb] * 100.0 : 0.0 // v2.1 STOP CLAMP. lowSince only ever moves against us, so a // dip after the neckline formed could drag the stop far under // the keel - that is where "risk 3.75%" came from. The boat is // dead if the keel breaks, so the stop can never be worse than // just under the keel itself. float raw = up ? b.lowSince - stop_buf * atr14 : b.lowSince + stop_buf * atr14 float cap = up ? b.keelPx - stop_buf * atr14 : b.keelPx + stop_buf * atr14 float nstop = up ? math.max(raw, cap) : math.min(raw, cap) // never closer to the entry than min_stop ATR F_stop := up ? math.min(nstop, close - min_stop * atr14) : math.max(nstop, close + min_stop * atr14) array.remove(boats, idx) if not fired and na(b.neckPx) and blocked == "no boat forming" blocked := "keel set, waiting for the rise to print a neckline" if bar_index - b.keelBar > max_wait + max_fall array.remove(boats, idx) // ---------------------------------------------------------------- the gate long_ext = atr14 > 0 ? (close - e) / atr14 : 0.0 short_ext = atr14 > 0 ? (e - close) / atr14 : 0.0 ext_now = F_dir > 0 ? long_ext : short_ext ang_now = F_dir > 0 ? ema_ang : -ema_ang string skip_why = "" if fired skip_why := ext_now > max_ext ? "CHASING - " + str.tostring(ext_now, "0.0") + " ATR from the EMA" : ang_now > max_ang ? "TOO STEEP - EMA at " + str.tostring(ang_now, "0") + " deg" : "" float sh_now = fired and math.abs(F_entry - F_stop) > 0 ? math.floor(f_risk_amt() / math.abs(F_entry - F_stop)) : 0 if fired and sh_now > max_sh and skip_why == "" skip_why := "size would be " + str.tostring(sh_now, "0") + " shares - over the " + str.tostring(max_sh) + " cap, stop is too tight" if fired and sh_now < min_sh and skip_why == "" skip_why := "stop too wide for $" + str.tostring(f_risk_amt(), "0") + " - only " + str.tostring(sh_now, "0") + " shares" bool wideStop = fired and useStopCap and atr14 > 0 and math.abs(F_entry - F_stop) > max_stop * atr14 if wideStop and skip_why == "" skip_why := "stop too wide (" + str.tostring(math.abs(F_entry - F_stop) / atr14, "0.0") + " ATR, max " + str.tostring(max_stop, "0.0") + ")" // Chop may skip noisy V-bottoms. A finished neckline boat (keel -> deck hold) still takes. if chopBlock and F_kind == "V" and skip_why == "" skip_why := "CHOP - V in two-sided tape (ER " + str.tostring(chopEff, "0.00") + ", x" + str.tostring(chopXs) + ")" bool oversize = fired and sh_now > max_sh take = fired and not oversize and not wideStop and not (chopBlock and F_kind == "V") and (not gate_on or skip_why == "") bgcolor(isChop ? color.new(#9e9e9e, 92) : na, title="Chop") // ---------------------------------------------------------------- drawing // Hull traced AROUND PRICE from the top of the waterfall, through the keel, // to here. Neckline drawn flat from where it formed. // polylines are kept so old hulls can be deleted instead of piling up // the label's setup name, kept for the ENTRY payload built further down var string kindNow = "BOAT" var array hullIds = array.new() f_hull(_start, _len, _up, _col, _deck) => pts = array.new() int steps = math.min(26, math.max(6, math.floor(_len / 3))) int wide = math.max(1, math.floor(_len / steps)) for s = 0 to steps int b0 = _start + s * wide if b0 <= bar_index float ex = _up ? 1e12 : -1e12 for k = 0 to wide - 1 int off = bar_index - (b0 + k) if off >= 0 and off < 4999 ex := _up ? math.min(ex, low[off]) : math.max(ex, high[off]) if math.abs(ex) < 1e11 array.push(pts, chart.point.from_index(b0, ex)) if array.size(pts) > 1 // only close the shape when it is actually being filled - a closed but // unfilled polyline still draws the return leg along the deck, which is // the line that made the chart look boxed in if do_fill array.push(pts, chart.point.from_index(bar_index, _deck)) array.push(pts, chart.point.from_index(_start, _deck)) pl_id = polyline.new(pts, curved=true, closed=do_fill, line_color=_col, fill_color=do_fill ? color.new(_col, fill_a) : na, line_width=hull_w, xloc=xloc.bar_index) array.push(hullIds, pl_id) while array.size(hullIds) > hull_keep polyline.delete(array.shift(hullIds)) if fired bool up = F_dir > 0 col = F_flat < min_flat ? (up ? c_vbU : c_vbD) : (up ? c_up : c_dn) f_hull(math.max(F_rb, F_kb - hull_max), bar_index - math.max(F_rb, F_kb - hull_max), up, col, F_neck) line.new(F_kb, F_neck, bar_index + 8, F_neck, color=color.new(col, 15), style=line.style_dashed, width=2) line.new(bar_index, F_stop, bar_index + 8, F_stop, color=color.new(#b91c1c, 0), style=line.style_dotted, width=1) float rr = math.abs(F_entry - F_stop) bool isV = F_flat < min_flat bool wasUp = F_ctx > ctx_pct string kind = F_kind == "V" ? "V-BOTTOM" : ((split_cd and wasUp) ? "COMP" : "BOAT") if take kindNow := kind string txtFull = (take ? (kind + (up ? " UP" : " DN")) : "SKIP " + kind) + "\nwidth " + str.tostring(F_flat) + "b to entry " + str.tostring(bar_index - F_kb) + "b" + "\nrisk " + str.tostring(rr / F_entry * 100.0, "0.00") + "%" string txtShort = take ? (kind == "V-BOTTOM" ? (up ? "V UP" : "V DN") : kind == "COMP" ? (up ? "C UP" : "C DN") : (up ? "B UP" : "B DN")) : "SKIP" string txt = lblCompact ? txtShort : txtFull string tip = (take ? "Waterfall, keel, rise, then a COIL - now expanding through it." : "GATE SAYS SKIP: " + skip_why) + "\nneckline (deck) " + str.tostring(F_neck, format.mintick) + "\nkeel WIDTH " + str.tostring(F_flat) + " bars near the low (" + (F_flat < min_flat ? "a V - one touch and gone" : "a real base") + ")" + "\nbars from the low to this entry: " + str.tostring(bar_index - F_kb) + "\nkeel low " + str.tostring(F_keel, format.mintick) + "\nstop " + str.tostring(F_stop, format.mintick) + " = lowest low since the neckline formed" + "\nrisk " + str.tostring(rr / F_entry * 100.0, "0.00") + "% of price" + "\nextension from EMA " + str.tostring(ext_now, "0.00") + " ATR" + "\nEMA angle " + str.tostring(ang_now, "0") + " deg" + "\n\nThis TRIGGER IS NEW and has not been backtested. The older left-rim version showed no edge over a random-entry control. Judge it forward." if take or not lblCompact label.new(bar_index, na, text=txt, tooltip=tip, yloc=up ? yloc.belowbar : yloc.abovebar, style=up ? label.style_label_up : label.style_label_down, color=color.new(col, take ? 0 : 45), textcolor=color.white, size=lblCompact ? size.small : size.normal) // ------------------------------------------------------------- webhook // Same shape as Fashionably Late so one ingest handles both indicators. var string TRADE_ID = na var int LEG_ID = 0 var int trade_no = 0 var int lastAddBar = -9999 var float lastAddDeck = na var float posUnits = 0.0 if ta.change(time("D")) != 0 trade_no := 0 f_num(_v, _f) => na(_v) ? "null" : str.tostring(_v, _f) f_tny() => str.format_time(time, "yyyy-MM-dd HH:mm", wh_tz) sendEvent(_msg) => if sendEvents alert(eventTag + "|" + _msg, alert.freq_once_per_bar_close) // ---------------------------------------------------------------- triangles // Light position tracker so entries and exits are marked. Not a strategy - it // exists to show, on the chart, where this thing would have got in and out. var bool inT = false var float tE = na var float tS = na var int tD = 0 var float tDeck = na var float tRim = na var float tTop = na var float tKeel = na var int tBarI = 0 var float tP1R = 1.0 var float tP2R = 2.0 var float tMMR = 0.0 var int tTime = 0 var bool p1 = false var bool p2 = false var bool tLotA = false var bool tLotB = false var bool tLotC = false var bool tArmed1R = false var bool tHeld2R = false var float tOrigStop = na var float tRealR = 0.0 var string xWhy = "" var array logTxt = array.new() var array logWin = array.new() bool sigEnterL = false bool sigEnterS = false bool sigExit = false bool sigP1 = false bool sigP2 = false bool sigAdd = false if take and inT and F_dir == tD // same boat, second step - not a new trade sigAdd := true if take and not inT inT := true tE := F_entry tS := F_stop tD := F_dir tDeck := F_neck tTime := time tRim := F_rim tTop := F_top tKeel := F_keel tBarI := bar_index float rk0 = math.abs(F_entry - F_stop) float mm0 = math.abs(nz(F_rim, F_entry) - nz(F_keel, F_entry)) tMMR := rk0 > 0 ? mm0 / rk0 : 0.0 tP1R := p_mode == "Fixed R (1R / 2R)" ? 1.0 : math.max(0.25, tMMR * p1_frac / 100.0) tP2R := p_mode == "Fixed R (1R / 2R)" ? 2.0 : math.max(0.50, tMMR * p2_frac / 100.0) p1 := false p2 := false tLotA := true tLotB := true tLotC := true tArmed1R := false tHeld2R := false tOrigStop := F_stop tRealR := 0.0 sigEnterL := F_dir > 0 sigEnterS := F_dir < 0 f_boatLog(float px, float blended, string tag) => array.push(logTxt, str.format_time(tTime, "HH:mm", "America/New_York") + " " + (tD > 0 ? "L " : "S ") + str.tostring(tE, format.mintick) + " -> " + str.tostring(px, format.mintick) + " " + tag + " " + (blended >= 0 ? "+" : "") + str.tostring(blended, "0.00") + "R" + (show_usd ? (" $" + str.tostring(blended * f_risk_amt(), "+0;-0")) : "")) array.push(logWin, blended > 0) while array.size(logTxt) > 8 array.shift(logTxt) array.shift(logWin) if inT float risk1 = math.abs(tE - nz(tOrigStop, tS)) bool failed = use_fail and (tD > 0 ? close < tDeck : close > tDeck) float mfe = tD > 0 ? high - tE : tE - low bool panic = panic_on and (tD > 0 ? ema_ang <= -panic_ang : ema_ang >= panic_ang) if james_x float rPx2 = tD > 0 ? tE + 2.0 * risk1 : tE - 2.0 * risk1 if tD > 0 ? high >= tE + risk1 : low <= tE - risk1 tArmed1R := true if tD > 0 ? close >= rPx2 : close <= rPx2 tHeld2R := true float sA = tOrigStop float sB = tOrigStop float sC = tOrigStop if tLotA and tArmed1R and not na(ma30_17) sA := tD > 0 ? math.max(tOrigStop, ma30_17) : math.min(tOrigStop, ma30_17) if tLotB and tHeld2R and not na(ma30_17) sB := tD > 0 ? math.max(tOrigStop, ma30_17) : math.min(tOrigStop, ma30_17) if tLotC and tHeld2R and not na(dma5) sC := tD > 0 ? math.max(tOrigStop, dma5) : math.min(tOrigStop, dma5) tS := tOrigStop if tLotA tS := tD > 0 ? math.max(tS, sA) : math.min(tS, sA) if tLotB tS := tD > 0 ? math.max(tS, sB) : math.min(tS, sB) if tLotC tS := tD > 0 ? math.max(tS, sC) : math.min(tS, sC) bool origHit = tD > 0 ? low <= tOrigStop : high >= tOrigStop bool a2R = tLotA and (tD > 0 ? high >= rPx2 : low <= rPx2) bool aTr = tLotA and tArmed1R and (tD > 0 ? low <= sA : high >= sA) bool bTr = tLotB and tHeld2R and (tD > 0 ? low <= sB : high >= sB) bool cTr = tLotC and tHeld2R and (tD > 0 ? low <= sC : high >= sC) if panic or failed or origHit float px = origHit ? tOrigStop : close float rr2 = risk1 > 0 ? ((px - tE) / risk1 * tD) : 0.0 float left = (tLotA ? 0.30 : 0.0) + (tLotB ? 0.50 : 0.0) + (tLotC ? 0.20 : 0.0) float blended = tRealR + left * rr2 xWhy := origHit ? ("STOP hit at " + str.tostring(tOrigStop, format.mintick)) : panic ? ("PANIC - EMA rolled " + str.tostring(ema_ang, "0") + " deg against") : "NECKLINE LOST" f_boatLog(px, blended, origHit ? "STOP" : (panic ? "PANIC" : "FAIL")) sigExit := true inT := false tLotA := false tLotB := false tLotC := false else if a2R tRealR := tRealR + 0.30 * 2.0 tLotA := false sigP1 := true xWhy := "2R scale 30%" f_boatLog(rPx2, 2.0, "2R") else if aTr float pxA = sA float rrA = risk1 > 0 ? ((pxA - tE) / risk1 * tD) : 0.0 tRealR := tRealR + 0.30 * rrA tLotA := false sigP1 := true xWhy := "PROT-17 30%" f_boatLog(pxA, rrA, "P17") else if bTr float pxB = sB float rrB = risk1 > 0 ? ((pxB - tE) / risk1 * tD) : 0.0 tRealR := tRealR + 0.50 * rrB tLotB := false sigP2 := true xWhy := "T17 50%" f_boatLog(pxB, rrB, "T17") else if cTr float pxC = sC float rrC = risk1 > 0 ? ((pxC - tE) / risk1 * tD) : 0.0 tRealR := tRealR + 0.20 * rrC tLotC := false xWhy := "T5DMA 20%" f_boatLog(pxC, rrC, "5DMA") if inT and not tLotA and not tLotB and not tLotC sigExit := true inT := false else bool stopHit = tD > 0 ? low <= tS : high >= tS bool trailed = trail_on and (mfe >= trail_arm * risk1) and (tD > 0 ? (close < e and e < e[1]) : (close > e and e > e[1])) if not p1 and risk1 > 0 and mfe >= tP1R * risk1 p1 := true sigP1 := true if not p2 and risk1 > 0 and mfe >= tP2R * risk1 p2 := true sigP2 := true xWhy := stopHit ? ("STOP hit at " + str.tostring(tS, format.mintick)) : panic ? ("PANIC - EMA rolled " + str.tostring(ema_ang, "0") + " deg against the trade (limit " + str.tostring(panic_ang, "0") + ")") : trailed ? ("EMA TRAIL - was " + str.tostring(mfe / risk1, "0.0") + "R up, price lost the turning EMA") : failed ? "NECKLINE LOST - closed back through the deck" : "" if stopHit or failed or trailed or panic sigExit := true inT := false float px = stopHit ? tS : close float rr2 = risk1 > 0 ? ((px - tE) / risk1 * tD) : 0.0 float f1 = p1_size / 100.0 float f2 = p2_size / 100.0 float blended = (p1 ? f1 * tP1R : 0.0) + (p2 ? f2 * tP2R : 0.0) + (1.0 - (p1 ? f1 : 0.0) - (p2 ? f2 : 0.0)) * rr2 f_boatLog(px, blended, (p1 ? "P1" : "--") + (p2 ? "/P2" : "/--")) // plotshape() cannot carry a tooltip, so every marker is a LABEL with a // triangle / cross / circle style. Same look, but each one explains itself. f_pct(float _a, float _b) => _b != 0 ? math.abs(_a) / _b * 100.0 : 0.0 if sigEnterL or sigEnterS bool lup = sigEnterL float mm = math.abs(nz(tRim, tE) - nz(tKeel, tE)) float tgt = lup ? tDeck + mm : tDeck - mm float rsk = math.abs(tE - tS) // WHERE IT CAN GO: nearest level in the way, so the target is not read in a // vacuum. A target beyond a big level is a harder ask than one below it. float nxt = na string nxtNm = "none" if lup if not na(pdh) and pdh > tE and (na(nxt) or pdh < nxt) nxt := pdh nxtNm := "prior-day high" if not na(sesHi) and sesHi > tE and (na(nxt) or sesHi < nxt) nxt := sesHi nxtNm := "session high" if not na(vwap_ref) and vwap_ref > tE and (na(nxt) or vwap_ref < nxt) nxt := vwap_ref nxtNm := "VWAP" else if not na(pdl) and pdl < tE and (na(nxt) or pdl > nxt) nxt := pdl nxtNm := "prior-day low" if not na(sesLo) and sesLo < tE and (na(nxt) or sesLo > nxt) nxt := sesLo nxtNm := "session low" if not na(vwap_ref) and vwap_ref < tE and (na(nxt) or vwap_ref > nxt) nxt := vwap_ref nxtNm := "VWAP" if na(nxt) nxt := lup ? tE + mm : tE - mm nxtNm := "nothing in the way" string tip = "ENTRY " + (lup ? "LONG" : "SHORT") + "\nprice " + str.tostring(tE, format.mintick) + "\ntime " + str.format_time(tTime, "HH:mm", "America/New_York") + " ET" + "\n\ndeck (neckline) " + str.tostring(tDeck, format.mintick) + "\nkeel low " + str.tostring(nz(tKeel, tE), format.mintick) + "\nwaterfall top " + str.tostring(nz(tRim, tE), format.mintick) + "\n\nMEASURED MOVE " + str.tostring(mm, format.mintick) + " (" + str.tostring(f_pct(mm, tE), "0.00") + "% of price)" + "\nprojected target " + str.tostring(tgt, format.mintick) + "\n\nstop " + str.tostring(tS, format.mintick) + " risk " + str.tostring(f_pct(rsk, tE), "0.00") + "%" + "\nmeasured move is " + str.tostring(rsk > 0 ? mm / rsk : 0, "0.0") + "R" + (show_usd ? ("\n\nRISK $" + str.tostring(f_risk_amt(), "0") + " shares " + str.tostring(rsk > 0 ? math.floor(f_risk_amt() / rsk) : 0, "0") + "\nposition $" + str.tostring(rsk > 0 ? math.floor(f_risk_amt() / rsk) * tE : 0, "0") + "\nP1 banks $" + str.tostring(0.40 * f_risk_amt(), "0") + " P2 banks $" + str.tostring(0.80 * f_risk_amt(), "0") + "\nif it runs to the measured move: $" + str.tostring((rsk > 0 ? mm / rsk : 0) * f_risk_amt(), "0")) : "") + "\n\nPLAN P1 +" + str.tostring(p_mode == "Fixed R (1R / 2R)" ? 1.0 : math.max(0.25, (rsk > 0 ? mm / rsk : 0) * p1_frac / 100.0), "0.00") + "R x " + str.tostring(p1_size, "0") + "% P2 +" + str.tostring(p_mode == "Fixed R (1R / 2R)" ? 2.0 : math.max(0.50, (rsk > 0 ? mm / rsk : 0) * p2_frac / 100.0), "0.00") + "R x " + str.tostring(p2_size, "0") + "%" + "\nladder captures " + str.tostring( (p1_size / 100.0) * (p_mode == "Fixed R (1R / 2R)" ? 1.0 : math.max(0.25, (rsk > 0 ? mm / rsk : 0) * p1_frac / 100.0)) + (p2_size / 100.0) * (p_mode == "Fixed R (1R / 2R)" ? 2.0 : math.max(0.50, (rsk > 0 ? mm / rsk : 0) * p2_frac / 100.0)) + (1.0 - p1_size / 100.0 - p2_size / 100.0) * (rsk > 0 ? mm / rsk : 0), "0.00") + "R of the " + str.tostring(rsk > 0 ? mm / rsk : 0, "0.00") + "R move" + "\n(holding it all to target would be " + str.tostring(rsk > 0 ? mm / rsk : 0, "0.00") + "R)" + "\n\nCAME FROM " + (F_ctx > ctx_pct ? "an UPTREND (" : F_ctx < -ctx_pct ? "a DOWNTREND (" : "sideways (") + str.tostring(F_ctx, "+0.00;-0.00") + "% over " + str.tostring(ctx_lb) + " bars)" + "\n -> " + (F_ctx > ctx_pct ? "a COMPRESSION continuing the trend" : "a BOAT reversing off a bottom") + "\n\nCAN GO TO next level up " + str.tostring(nxt, format.mintick) + " (" + str.tostring(rsk > 0 ? math.abs(nxt - tE) / rsk : 0, "0.0") + "R away, " + nxtNm + ")" + "\n " + ((lup ? tgt <= nxt : tgt >= nxt) ? "target is BELOW it - clear air to the target" : "target sits BEYOND it - expect a fight at " + str.tostring(nxt, format.mintick)) // ---- webhook: ENTRY ------------------------------------------------- float _rk = math.abs(tE - tS) float _mm = math.abs(nz(tRim, tE) - nz(tKeel, tE)) trade_no := trade_no + 1 TRADE_ID := trade_prefix + "-" + syminfo.ticker + "-boat-" + str.format_time(tTime, "yyyy-MM-dd-HH:mm:ss", wh_tz) + "-" + str.tostring(trade_no) LEG_ID := 1 posUnits := 1.0 lastAddBar := bar_index lastAddDeck := tDeck string _pe = "{" _pe += "\"indicator\":\"" + eventTag + "\"," _pe += "\"v\":\"boat_v36f\"," _pe += "\"trade_id\":\"" + TRADE_ID + "\"," _pe += "\"leg_id\":\"" + str.tostring(LEG_ID) + "\"," _pe += "\"event_type\":\"ENTRY\"," _pe += "\"entry_type\":\"" + kindNow + "\"," _pe += "\"direction\":\"" + (lup ? "LONG" : "SHORT") + "\"," _pe += "\"sym\":\"" + syminfo.ticker + "\"," _pe += "\"tf\":\"" + timeframe.period + "\"," _pe += "\"ts\":" + str.tostring(tTime) + "," _pe += "\"ts_ny\":\"" + f_tny() + "\"," _pe += "\"entry_px\":" + f_num(tE, "#.####") + "," _pe += "\"stop\":" + f_num(tS, "#.####") + "," _pe += "\"stop_pct\":" + f_num(tE != 0 ? _rk / tE * 100.0 : na, "#.####") + "," _pe += "\"shares\":" + f_num(_rk > 0 ? math.floor(f_risk_amt() / _rk) : na, "#") + "," _pe += "\"risk_usd\":" + f_num(f_risk_amt(), "#.##") + "," _pe += "\"keel\":" + f_num(tKeel, "#.####") + "," _pe += "\"deck\":" + f_num(tDeck, "#.####") + "," // the REAL top of the decline, and separately the 20-bar local high the // measured move is actually computed from - they are not the same point _pe += "\"waterfall_top\":" + f_num(tTop, "#.####") + "," _pe += "\"local_rim\":" + f_num(tRim, "#.####") + "," _pe += "\"measured_move_basis\":\"local_rim\"," // FL's column names, so stop_1_atr / target_1_5_atr stop arriving NULL _pe += "\"stop_1_atr\":" + f_num(tS, "#.####") + "," _pe += "\"target_1_5_atr\":" + f_num(tgt, "#.####") + "," _pe += "\"measured_move\":" + f_num(_mm, "#.####") + "," _pe += "\"measured_move_r\":" + f_num(_rk > 0 ? _mm / _rk : na, "#.##") + "," _pe += "\"target\":" + f_num(tgt, "#.####") + "," _pe += "\"keel_width_bars\":" + str.tostring(F_flat) + "," _pe += "\"bars_low_to_entry\":" + str.tostring(bar_index - F_kb) + "," _pe += "\"ema_len\":" + str.tostring(ema_len) + "," _pe += "\"ema\":" + f_num(e, "#.####") + "," _pe += "\"ema_slope_deg\":" + f_num(ema_ang, "#.##") + "," _pe += "\"atr\":" + f_num(atr14, "#.####") + "," _pe += "\"vwap\":" + f_num(vwap_ref, "#.####") + "," _pe += "\"ext_atr\":" + f_num(ext_now, "#.##") + "," _pe += "\"open\":" + f_num(open, "#.####") + "," _pe += "\"high\":" + f_num(high, "#.####") + "," _pe += "\"low\":" + f_num(low, "#.####") + "," _pe += "\"close\":" + f_num(close, "#.####") + "," _pe += "\"volume\":" + f_num(volume, "#.##") + "," _pe += "\"qty\":1.0," _pe += "\"testing\":" + (test_mode ? "true" : "false") _pe += "}" sendEvent(_pe) if show_json log.info("\nBOAT ENTRY {0}", _pe) label.new(bar_index, na, text="", tooltip=tip, yloc = lup ? yloc.belowbar : yloc.abovebar, style = lup ? label.style_triangleup : label.style_triangledown, color = lup ? c_entL : c_entS, size=size.small) // An add only counts as a second step if time has passed AND the structure has // genuinely moved on - otherwise it is the same setup being re-detected. bool addFresh = sigAdd and inT and not na(TRADE_ID) and (bar_index - lastAddBar) >= add_gap and (na(lastAddDeck) or (tD > 0 ? F_neck > lastAddDeck : F_neck < lastAddDeck)) if addFresh and add_send LEG_ID := LEG_ID + 1 posUnits := posUnits + 1.0 lastAddBar := bar_index lastAddDeck := F_neck float _ark = math.abs(F_entry - F_stop) string _pa = "{" _pa += "\"indicator\":\"" + eventTag + "\"," _pa += "\"v\":\"boat_v36f\"," _pa += "\"trade_id\":\"" + TRADE_ID + "\"," _pa += "\"leg_id\":\"" + str.tostring(LEG_ID) + "\"," _pa += "\"event_type\":\"ENTRY\"," _pa += "\"entry_type\":\"ADD\"," _pa += "\"direction\":\"" + (tD > 0 ? "LONG" : "SHORT") + "\"," _pa += "\"sym\":\"" + syminfo.ticker + "\"," _pa += "\"tf\":\"" + timeframe.period + "\"," _pa += "\"ts\":" + str.tostring(time) + "," _pa += "\"ts_ny\":\"" + f_tny() + "\"," _pa += "\"entry_px\":" + f_num(F_entry, "#.####") + "," _pa += "\"stop\":" + f_num(F_stop, "#.####") + "," _pa += "\"deck\":" + f_num(F_neck, "#.####") + "," _pa += "\"keel\":" + f_num(F_keel, "#.####") + "," _pa += "\"waterfall_top\":" + f_num(F_top, "#.####") + "," _pa += "\"stop_1_atr\":" + f_num(F_stop, "#.####") + "," _pa += "\"shares\":" + f_num(_ark > 0 ? math.floor(f_risk_amt() / _ark) : na, "#") + "," _pa += "\"bars_since_last_leg\":" + str.tostring(bar_index - tBarI) + "," _pa += "\"qty\":1.0," _pa += "\"testing\":" + (test_mode ? "true" : "false") _pa += "}" sendEvent(_pa) if show_json log.info("\nBOAT ADD {0}", _pa) if addFresh label.new(bar_index, na, text="", yloc = F_dir > 0 ? yloc.belowbar : yloc.abovebar, style = F_dir > 0 ? label.style_triangleup : label.style_triangledown, color = color.new(#eab308, 0), size=size.tiny, tooltip = "ADD - " + (F_kind == "V" ? "V-bottom" : "neckline") + " break on the SAME boat" + "\nprice " + str.tostring(close, format.mintick) + "\ntime " + str.format_time(time, "HH:mm", "America/New_York") + " ET" + "\n\nalready long from " + str.tostring(tE, format.mintick) + " at " + str.format_time(tTime, "HH:mm", "America/New_York") + "\nthis is the second step of one trade, not a new one -" + "\nthe log books it once so a single move cannot show up as two wins.") if sigP1 or sigP2 float rkp = math.abs(tE - tS) float lvl = sigP1 ? tE + tD * tP1R * rkp : tE + tD * tP2R * rkp float legR = sigP1 ? tP1R : tP2R float legF = (sigP1 ? p1_size : p2_size) / 100.0 float gain = math.abs(lvl - tE) string wh = (sigP1 ? "PARTIAL 1" : "PARTIAL 2") + " - target +" + str.tostring(legR, "0.00") + "R" + (p_mode == "Fixed R (1R / 2R)" ? " (fixed)" : " (" + str.tostring(sigP1 ? p1_frac : p2_frac, "0") + "% of the measured move)") // ---- webhook: PARTIAL as an EXIT leg, so FIFO can close against it ---- LEG_ID := LEG_ID + 1 string _pp = "{" _pp += "\"indicator\":\"" + eventTag + "\"," _pp += "\"v\":\"boat_v36f\"," _pp += "\"trade_id\":\"" + (na(TRADE_ID) ? "" : TRADE_ID) + "\"," _pp += "\"leg_id\":\"" + str.tostring(LEG_ID) + "\"," _pp += "\"event_type\":\"EXIT\"," _pp += "\"reason\":\"" + (sigP1 ? "P1_PARTIAL" : "P2_PARTIAL") + "\"," _pp += "\"direction\":\"" + (tD > 0 ? "LONG" : "SHORT") + "\"," _pp += "\"sym\":\"" + syminfo.ticker + "\"," _pp += "\"tf\":\"" + timeframe.period + "\"," _pp += "\"ts\":" + str.tostring(time) + "," _pp += "\"ts_ny\":\"" + f_tny() + "\"," _pp += "\"entry_px\":" + f_num(tE, "#.####") + "," _pp += "\"exit_px\":" + f_num(lvl, "#.####") + "," _pp += "\"leg_r\":" + f_num(legR, "#.##") + "," _pp += "\"leg_pct_of_position\":" + f_num(legF * 100.0, "#.#") + "," _pp += "\"shares_off\":" + f_num(rkp > 0 ? math.floor(legF * math.floor(f_risk_amt() / rkp)) : na, "#") + "," _pp += "\"stop\":" + f_num(tS, "#.####") + "," _pp += "\"stop_1_atr\":" + f_num(tS, "#.####") + "," _pp += "\"qty\":" + f_num(posUnits * legF, "#.####") + "," _pp += "\"position_units\":" + f_num(posUnits, "#.##") + "," _pp += "\"testing\":" + (test_mode ? "true" : "false") _pp += "}" sendEvent(_pp) if show_json log.info("\nBOAT PARTIAL {0}", _pp) if show_partials label.new(bar_index, na, text="", yloc=yloc.abovebar, style=label.style_circle, color = sigP1 ? color.new(#0ea5e9, 0) : color.new(#0284c7, 0), size=size.tiny, tooltip = wh + "\nfill level " + str.tostring(lvl, format.mintick) + "\ntime " + str.format_time(time, "HH:mm", "America/New_York") + " ET" + "\n\nsize off 40% of the position" + "\nthis leg +" + str.tostring(legR, "0.00") + "R (" + str.tostring(gain, format.mintick) + " per share, " + str.tostring(tE != 0 ? gain / tE * 100.0 : 0, "0.00") + "%)" + "\nbanked +" + str.tostring(legF * legR, "0.00") + "R of the whole trade" + (show_usd ? ("\nshares off " + str.tostring(rkp > 0 ? math.floor(legF * math.floor(f_risk_amt() / rkp)) : 0, "0") + " cash $" + str.tostring(legF * legR * f_risk_amt(), "0")) : "") + "\n\nentry " + str.tostring(tE, format.mintick) + " at " + str.format_time(tTime, "HH:mm", "America/New_York") + " stop " + str.tostring(tS, format.mintick)) if sigExit float rk = math.abs(tE - tS) float rr3 = rk > 0 ? (close - tE) / rk * tD : 0.0 // real sizes and real levels - the old tooltip hard-coded 0.40R / 0.80R, // which stopped being true once sizes and levels became inputs float pf1 = p1 ? p1_size / 100.0 : 0.0 float pf2 = p2 ? p2_size / 100.0 : 0.0 float fr = 1.0 - pf1 - pf2 float totR = pf1 * tP1R + pf2 * tP2R + fr * rr3 // ---- webhook: FINAL EXIT, carrying the rule that fired --------------- LEG_ID := LEG_ID + 1 string _px = "{" _px += "\"indicator\":\"" + eventTag + "\"," _px += "\"v\":\"boat_v36f\"," _px += "\"trade_id\":\"" + (na(TRADE_ID) ? "" : TRADE_ID) + "\"," _px += "\"leg_id\":\"" + str.tostring(LEG_ID) + "\"," _px += "\"event_type\":\"EXIT\"," _px += "\"reason\":\"" + xWhy + "\"," _px += "\"direction\":\"" + (tD > 0 ? "LONG" : "SHORT") + "\"," _px += "\"sym\":\"" + syminfo.ticker + "\"," _px += "\"tf\":\"" + timeframe.period + "\"," _px += "\"ts\":" + str.tostring(time) + "," _px += "\"ts_ny\":\"" + f_tny() + "\"," _px += "\"entry_px\":" + f_num(tE, "#.####") + "," _px += "\"exit_px\":" + f_num(close, "#.####") + "," _px += "\"stop\":" + f_num(tS, "#.####") + "," _px += "\"stop_1_atr\":" + f_num(tS, "#.####") + "," _px += "\"total_r\":" + f_num(totR, "#.##") + "," _px += "\"total_usd\":" + f_num(totR * f_risk_amt(), "#.##") + "," _px += "\"p1_hit\":" + (p1 ? "true" : "false") + "," _px += "\"p2_hit\":" + (p2 ? "true" : "false") + "," _px += "\"bars_held\":" + str.tostring(bar_index - tBarI) + "," _px += "\"ema_slope_deg\":" + f_num(ema_ang, "#.##") + "," _px += "\"atr\":" + f_num(atr14, "#.####") + "," _px += "\"qty\":" + f_num(posUnits * (1.0 - (p1 ? p1_size / 100.0 : 0.0) - (p2 ? p2_size / 100.0 : 0.0)), "#.####") + "," _px += "\"position_units\":" + f_num(posUnits, "#.##") + "," _px += "\"testing\":" + (test_mode ? "true" : "false") _px += "}" sendEvent(_px) if show_json log.info("\nBOAT EXIT {0}", _px) TRADE_ID := na LEG_ID := 0 posUnits := 0.0 lastAddBar := -9999 lastAddDeck := na label.new(bar_index, na, text="", yloc = tD > 0 ? yloc.abovebar : yloc.belowbar, style=label.style_xcross, color = tD > 0 ? c_exL : c_exS, size=size.tiny, tooltip = "EXIT " + (tD > 0 ? "LONG" : "SHORT") + "\nWHY: " + xWhy + "\nprice " + str.tostring(close, format.mintick) + "\ntime " + str.format_time(time, "HH:mm", "America/New_York") + " ET" + "\nheld " + str.tostring(bar_index - tBarI) + " bars" + "\n\nentry " + str.tostring(tE, format.mintick) + " at " + str.format_time(tTime, "HH:mm", "America/New_York") + "\nstop " + str.tostring(tS, format.mintick) + "\n\nlegs, in R and in cash at $" + str.tostring(f_risk_amt(), "0") + " risk:" + "\n P1 " + (p1 ? (str.tostring(pf1 * 100.0, "0") + "% at +" + str.tostring(tP1R, "0.00") + "R = +" + str.tostring(pf1 * tP1R, "0.00") + "R $" + str.tostring(pf1 * tP1R * f_risk_amt(), "+0;-0")) : "never hit") + "\n P2 " + (p2 ? (str.tostring(pf2 * 100.0, "0") + "% at +" + str.tostring(tP2R, "0.00") + "R = +" + str.tostring(pf2 * tP2R, "0.00") + "R $" + str.tostring(pf2 * tP2R * f_risk_amt(), "+0;-0")) : "never hit") + "\n run " + str.tostring(fr * 100.0, "0") + "% at " + str.tostring(rr3, "+0.00;-0.00") + "R = " + str.tostring(fr * rr3, "+0.00;-0.00") + "R $" + str.tostring(fr * rr3 * f_risk_amt(), "+0;-0") + "\n ------------------------------" + "\n TOTAL " + str.tostring(totR, "+0.00;-0.00") + "R $" + str.tostring(totR * f_risk_amt(), "+0;-0") + "\n shares " + str.tostring(rk > 0 ? math.floor(f_risk_amt() / rk) : 0, "0")) var table logT = table.new(position.bottom_right, 1, 10, bgcolor=color.new(#131722, 10), frame_color=color.new(color.gray, 55), frame_width=1) if show_log and barstate.islast table.clear(logT, 0, 0, 0, 9) table.cell(logT, 0, 0, " time side entry -> exit R ", text_color=color.white, text_size=tblSzSm, bgcolor=color.new(#2A2E39, 0)) int row = 1 if inT table.cell(logT, 0, row, " OPEN " + (tD > 0 ? "L " : "S ") + str.tostring(tE, format.mintick) + " stop " + str.tostring(tS, format.mintick), text_color=#58a6ff, text_size=tblSz) row += 1 if array.size(logTxt) > 0 for q = 0 to array.size(logTxt) - 1 if row <= 9 table.cell(logT, 0, row, array.get(logTxt, q), text_color=array.get(logWin, q) ? #3fb950 : #f85149, text_size=tblSz) row += 1 // ---------------------------------------------------------------- live boats // Draw what the code is CURRENTLY tracking, so a wrong deck is visible as a // number on the chart rather than as a missing label. var array liveL = array.new() var array