0bps

Strategy vault / Other

Highest high lowest low stop

Pine Script strategy by Zer3192.

Pine ScriptOther
Author
Zer3192
Complexity
Starter · 46 lines
Parameters
2

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
v_input_120Highest High Lookback
v_input_220Lowest Low Lookback

Source Pine Script

//@version=3
strategy(title="Highest high/lowest low stop", overlay=true)

// STEP 1:
// Make inputs for length of highest high and lowest low
hiLen = input(title="Highest High Lookback", type=input.integer,
     defval=20, minval=2)

loLen = input(title="Lowest Low Lookback", type=input.integer,
     defval=20, minval=2)

// STEP 2:
// Calculate recent extreme high and low
hiHighs = highest(high, hiLen)[1]
loLows  = lowest(low, loLen)[1]

// Plot stop values for visual confirmation
plot(series=(strategy.position_size > 0) ? loLows : na,
     style=circles, color=green, linewidth=3,
     title="Lowest Low Stop")

plot(series=(strategy.position_size < 0) ? hiHighs : na,
     style=circles, color=red, linewidth=3,
     title="Highest High Stop")

// Trading conditions for this example strategy
higherCloses = (close > close[1]) and
     (close[1] > close[2]) and (close[2] > close[3])
lowerCloses = (close < close[1]) and
     (close[1] < close[2]) and (close[2] < close[3])
isFlat = (strategy.position_size == 0)

// Submit entry orders
if (isFlat and higherCloses)
    strategy.entry(id="EL", long=true)

if (isFlat and lowerCloses)
    strategy.entry(id="ES", long=false)

// STEP 3:
// Submit stops based on highest high and lowest low
if (strategy.position_size > 0)
    strategy.exit(id="XL HH", stop=loLows)

if (strategy.position_size < 0)
    strategy.exit(id="XS LL", stop=hiHighs)

Published by Zer3192 on the FMZ strategy square · last modified 2023-01-07. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Highest-high-lowest-low-stop.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open