Skip to main content

Why Inputs and Variables Matter When Building a Trading Bot

Understand Inputs vs Variables in the Builder. Learn when to use fixed MT5 settings, when to use dynamic stored values, and how blocks modify, calculate, compare, and reuse values in your EA.

Summary

Inputs and Variables both store values for your EA, but they are used for different jobs.

The simple rule:

Inputs = settings you choose before the EA starts 
Variables = values the EA can remember and update while it runs

Use Inputs for settings you want to adjust in MT5 before running or backtesting, like risk %, stop loss size, or indicator period.

Use Variables when the bot needs to store, update, or remember something during the strategy, like today’s high, previous candle low, a daily trade gate, or a custom calculation.

Also known as: bot settings, MT5 inputs, stored values, dynamic values, variable logic, Formula values, Modify Variables, previous candle high, session high/low.


The core mental model

Think of your EA like a simple decision system.

It needs three things:

  1. Settings
    Values you choose before the EA starts -> INPUTS

  2. Memory
    Values the bot stores and updates while it runs -> VARIABLES

  3. Logic blocks
    Blocks that read, compare, calculate, or change those values.

In the Builder, that means:

Input = setting Variable = memory 
Formula block = calculate and store a value Modify
Variables block = directly change a variable
Trade Rule block = compare two values

Example:

Input: Risk_Per_Trade = 1% 
Variable: Previous_High = 0

Run per Candle
→ Modify Variables: Previous_High = Candle High ID 1
→ Trade Rule: Bid crosses above Previous_High
→ Buy Now

The input controls the risk setting.
The variable stores the previous candle high.
The Trade Rule checks whether price breaks that stored level.

That is the basic flow.


Inputs vs Variables in one table

Question

Use Input

Use Variable

Should the user set this before the EA starts?

Yes

No

Should it appear in the MT5 EA settings?

Yes

No

Should it change while the EA is running?

No

Yes

Is it used for optimization/backtesting settings?

Yes

Sometimes

Is it used to remember market data or strategy state?

No

Yes

Can Formula or Modify Variables update it?

No

Yes

Can it be visualized on the MT5 chart?

No

Yes


Inputs

What is an Input?

An Input is a fixed setting.

You choose it before starting the EA or before running a backtest in MT5.

Once the EA is running, the input stays the same.

Use inputs for values you want to test, optimize, or adjust without rebuilding the project.


Common Input examples

Use inputs for:

  • Risk per trade

  • Lot size

  • Stop loss size

  • Take profit size

  • Moving Average period

  • RSI period

  • Maximum spread

  • Session start time

  • Session end time

  • On/off switches for optional logic

Example:

Input: Risk_Per_Trade = 1 
Input: Stop_Loss_Pips = 30
Input: Take_Profit_Pips = 60
Input: MA_Period = 20

These are settings. The user can adjust them in MT5 before running the EA.


When should I use an Input?

Use an input when the value should be adjustable from MT5 before the EA starts.

Good question to ask:

“Do I want to change this setting before running or backtesting?”

If yes, use an Input.

Example:

You want to test a Moving Average strategy with different periods:

MA_Period = 20 
MA_Period = 50
MA_Period = 100

That should be an input because you want to adjust it before testing.


Important limitation

Inputs do not update while the EA runs.

If the value needs to change during the strategy, use a Variable instead.

Bad use of input:

Today_High = input

The daily high changes while the market moves. That should be a variable, not an input.


Variables

What is a Variable?

A Variable is a value the EA can store, update, and reuse while it runs.

Think of a variable as the bot’s memory.

At first, a variable usually starts with a default value like 0.

Then blocks can update it later.

Example:

Variable: London_High = 0

At the start, the bot knows nothing yet, so the value is 0.

Later, the EA can update it:

Modify Variables: London_High = Highest High of London session

Now the bot remembers the London high and can use it in a Trade Rule.


Common Variable examples

Use variables for:

  • Previous candle high

  • Previous candle low

  • Session high

  • Session low

  • Daily high

  • Daily low

  • Trade gate: 0 or 1

  • Counter

  • Custom indicator signal

  • Candle range

  • ATR stop size

  • Breakout level

  • Last trade time

  • Whether a condition already happened

Example:

Variable: Buy_Gate = 0 
Variable: Previous_High = 0
Variable: London_High = 0
Variable: ATR_Stop_Size = 0

Show variables on the MT5 chart

You can show variable values directly on the MT5 chart while testing your EA. In the Inputs & Variables window, click the eye icon next to the variable you want to track. After exporting and running the EA in MT5 Visual Mode, the selected variable appears on the chart. This is useful for checking if values like Previous_High, London_High, Buy_Gate, or ATR_Stop_Size are being stored, updated, and reset correctly. Use this as a simple debugging method before changing your strategy logic.


When should I use a Variable?

Use a variable when the EA needs to remember or update something while it runs.

Good question to ask:

“Does the bot need to calculate, store, update, or remember this value?”

If yes, use a Variable.


How Variables connect to blocks

Variables do nothing by themselves.

They become useful when blocks interact with them.

1. Create the variable

Example:

Variable: Previous_High = 0

This creates a named storage container.


2. Modify the variable

Use Modify Variables when you want to directly assign a value.

Example:

Previous_High = Candle High ID 1

This stores the high of the last closed candle.


3. Calculate a variable

Use Formula when you need a calculation.

Example:

Candle_Range = Candle High ID 1 - Candle Low ID 1

The 'Formula' block calculates the range and stores the result in Candle_Range.


4. Compare the variable

Use a Trade Rule when you want to compare the variable against another value.

Example:

Bid crosses above Previous_High

If true, the bot can continue to the next block.


5. Use the variable in execution or management

Variables can be used for:

  • Entry levels

  • Stop loss distances

  • Take profit distances

  • Trade filters

  • Management logic

  • Daily limits

  • Session breakout levels

Example:

Buy Pending Order at London_High

The EA uses the stored variable as the order level.


Example 1: Stock example

Goal

Buy a stock CFD if price breaks above the previous candle high.

Use an input for risk and a variable for the previous high.

Setup

Input: Risk_Per_Trade = 1 Variable: Previous_High = 0

Logic

Run per Candle → Modify Variables: Previous_High = Candle High ID 1

This updates Previous_High once every new candle.

Then:

Run per Tick 
→ Trade Rule: Bid crosses above Previous_High
→ Count Trades: Buy trades = 0
→ Buy Now

Why this works

Risk_Per_Trade is an input because it is a setting you choose before running.

Previous_High is a variable because it changes every candle.


Example 2: Forex example

Goal

Trade a breakout of the London session high on EURUSD.

Use an input for maximum spread and a variable for the London high.

Setup

Input: Max_Spread = 20 Variable: London_High = 0

Logic

At the end of the London session:

Run at Time: 15:00 → Modify Variables: London_High = Highest Candle High from Candle ID 1 to Candle ID 8

During the New York session:

Run in Session: 15:00 to 21:00 
→ Check Spread: spread below Max_Spread
→ Trade Rule: Bid crosses above London_High
→ Count Trades: Buy trades = 0
→ Buy Now

Why this works

Max_Spread is an input because you may want to adjust it before testing.

London_High is a variable because it changes every day based on the session.


Example 3: Previous candle high and low

Goal

Store the previous candle high and low, then use them as breakout levels.

Setup

Variable: Previous_Candle_High = 0 Variable: Previous_Candle_Low = 0

Store the values

Run per Candle 
→ Modify Variables:
Previous_Candle_High = Candle High ID 1
Previous_Candle_Low = Candle Low ID 1

Candle ID 1 means the last fully closed candle.

Do not use Candle ID 0 for this example, because Candle ID 0 is still forming and can change.

Use the values

Buy breakout:

Trade Rule: Bid crosses above Previous_Candle_High 
→ Count Trades: Buy trades = 0
→ Buy Now

Sell breakout:

Trade Rule: Bid crosses below Previous_Candle_Low 
→ Count Trades: Sell trades = 0
→ Sell Now

Why this works

The EA stores the previous candle levels first.

Then it uses those stored levels in Trade Rules.

That is the logic flow:

Store level 
→ Compare price to level
→ Execute trade if true

Example 4: Daily trade gate

Goal

Allow only one buy trade per day.

Setup

Variable: Buy_Gate = 0

Meaning:

0 = buy allowed 
1 = buy blocked

Entry logic

Run per Candle 
→ Trade Rule: Buy_Gate = 0
→ Buy Now
→ Modify Variables: Buy_Gate = 1

After the trade opens, the EA changes Buy_Gate from 0 to 1.

Now the next buy trade is blocked.

Reset logic

Run at Time: 01:00 
→ Modify Variables: Buy_Gate = 0

The next day, the gate resets and buying is allowed again.

Why this works

The variable remembers whether the bot already traded today.

An input cannot do this because the value must change while the EA runs.


Data types

Inputs and Variables both need a data type.

Use the type that matches the value.

Double / Number

Use for decimal numbers.

Examples:

Risk_Per_Trade = 1.0 
Stop_Loss_Pips = 30
London_High = 1.08500

Best for:

  • Prices

  • Risk %

  • Lot size

  • Indicator values

  • Stop loss values

  • Take profit values


Boolean / True-False

Use for simple on/off settings.

Examples:

Use_RSI_Filter = true 
Use_Trailing_Stop = false

In many strategy examples, we also use 0 and 1 variables:

0 = off / false / inactive 
1 = on / true / active

Example:

Buy_Gate = 0 
HMA_Green = 1

Timeframe

Use when a setting should let you choose a timeframe.

Example:

Signal_Timeframe = H1 
Trend_Timeframe = H4

Datetime

Use when you need a specific date or time reference.

Example:

Start_Date 
End_Date
Last_Trade_Time

How to check if variables work

You can show variables directly on the MT5 chart.

In the Inputs & Variables panel, click the eye icon next to the variable.

Then export and test in MT5 Visual Mode.

Use this to check:

  • Is the variable updating?

  • Is the value correct?

  • Does it reset at the right time?

  • Is the stored price level correct?

  • Does the Trade Rule compare against the right value?

Example:

If London_High should store the session high, show it on the chart and confirm the value before trusting the breakout logic.


Common mistakes

Mistake 1: Using an Input when the value should update

Bad:

Previous_High = Input

Better:

Previous_High = Variable 
Run per Candle → Modify Variables: Previous_High = Candle High ID 1

If the value changes while the EA runs, it should be a variable.


Mistake 2: Creating a variable but never modifying it

If you create:

London_High = 0

but never update it, the value stays 0.

You need a block like:

Modify Variables: London_High = Highest High of session

Mistake 3: Modifying a variable too often

If you place a Modify Variables block after Run per Tick, the variable may update many times per second.

That can be useful for live price tracking, but dangerous if you only wanted one update per candle.

Use:

Run per Candle

when the value should update once per candle.


Mistake 4: Using Candle ID 0 when you need a closed candle

Candle ID 0 is the current forming candle.

Its high, low, close, and indicator values can still change.

For most stable logic, use:

Candle ID 1 = last fully closed candle

Mistake 5: Expecting variables to appear in MT5 settings

Inputs appear in the MT5 EA settings.

Variables do not.

Variables are controlled by the strategy logic while the EA runs.


Best practice workflow

Use this order when building with inputs and variables:

1. Decide what should be adjustable before running    
→ create Inputs

2. Decide what the bot must remember while running
→ create Variables

3. Decide when the variable should update
→ Run per Candle / Run at Time / Run in Session / Run per Tick

4. Store or calculate the value
→ Modify Variables / Formula

5. Use the value
→ Trade Rule / Buy Now / Sell Now / Pending Order / Management block

6. Export and test in MT5 Visual Mode
→ use the eye icon to check the variable values

Quick decision guide

Use this when you are unsure.

You want to...

Use

Adjust risk before testing

Input

Adjust stop loss before testing

Input

Test different MA periods

Input

Enable or disable a filter

Input

Store previous candle high

Variable

Store London session high

Variable

Store today’s low

Variable

Count candles

Variable

Remember if a trade happened today

Variable

Calculate candle range

Formula + Variable

Reset a value daily

Run at Time + Modify Variables

Compare price to stored level

Trade Rule

Show value on MT5 chart

Variable eye icon


Conclusion

Inputs and Variables are not the same.

Use this simple rule:

Inputs are settings. Variables are memory. Blocks control when values are read, changed, calculated, compared, or used.

If the value should be chosen before the EA starts, use an Input.

If the value should update while the EA runs, use a Variable.

When building, always think in this flow:

Create value → Update value → Compare value → Use value → Test in MT5 Visual Mode
Did this answer your question?