LOGIN

Join & EARN

FOREX ALGOS { }

What We Do

BlackBox

Backtest Results How It Works Full Refund Promise Supported Brokers Income Targets

Robots Glossary

State (State Machine)

State - A variable or construct that represents the current “mode” of the bot. Although not specific to trading, state machines are often used in EAs to handle multi-step logic. For example, a strategy might have states like WaitingForSignalPositionOpenTrailingStopActive. By tracking state, the code ensures it doesn’t repeatedly enter or exit at the wrong time.

  • Definition: A value (often an enum or bool) that indicates what the strategy is currently doing.

  • Context: For example, a flag isPositionOpen can prevent new entries until the current trade exits. Or an enum TradeState { None, Long, Short } can guide logic.

  • Example:

    enum State { Waiting, LongOpen, ShortOpen }; State currentState = Waiting; // In OnTick(): if (currentState == Waiting && buyCondition) { OrderSend(...); currentState = LongOpen; } if (currentState == LongOpen && sellCondition) { OrderClose(...); currentState = Waiting; }

    This ensures the EA knows whether it’s in a position or not.

Each of these terms plays a crucial role in the design and implementation of Forex trading robots. By understanding and correctly implementing these logic components – often via built-in functions or language constructs like iffor, and strategy-specific methods – developers can build robust automated strategies. All examples here illustrate how these concepts translate into code across MetaTrader (MQL), cTrader (C#), and NinjaTrader (NinjaScript) environments.