Author: Ron Thompson
Profit factor:
0.55

Here's a breakdown of the MQL4 script's logic in plain language, designed for someone who doesn't code.

Overall Goal:

This script is designed to automatically trade in the Forex market based on signals from a technical indicator called the Commodity Channel Index (CCI). It aims to open and close trades hoping to profit from price movements.

Core Concepts

  • Technical Indicator (CCI): Think of this as a mathematical formula applied to price data to generate buy or sell signals. In this case the script use this to help determine possible trend changes in the market.
  • Buy/Sell Orders: These are instructions to your broker to either buy (expecting the price to go up) or sell (expecting the price to go down) a currency pair.
  • Take Profit/Stop Loss: These are safety nets. Take Profit automatically closes a trade when it reaches a certain profit level. Stop Loss automatically closes a trade to limit potential losses.
  • Lot Size: The size of your trade. It represents the amount of currency you are buying or selling.

How the Script Works

  1. Setup (Initialization):

    • When the script starts, it sets up some initial values based on the user-defined settings (input parameters). The interval setting is stored for later use.
  2. Main Trading Logic (The start() Function):

    • Checking Conditions: Before doing anything, the script checks a few things:

      • Account Balance: Does your account have enough money to place a trade with the specified "Lots" size?
      • Data Availability: Has enough price data been loaded for the script to work?
      • Market Movement: Has the price actually changed since the last time the script ran? If not, there is no need to do anything.
    • Calculating Stop Loss and Take Profit:

      • The script figures out where to place the stop loss and take profit orders, based on the user defined pip parameter relative to the current price.
    • Analyzing the CCI Indicator:

      • The script looks at the CCI indicator at the current and previous price bars.
    • Identifying Crossover Signals:

      • The script specifically watches for the CCI to "cross" the zero line.
      • Rising Cross: If the CCI was below zero in the previous bar but is now above zero, this is considered a bullish (buy) signal.
      • Falling Cross: If the CCI was above zero in the previous bar but is now below zero, this is considered a bearish (sell) signal.
    • Opening and Closing Trades:

      • If a Crossover Occurs:
        • The script closes all existing trades for the currency pair.
        • Then, it opens a new trade based on the direction of the crossover: If rising, it opens a buy order. If falling, it opens a sell order. It sets the Stop Loss and Take Profit levels for the new trade.
      • Pyramiding: *The program tries to open more orders in the same direction
        • If there is an order already opened in the current symbol it keeps counting how many bars have passed to open new orders.
        • If the number of bars that have passed reach the configured Interval it will create a new order in the same direction with the same stop loss and take profit.
        • After opening the pyramiding order, the number of bars that have passed is set back to zero to wait until the next Interval is reached.
        • If it open an order, the Stop Loss and Take Profit settings are set.
  3. Looping:

    • The start() function runs repeatedly as new price data becomes available, constantly monitoring the market and adjusting positions.
Price Data Components
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Commodity channel index
10 Views
0 Downloads
0 Favorites
zzz004
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| 1MA Expert                               |
//+------------------------------------------------------------------+
#property copyright "Ron Thompson"
#property link      "http://www.lightpatch.com/forex"

// User Input
extern double Lots = 0.1;
extern int    TakeProfit=90;
extern int    StopLoss=0;
extern int    Interval=5;


// Global scope
double barmove0 = 0;
double barmove1 = 0;
int         itv = 0;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|

int init()
  {
   itv=Interval;
   return(0);
  }


//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {

   bool      found=false;
   bool     rising=false;
   bool    falling=false;
   bool      cross=false;

   double slA=0, slB=0, tpA=0, tpB=0;
   double p=Point();
   
   double cCI0;
   double cCI1;
   
   int      cnt=0;

   // Error checking
   if(AccountFreeMargin()<(1000*Lots))        {Print("-----NO MONEY"); return(0);}
   if(Bars<100)                               {Print("-----NO BARS "); return(0);}
   if(barmove0==Open[0] && barmove1==Open[1]) {                        return(0);}

   // bars moved, update current position
   barmove0=Open[0];
   barmove1=Open[1];

   // interval (bar) counter
   // used to pyramid orders during trend
   itv++;
   
   // since the bar just moved
   // calculate TP and SL for (B)id and (A)sk
   tpA=Ask+(p*TakeProfit);
   slA=Ask-(p*StopLoss);
   tpB=Bid-(p*TakeProfit);
   slB=Bid+(p*StopLoss);
   if (TakeProfit==0) {tpA=0; tpB=0;}           
   if (StopLoss==0)   {slA=0; slB=0;}           
   
   // get CCI based on OPEN
   cCI0=iCCI(Symbol(),0,30,PRICE_OPEN,0);
   cCI1=iCCI(Symbol(),0,30,PRICE_OPEN,1);

   // is it crossing zero up or down
   if (cCI1<0 && cCI0>0) { rising=true; cross=true; Print("Rising  Cross");}
   if (cCI1>0 && cCI0<0) {falling=true; cross=true; Print("Falling Cross");}
   
   // close then open orders based on cross
   // pyramid below based on itv
   if (cross)
     {
      // Close ALL the open orders 
      for(cnt=0;cnt<OrdersTotal();cnt++)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol()==Symbol())
           {
            if (OrderType()==0) {OrderClose(OrderTicket(),Lots,Bid,3,White);}
            if (OrderType()==1) {OrderClose(OrderTicket(),Lots,Ask,3,Red);}
            itv=0;
           }
        }
      // Open new order based on direction of cross
      if (rising)  OrderSend(Symbol(),OP_BUY,Lots,Ask,3,slA,tpA,"ZZZ100",11123,0,White);
      if (falling) OrderSend(Symbol(),OP_SELL,Lots,Bid,3,slB,tpB,"ZZZ100",11321,0,Red);
      
      // clear the interval counter
      itv=0;
     }
   
   // Only pyramid if order already open
   found=false;
   for(cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol())
        {
         found=true;
         break;
        }
     }


   // Pyramid
   // add an order every
   if (found && itv>=Interval)
     {
      OrderSend(Symbol(),OP_BUY,Lots,Ask,3,slA,tpA,"ZZZ100",11123,0,White);
      itv=0;
     }

   if (found && itv>=Interval)
     {
      OrderSend(Symbol(),OP_SELL,Lots,Bid,3,slB,tpB,"ZZZ100",11321,0,Red);
      itv=0;
     }
   
   
   return(0);
  }

Profitability Reports

USD/CAD Oct 2024 - Jan 2025
1.08
Total Trades 150
Won Trades 90
Lost trades 60
Win Rate 60.00 %
Expected payoff 0.29
Gross Profit 574.70
Gross Loss -530.61
Total Net Profit 44.09
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
1.05
Total Trades 347
Won Trades 197
Lost trades 150
Win Rate 56.77 %
Expected payoff 0.25
Gross Profit 1724.70
Gross Loss -1637.00
Total Net Profit 87.70
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.93
Total Trades 278
Won Trades 198
Lost trades 80
Win Rate 71.22 %
Expected payoff -0.32
Gross Profit 1199.88
Gross Loss -1288.86
Total Net Profit -88.98
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.82
Total Trades 182
Won Trades 108
Lost trades 74
Win Rate 59.34 %
Expected payoff -0.86
Gross Profit 698.06
Gross Loss -855.00
Total Net Profit -156.94
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.74
Total Trades 369
Won Trades 193
Lost trades 176
Win Rate 52.30 %
Expected payoff -1.64
Gross Profit 1685.60
Gross Loss -2289.40
Total Net Profit -603.80
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.73
Total Trades 195
Won Trades 102
Lost trades 93
Win Rate 52.31 %
Expected payoff -1.65
Gross Profit 879.50
Gross Loss -1201.10
Total Net Profit -321.60
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.71
Total Trades 296
Won Trades 161
Lost trades 135
Win Rate 54.39 %
Expected payoff -1.31
Gross Profit 940.54
Gross Loss -1329.15
Total Net Profit -388.61
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.67
Total Trades 544
Won Trades 241
Lost trades 303
Win Rate 44.30 %
Expected payoff -1.67
Gross Profit 1851.10
Gross Loss -2758.10
Total Net Profit -907.00
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.66
Total Trades 366
Won Trades 201
Lost trades 165
Win Rate 54.92 %
Expected payoff -2.90
Gross Profit 2047.98
Gross Loss -3108.06
Total Net Profit -1060.08
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.66
Total Trades 530
Won Trades 269
Lost trades 261
Win Rate 50.75 %
Expected payoff -2.01
Gross Profit 2042.90
Gross Loss -3110.80
Total Net Profit -1067.90
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.65
Total Trades 195
Won Trades 106
Lost trades 89
Win Rate 54.36 %
Expected payoff -3.12
Gross Profit 1143.55
Gross Loss -1751.26
Total Net Profit -607.71
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.62
Total Trades 136
Won Trades 78
Lost trades 58
Win Rate 57.35 %
Expected payoff -3.07
Gross Profit 676.90
Gross Loss -1094.50
Total Net Profit -417.60
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.62
Total Trades 122
Won Trades 72
Lost trades 50
Win Rate 59.02 %
Expected payoff -2.20
Gross Profit 440.04
Gross Loss -708.43
Total Net Profit -268.39
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.61
Total Trades 187
Won Trades 112
Lost trades 75
Win Rate 59.89 %
Expected payoff -3.42
Gross Profit 993.70
Gross Loss -1632.60
Total Net Profit -638.90
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.60
Total Trades 368
Won Trades 211
Lost trades 157
Win Rate 57.34 %
Expected payoff -2.37
Gross Profit 1327.76
Gross Loss -2201.17
Total Net Profit -873.41
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.55
Total Trades 202
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -3.64
Gross Profit 915.60
Gross Loss -1650.70
Total Net Profit -735.10
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.53
Total Trades 341
Won Trades 194
Lost trades 147
Win Rate 56.89 %
Expected payoff -4.51
Gross Profit 1732.90
Gross Loss -3269.90
Total Net Profit -1537.00
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.52
Total Trades 184
Won Trades 92
Lost trades 92
Win Rate 50.00 %
Expected payoff -3.79
Gross Profit 748.40
Gross Loss -1444.90
Total Net Profit -696.50
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.50
Total Trades 453
Won Trades 221
Lost trades 232
Win Rate 48.79 %
Expected payoff -4.27
Gross Profit 1921.10
Gross Loss -3855.20
Total Net Profit -1934.10
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.48
Total Trades 339
Won Trades 192
Lost trades 147
Win Rate 56.64 %
Expected payoff -3.98
Gross Profit 1248.40
Gross Loss -2598.58
Total Net Profit -1350.18
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.45
Total Trades 151
Won Trades 79
Lost trades 72
Win Rate 52.32 %
Expected payoff -4.10
Gross Profit 514.25
Gross Loss -1133.82
Total Net Profit -619.57
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2024 - Jan 2025
0.44
Total Trades 161
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -4.56
Gross Profit 573.13
Gross Loss -1307.67
Total Net Profit -734.54
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.44
Total Trades 318
Won Trades 199
Lost trades 119
Win Rate 62.58 %
Expected payoff -4.72
Gross Profit 1173.40
Gross Loss -2673.78
Total Net Profit -1500.38
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.34
Total Trades 176
Won Trades 99
Lost trades 77
Win Rate 56.25 %
Expected payoff -6.47
Gross Profit 586.41
Gross Loss -1725.01
Total Net Profit -1138.60
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.26
Total Trades 475
Won Trades 214
Lost trades 261
Win Rate 45.05 %
Expected payoff -7.13
Gross Profit 1217.16
Gross Loss -4603.30
Total Net Profit -3386.14
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.18
Total Trades 622
Won Trades 228
Lost trades 394
Win Rate 36.66 %
Expected payoff -10.02
Gross Profit 1378.71
Gross Loss -7610.87
Total Net Profit -6232.16
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.00
Total Trades 99
Won Trades 55
Lost trades 44
Win Rate 55.56 %
Expected payoff -981.35
Gross Profit 488.00
Gross Loss -97641.50
Total Net Profit -97153.50
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 21
Won Trades 10
Lost trades 11
Win Rate 47.62 %
Expected payoff -5024.03
Gross Profit 90.00
Gross Loss -105594.60
Total Net Profit -105504.60
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 38
Won Trades 20
Lost trades 18
Win Rate 52.63 %
Expected payoff -2772.03
Gross Profit 168.20
Gross Loss -105505.20
Total Net Profit -105337.00
-100%
-50%
0%
50%
100%

Comments