lag_exp_1b1

Author: Ron Thompson
Profit factor:
1.01

This script is designed to automatically trade on the Forex market using the MetaTrader platform. Here's a breakdown of its logic:

Overall Strategy:

The script's core strategy relies on a combination of a Moving Average (MA) and a Laguerre filter to identify potential buying and selling opportunities. It aims to detect when the price is trending upwards or downwards and then executes trades accordingly. Optionally, it can also build a "pyramid" of trades, adding more positions in the same direction as the trend continues.

Key Components:

  1. User Settings: The script starts with several settings that you, as the user, can adjust. These include:

    • Lots: The size of each trade.
    • MovingAvg: The period of the moving average, determining how much historical data it uses.
    • filter: A sensitivity threshold, affecting how reactive the filter is to price changes.
    • Pyramid: If enabled, this allows the script to open additional trades as the trend continues.
    • gamma: A smoothing factor for the Laguerre filter.
  2. Initialization: When the script starts, it performs some checks to ensure it's safe to trade:

    • It verifies if there's enough money in your account to place trades.
    • It checks if enough price data is available.
    • It confirms that the price is actually moving (to avoid acting on stagnant data).
  3. Moving Average Calculation: The script calculates a moving average (MA) of the opening price of the currency pair. The moving average smooths out the price data over a certain period, helping to identify the overall trend.

  4. Laguerre Filter Calculation: The Laguerre filter is applied to further smooth the price action and help identify trend reversals. It uses a specific mathematical formula to generate a value that oscillates between 0 and 1, acting as a signal for potential buy and sell zones.

  5. Trend Detection: The script analyzes the Laguerre filter to determine if the price is trending upwards or downwards. It compares the current filter value to the previous value.

  6. Order Management:

    • Initial Trade:
      • If the script detects an upward trend and no trades are currently open, it places a buy order.
      • If the script detects a downward trend and no trades are currently open, it places a sell order.
    • Closing Trades:
      • If the script detects a trend reversal (e.g., it was previously buying, but now sees a downward trend), it closes all existing trades for that currency pair.
    • Pyramiding (Optional):
      • If the Pyramid setting is enabled, the script will add additional trades in the direction of the trend. It waits for the trend to persist for a certain number of bars before opening another trade.

In Simple Terms:

Imagine the script is a sophisticated weather forecaster for the Forex market. It uses a moving average as a general trend indicator and the Laguerre filter to fine-tune its predictions. If the "weather" suggests an upward trend, it buys; if it forecasts a downward trend, it sells. It also has a feature that lets it double down on its bets if the weather continues to confirm its initial forecast. The script is also programmed to cut its losses and reverse direction when the weather changes unexpectedly.

Important Note:

This script is designed to automate trading, but it's important to remember that Forex trading involves risk. The script's logic is based on specific indicators and may not be suitable for all market conditions. You should carefully consider your risk tolerance and understand the script's behavior before using it with real money.

Price Data Components
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Moving average indicator
7 Views
0 Downloads
0 Favorites
lag_exp_1b1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| 1MA Expert                               |
//+------------------------------------------------------------------+

// 1b1  -  lagurre cross 50

#property copyright "Ron Thompson"
#property link      "http://www.lightpatch.com/forex"

// User Input
extern double Lots = 0.1;
extern double MovingAvg = 10;
extern double filter = 5.1;
extern double Pyramid = 0;

       double barmove0 = 0;
       double barmove1 = 0;
         int  risingcnt = 0;
         int fallingcnt = 0;

extern double gamma=0.5;

double L0 = 0;
double L1 = 0;
double L2 = 0;
double L3 = 0;
double L0A = 0;
double L1A = 0;
double L2A = 0;
double L3A = 0;
double LRSI = 0;
double CU = 0;
double CD = 0;

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

int init()
  {
   return(0);
  }


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


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

int start()
  {
   double   cMA=0, pMA=0;
   double  lowpass0=0, lowpass1=0;
   double   p=Point();
      
   bool     found=false;
   bool    rising=false;
   bool   falling=false;
   bool    bought=false;
   bool      sold=false;

   int      cnt=0;
/*     
   // Symbols that I've optimized
   if (ALLOWChanges!=0)
     {
      if (Symbol()=="AUDUSD") {MovingAvg=10; filter= 8.2;}
      if (Symbol()=="EURAUD") {MovingAvg= 6; filter= 8.0;}
      if (Symbol()=="EURCHF") {MovingAvg= 7; filter= 3.6;}
      if (Symbol()=="EURGBP") {MovingAvg=10; filter= 0.5;}
      if (Symbol()=="EURJPY") {MovingAvg= 2; filter= 9.9;}
      if (Symbol()=="EURUSD") {MovingAvg= 1; filter= 0.9;}
      if (Symbol()=="GBPCHF") {MovingAvg= 4; filter=12.0;}
      if (Symbol()=="GBPJPY") {MovingAvg=10; filter= 9.3;}
      if (Symbol()=="GBPUSD") {MovingAvg= 1; filter= 3.9;}
      if (Symbol()=="USDCAD") {MovingAvg= 1; filter= 0.9;}
      if (Symbol()=="USDCHF") {MovingAvg= 1; filter= 4.0;}
      if (Symbol()=="USDJPY") {MovingAvg=21; filter=11.6;}
     }
*/   

   // Error checking
   if(AccountFreeMargin()<(1000*Lots))        {Print("We have no money");   return(0);}
   if(Bars<100)                               {Print("Bars less than 100"); return(0);}
   if(barmove0==Open[0] && barmove1==Open[1]) {Print("Bar has not moved");  return(0);}

   barmove0=Open[0];
   barmove1=Open[1];

   cMA=iMA(Symbol(), 0, MovingAvg, 0, MODE_LWMA, PRICE_OPEN, 0);
   pMA=iMA(Symbol(), 0, MovingAvg, 0, MODE_LWMA, PRICE_OPEN, 1);
   lowpass0=lagurre(0);
   lowpass1=lagurre(1);


   // rising and falling is filter-qualified by some number of points
   // and each rise/fall is counted for pyramiding decision later
   if (lowpass1<0.5 && lowpass0>0.5) {rising=true;  falling=false; risingcnt++;}
   if (lowpass1>0.5 && lowpass0<0.5) {rising=false; falling=true; fallingcnt++;}

   for(cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderComment()=="LAGURRE01INITTRANS")
        {
         found=true;
         if (OrderType()==0) {bought=true;  sold=false;}
         if (OrderType()==1) {bought=false; sold=true;}
         break;
        }
         else
        {
         found=false;
        }        
     }
   

   // there is no order and MA is rising, BUY something
   // and reset the pyramid counters
   // comment here is very important in identifying initial transaction
   // of the many that may be involved in the pyramid
   if (!found && rising)
     {
      OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"LAGURRE01INITTRANS",11123,0,White);
      if (Pyramid>0) {fallingcnt=0; risingcnt=0;}
      return(0);
     }


   // there is no order and MA is falling, SELL something
   // and reset the pyramid counters
   // comment here is very important in identifying initial transaction
   // of the many that may be involved in the pyramid
   if (!found && falling)
     {
      OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"LAGURRE01INITTRANS",11321,0,Red);
      if (Pyramid>0) {fallingcnt=0; risingcnt=0;}
      return(0);
     }

   // existing SELL and the direction changed
   // loop to close all pyramid orders 
   if (rising && sold)
     {
      for(cnt=0;cnt<OrdersTotal();cnt++)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol()==Symbol())
           {
            OrderClose(OrderTicket(),Lots,Ask,2,Red);
            Sleep(10000);
           }        
        }
      if (Pyramid>0) {fallingcnt=0; risingcnt=0;}
     }


   // existing BUY and the direction changed
   // loop to close all pyramid orders 
   if (falling && bought)
     {
      for(cnt=0;cnt<OrdersTotal();cnt++)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol()==Symbol())
           {
            OrderClose(OrderTicket(),Lots,Bid,2,White);
            Sleep(10000);
           }        
        }
      if (Pyramid>0) {fallingcnt=0; risingcnt=0;}
     }


   if (Pyramid>0)
     {
      // BUY ASK another lot?
      //if (rising && bought && risingcnt>=Pyramid && OrderOpenPrice()<Open[0])
      if (rising && bought && risingcnt>=Pyramid)
        {
         OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"LAGURRE01 Pyramid Buy",22123,0,White);
         if (Pyramid>0) {fallingcnt=0; risingcnt=0;}
         return(0);
        }

      // SELL BID another lot?
      //if (falling && sold && fallingcnt>=Pyramid && OrderOpenPrice()>Open[0])
      if (falling && sold && fallingcnt>=Pyramid)
        {
         OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"LAGURRE01 Pyramid Sell",22321,0,Red);
         if (Pyramid>0) {fallingcnt=0; risingcnt=0;}
         return(0);
        }
     }

   return(0);
  }



double lagurre (int i)
  {
   L0A = L0;
   L1A = L1;
   L2A = L2;
   L3A = L3;
   L0 = (1 - gamma)*Open[i] + gamma*L0A;
   L1 = - gamma *L0 + L0A + gamma *L1A;
   L2 = - gamma *L1 + L1A + gamma *L2A;
   L3 = - gamma *L2 + L2A + gamma *L3A;

   CU = 0;
   CD = 0;
    
   if (L0 >= L1) CU = L0 - L1; else CD = L1 - L0;
   if (L1 >= L2) CU = CU + L1 - L2; else CD = CD + L2 - L1;
   if (L2 >= L3) CU = CU + L2 - L3; else CD = CD + L3 - L2;

   if (CU + CD != 0) LRSI = CU / (CU + CD);
   return(LRSI);
  }




Profitability Reports

GBP/AUD Jul 2025 - Sep 2025
0.77
Total Trades 52
Won Trades 21
Lost trades 31
Win Rate 40.38 %
Expected payoff -3.07
Gross Profit 524.17
Gross Loss -683.76
Total Net Profit -159.59
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
1.28
Total Trades 45
Won Trades 18
Lost trades 27
Win Rate 40.00 %
Expected payoff 3.95
Gross Profit 803.60
Gross Loss -626.00
Total Net Profit 177.60
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.80
Total Trades 48
Won Trades 23
Lost trades 25
Win Rate 47.92 %
Expected payoff 4.30
Gross Profit 465.40
Gross Loss -259.10
Total Net Profit 206.30
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
1.13
Total Trades 98
Won Trades 39
Lost trades 59
Win Rate 39.80 %
Expected payoff 1.95
Gross Profit 1701.36
Gross Loss -1510.51
Total Net Profit 190.85
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
1.11
Total Trades 116
Won Trades 28
Lost trades 88
Win Rate 24.14 %
Expected payoff 1.90
Gross Profit 2202.92
Gross Loss -1982.51
Total Net Profit 220.41
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.98
Total Trades 101
Won Trades 40
Lost trades 61
Win Rate 39.60 %
Expected payoff -0.31
Gross Profit 1376.29
Gross Loss -1407.23
Total Net Profit -30.94
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.91
Total Trades 101
Won Trades 31
Lost trades 70
Win Rate 30.69 %
Expected payoff -1.25
Gross Profit 1247.20
Gross Loss -1373.30
Total Net Profit -126.10
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.75
Total Trades 113
Won Trades 40
Lost trades 73
Win Rate 35.40 %
Expected payoff -6.42
Gross Profit 2162.80
Gross Loss -2888.60
Total Net Profit -725.80
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.56
Total Trades 121
Won Trades 34
Lost trades 87
Win Rate 28.10 %
Expected payoff -8.87
Gross Profit 1380.31
Gross Loss -2454.18
Total Net Profit -1073.87
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.60
Total Trades 122
Won Trades 50
Lost trades 72
Win Rate 40.98 %
Expected payoff -9.95
Gross Profit 1840.32
Gross Loss -3054.34
Total Net Profit -1214.02
-100%
-50%
0%
50%
100%

Comments