Uptrick: Price Memory Trend Strategy by shravanreddy0808
By shravanreddy0808
Performance Metrics
- Author: shravanreddy0808
- Symbol: AMEX:SPY
- Timeframe: 1 minute
- Net P&L: −42,440.50 USD (−4.25%)
- Win Rate: 30.8%
- Profit Factor: 0.852
- Max Drawdown: 61,865.78 USD (6.16%)
- Total Trades: 727
Description
Here are clear, structured notes explaining the Pine Script code — the simplified "LSTM-like" trend predictor you were given earlier.Overall Purpose of the ScriptThe script tries to imitate LSTM memory behavior (long-term memory + selective forgetting/updating) using only Pine Script's basic math and variables — because real LSTM neural networks (with matrices, multiple gates, backpropagation) are not possible in Pine.It creates a persistent memory line that:slowly forgets old information,selectively accepts new price information,tries to act as a trend-following / regime-detecting centerline.Then it uses momentum of this memory line + deviation size to decide whether the market is in an uptrend or downtrend.Key Sections Explained1. Inputs (tunable parameters)pinescriptmemoryStrength = input.float(0.14, "Forget Gate strength (like 1-f)", step=0.01, minval=0.01, maxval=0.99)inputGate = input.float(0.22, "Input Gate strength", step=0.01, minval=0.01, maxval=1.0)cellDecay = input.float(0.965, "Cell state decay", step=0.001, minval=0.8, maxval=0.999)lookback = input.int(21, "Lookback for momentum", minval=5)sensitivity = input.float(1.35, "Trend sensitivity multiplier", step=0.05)ParameterWhat it controlsTypical effectHigher value means…memoryStrengthHow aggressively old memory is forgottenControls "forget gate" strengthForgets faster, more responsiveinputGateHow much new price is allowed into memoryControls how much price influences cellMemory follows price more closelycellDecayNatural fading of long-term memory per barPrevents memory from living foreverLower = memory fades fasterlookbackPeriod for momentum and deviation calculationSmoothness of trend detectionLonger = smoother, fewer signalssensitivityHow strong momentum must be to flip trendFinal trigger strictnessHigher = fewer but stronger signals2. Memory Variables (the "LSTM core")pinescriptvar float cell = na // long-term memory ≈ cell state Cvar float hidden = na // short-term state ≈ hidden state hif bar_index == 0 cell := price hidden := pricecell → tries to act like LSTM cell state (long memory)hidden → tries to act like LSTM hidden state (what we actually observe/use)3. Simplified Gatespinescriptforget = math.tanh(hidden * memoryStrength)i_gate = math.tanh(price * inputGate)candidate = price - hiddenforget — value between -1 and +1, but we treat higher positive = forget morei_gate — how much new info we want to acceptcandidate — the new information we could add (difference from current hidden)Very crude approximation — real LSTM uses sigmoid + learned weights.4. Core LSTM-like Update Rulepinescriptcell := cell * (1 - forget) + candidate * i_gatecell := cell * cellDecayhidden := cell * 0.65 + price * 0.35This is the heart of the "fake LSTM":Keep (1 – forget) of old cellAdd a portion (i_gate) of the candidate changeApply slow exponential decay (cellDecay 1.0 and trendScore[1] = -1.0if bullCondition trend := 1else if bearCondition trend := -1else trend := nz(trend[1])Only changes trend when crossing the threshold from the other sidePrevents flickering / frequent flippingPersistent until strong opposite signal appears7. Visualization SummaryBackground tint (light green/red)Thick memory line (changes color with trend)Dashed ±1.6× deviation bandsBig up/down labels on trend flipsAlert conditions on every new trend directionQuick Tuning GuideGoalSuggestionFewer but stronger signals↑ sensitivity (1.6–2.2), ↑ lookback (30–60)More responsive / earlier entries↑ inputGate, ↓ cellDecay, ↓ memoryStrengthSmoother memory line↓ inputGate, ↑ cellDecay (0.98+)Better in choppy markets↑ lookback, ↑ sensitivityBetter in trending markets↓ lookback, moderate sensitivity (~1.2–1.5)Most Important TakeawayThis is not a real LSTM — it's a hand-crafted, analog-style memory filter inspired by LSTM ideas.It tries to combine:slow-adapting memory (like EMA but with forgetting control)selective update depending on current deviationmomentum-of-memory as trend strengthMany traders find this kind of memory line more "intelligent" than simple moving averages when tuning the forget/input/decay parameters to match the market personality.