Many traders want to modify parameters in free EA source code but don‘t understand MQL4 syntax. This source code interpretation walks through a complete trailing stop script – a simpler starting point than a full EA. After reading, you’ll be able to compile and modify scripts confidently.
The Complete Source Code (Trailing Stop Script)
```cpp
//+------------------------------------------------------------------+
//| Trailing.mq4 |
//| Generated by AutoCompile AI |
//| |
//+------------------------------------------------------------------+
#property copyright "AutoCompile AI"
#property link ""
#property version "1.00"
#property strict
#property show_inputs
input int TrailingStart = 15; // Trailing activates after 15 pips profit
input int TrailingStep = 10; // Trail distance in pips
input int Slippage = 30; // Slippage for modify orders
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() != Symbol()) continue;
if(OrderType() == OP_BUY)
{
double profitPips = (Bid - OrderOpenPrice()) / Point;
if(profitPips > TrailingStart)
{
double newStopLoss = Bid - TrailingStep * Point;
if(newStopLoss > OrderStopLoss())
OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, OrderTakeProfit(), 0, clrBlue);
}
}
else if(OrderType() == OP_SELL)
{
double profitPips = (OrderOpenPrice() - Ask) / Point;
if(profitPips > TrailingStart)
{
double newStopLoss = Ask + TrailingStep * Point;
if(newStopLoss < OrderStopLoss() || OrderStopLoss() == 0)
OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, OrderTakeProfit(), 0, clrBlue);
}
}
}
}
}
//+------------------------------------------------------------------+
```
Line-by-Line Interpretation
#### 1. Property Declarations (Lines 4-8)
```cpp
#property copyright "AutoCompile AI"
#property strict
#property show_inputs
```
#### 2. Input Parameters (Lines 10-12)
```cpp
input int TrailingStart = 15;
input int TrailingStep = 10;
input int Slippage = 30;
```
#### 3. OnStart() Function (Line 16)
```cpp
void OnStart()
```
#### 4. Order Loop (Lines 17-18)
```cpp
for(int i = OrdersTotal() - 1; i >= 0; i--)
```
#### 5. OrderSelect() (Line 19)
```cpp
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
```
#### 6. Symbol Filter (Line 21)
```cpp
if(OrderSymbol() != Symbol()) continue;
```
#### 7. Buy Order Logic (Lines 23-32)
```cpp
double profitPips = (Bid - OrderOpenPrice()) / Point;
```
```cpp
if(profitPips > TrailingStart)
```
```cpp
double newStopLoss = Bid - TrailingStep * Point;
```
```cpp
if(newStopLoss > OrderStopLoss())
```
```cpp
OrderModify(OrderTicket(), OrderOpenPrice(), newStopLoss, OrderTakeProfit(), 0, clrBlue);
```
#### 8. Sell Order Logic (Lines 33-42)
```cpp
double profitPips = (OrderOpenPrice() - Ask) / Point;
```
```cpp
double newStopLoss = Ask + TrailingStep * Point;
```
How to Compile and Modify
1. Save as `Trailing.mq4` in the `Scripts` folder.
2. Open in MetaEditor (F4), press F7 to compile.
3. If successful, drag script to chart – input dialog appears.
4. Modify parameters like TrailingStart from 15 to 20 pips without editing code.
5. To permanently change defaults: edit the `input` line values, then recompile (F7).
Common Modification Examples
| Change Desired | Line to Modify |
|----------------|----------------|
| Change default activation pips | `input int TrailingStart = 25;` |
| Change trail distance | `input int TrailingStep = 15;` |
| Add minimum lot check (advanced) | Add after line 23: `if(OrderLots() < 0.01) continue;` |
| Add alert on modification | Add after OrderModify: `Alert(“Trailing adjusted”);` |
This MQL4 tutorial shows that reading source code interpretation is the fastest way to learn EA programming entry. After mastering scripts, move to EAs with `OnTick()` and timer functions. Subscribe for weekly compile and modify guides on advanced EA tools.
Reference: AutoCompile AI - Original code interpretation tutorial, 2025.