expert_abc_ws_cci_v1

Download script
Author: Copyright 2011, MetaQuotes Software Corp.

This automated trading system is designed to manage market entries and exits by analyzing specific price movements and technical indicators. Below is a professional breakdown of the logic used by this script:

Core Trading Logic

The script operates as an "Expert Advisor," meaning it automatically monitors the market to execute trades based on predefined rules. It focuses on three primary pillars: signal generation, filtering, and risk management.

Signal Generation and Execution

The system relies on a specific set of triggers to determine when to enter or exit a position.

  • Entry Thresholds: The script looks for price movements that meet a specific "Open" threshold (set by the user). If the market behavior crosses this designated intensity, the system prepares to enter a trade.
  • Exit Thresholds: Conversely, it monitors a "Close" threshold. When conditions fall below this level, the system identifies an opportunity to exit the position.
  • Order Management: The script includes parameters for specific price levels, as well as defined Stop Loss and Take Profit points. It also features an expiration mechanism that automatically removes pending orders if they are not filled within a certain number of bars (timeframes).

Advanced Filtering (CBC_WS_CCI)

To increase accuracy and reduce "false starts," the script applies a sophisticated technical filter known as the CBC_WS_CCI. This filter uses three distinct components to validate a trade:

  1. CCI Period: A calculation based on a 37-period cycle to identify momentum.
  2. Moving Average (MA): A smoothing calculation over a 13-period window to help determine the general trend of the price.
  3. Weighting: A customizable balance that determines how much importance the script should give to these indicators versus raw price action.

By combining these filters, the system ensures that it only enters a trade when both the momentum (CCI) and the trend (MA) align with the desired direction.

Money Management and Risk Control

The script includes a structured approach to capital preservation:

  • Fixed Volume Positioning: It manages trades using a fixed lot size, ensuring that every position remains consistent in size regardless of market volatility.
  • Percentage Allocation: It allows the user to define what percentage of the account equity should be considered for these trades, helping to maintain a balanced risk profile.
  • Trailing Logic: The script is configured with a "None" trailing system, meaning it will strictly adhere to the initial Take Profit and Stop Loss levels provided by the user rather than moving them dynamically as the price fluctuates.

Operational Flow

When the script is activated, it performs an automated setup check to ensure all indicators and money management rules are valid. Once verified, it runs continuously, scanning every price tick for opportunities that meet the combined requirements of the CCI filter, the entry thresholds, and the risk management parameters.

5 Views
0 Downloads
0 Favorites
expert_abc_ws_cci_v1
//+------------------------------------------------------------------+
//|                                            Expert_ABC_WS_CCI.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
//--- available signals
#include <Expert\Signal\MySignals\ACBC_WS_CCI.mqh>
//--- available trailing
#include <Expert\Trailing\TrailingNone.mqh>
//--- available money management
#include <Expert\Money\MoneyFixedLot.mqh>
//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
//--- inputs for expert
input string Expert_Title         ="Expert_ABC_WS_CCI"; // Document name
ulong        Expert_MagicNumber   =22954;               // 
bool         Expert_EveryTick     =false;               // 
//--- inputs for main signal
input int    Signal_ThresholdOpen =40;                  // Signal threshold value to open [0...100]
input int    Signal_ThresholdClose=20;                  // Signal threshold value to close [0...100]
input double Signal_PriceLevel    =0.0;                 // Price level to execute a deal
input double Signal_StopLevel     =0.0;                 // Stop Loss level (in points)
input double Signal_TakeLevel     =0.0;                 // Take Profit level (in points)
input int    Signal_Expiration    =4;                   // Expiration of pending orders (in bars)
input int    Signal__PeriodCCI    =37;                  // CBC_WS_CCI(37,13) Period of CCI
input int    Signal__PeriodMA     =13;                  // CBC_WS_CCI(37,13) Period of MA
input double Signal__Weight       =1.0;                 // CBC_WS_CCI(37,13) Weight [0...1.0]
//--- inputs for money
input double Money_FixLot_Percent =10.0;                // Percent
input double Money_FixLot_Lots    =0.1;                 // Fixed volume
//+------------------------------------------------------------------+
//| Global expert object                                             |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing expert");
      ExtExpert.Deinit();
      return(-1);
     }
//--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(-2);
     }
//---
   ExtExpert.InitSignal(signal);
   signal.ThresholdOpen(Signal_ThresholdOpen);
   signal.ThresholdClose(Signal_ThresholdClose);
   signal.PriceLevel(Signal_PriceLevel);
   signal.StopLevel(Signal_StopLevel);
   signal.TakeLevel(Signal_TakeLevel);
   signal.Expiration(Signal_Expiration);
//--- Creating filter CBC_WS_CCI
   CBC_WS_CCI *filter0=new CBC_WS_CCI;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(-3);
     }
   signal.AddFilter(filter0);
//--- Set filter parameters
   filter0.PeriodCCI(Signal__PeriodCCI);
   filter0.PeriodMA(Signal__PeriodMA);
   filter0.Weight(Signal__Weight);
//--- Creation of trailing object
   CTrailingNone *trailing=new CTrailingNone;
   if(trailing==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating trailing");
      ExtExpert.Deinit();
      return(-4);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing trailing");
      ExtExpert.Deinit();
      return(-5);
     }
//--- Set trailing parameters
//--- Creation of money object
   CMoneyFixedLot *money=new CMoneyFixedLot;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(-6);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(-7);
     }
//--- Set money parameters
   money.Percent(Money_FixLot_Percent);
   money.Lots(Money_FixLot_Lots);
//--- Check all trading objects parameters
   if(!ExtExpert.ValidationSettings())
     {
      //--- failed
      ExtExpert.Deinit();
      return(-8);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(-9);
     }
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
   ExtExpert.OnTick();
  }
//+------------------------------------------------------------------+
//| "Trade" event handler function                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
   ExtExpert.OnTrade();
  }
//+------------------------------------------------------------------+
//| "Timer" event handler function                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ExtExpert.OnTimer();
  }
//+------------------------------------------------------------------+

Comments