Random State Machine Strategy by smoyer
By robbatt
Performance Metrics
- Author: robbatt
- Symbol: NASDAQ:TSLA
- Timeframe: 30 minutes
- Net P&L: +2,248.40 USD (+2.25%)
- Win Rate: 45.7%
- Profit Factor: 2.146
- Max Drawdown: 174.32 USD (0.17%)
- Total Trades: 1,077
- Sharpe Ratio: β3.062
Description
π Random State Machine Strategy (Educational)This strategy showcases a randomized entry model driven by a finite state machine, integrated with user-defined exit controls and a full-featured moving average filter.π§ Trade Entry LogicEntries occur only when:A random trigger occurs (~5% probability per bar)The state machine accepts a new transition (sm.step())Price is:Above the selected MA for long entriesBelow the selected MA for short entriesThis ensures that entries are both stochastically driven and trend-aligned, avoiding frequent or arbitrary trades.βοΈ How It WorksRandomized TriggersA pseudo-random generator (seeded with time and volume) attempts to trigger state transitions.Finite State MachineTransitions are managed using the StateMachine from robbatt/lib_statemachine β credit to robbatt for the modular FSM design.Controlled ResetThe state machine resets every N bars (default: 100) if at least two transitions have occurred. This prevents stale or locked states.Backtest RangeDefine a specific test window using Start and End Date inputs.Risk & ExitsSpecify risk in points and a target risk/reward ratio. TP is auto-computed. Timed and MA-based exits can be toggled.π§ͺ How to UseEnable Long or Short tradesChoose your Moving Average type and lengthSet Risk per trade and R/R ratioToggle TP/SL, timed exit, or MA cross exitAdjust the State Reset Interval to suit your signal frequencyπ NotesEducational use only β not financial adviceRandom logic is used to model structure, not predict movementThanks to robbatt for the lib_statemachine integration