Expert_AMS_ES_CCI
Download scriptThis automated trading system, titled Expert_AMS_ES_CCI, is designed to manage and execute trades on the financial markets by combining specific technical indicators with predefined risk management rules. Instead of manual trading, this script follows a systematic logic to identify entry points, exit points, and trade volumes based on the data it processes in real-time.
Core Trading Logic
The system operates by evaluating market conditions through a specialized filtering mechanism. Specifically, it utilizes a combination of two primary technical components:
- CCI (Commodity Channel Index): This helps the system measure the price's relationship to its average, identifying whether an asset is overbought or oversold.
- Moving Average (MA): By incorporating a moving average, the script smooths out price fluctuations to identify broader trends.
The logic weights these factors together to generate a "signal." The software is programmed to act only when certain numerical thresholds are met:
- Entry Logic: A trade is triggered when the calculated signal strength reaches or exceeds a specific "Open" threshold.
- Exit Logic: The system monitors the signal continuously and will initiate a closing action if the value drops below a designated "Close" threshold.
Trade Management and Execution
Beyond simply identifying opportunities, the script handles the logistics of the trade:
- Price & Expiration: Users can define specific price levels for execution and set an expiration limit on pending orders (measured in bars), ensuring that old signals do not become obsolete.
- Safety Boundaries: The system allows for the definition of "Stop Loss" and "Take Profit" levels, which act as automatic safety nets to protect capital or secure gains.
Risk and Money Management
The script includes a dedicated module for "Money Management." This ensures that every trade is executed with a consistent approach to risk:
- Fixed Lot Sizing: You can define a specific volume (Lot size) for each trade.
- Percentage Allocation: The system can manage how much of the total account balance is utilized, allowing for a more disciplined approach to capital preservation.
Operational Behavior
The system is built to be "event-driven." It listens for every price change (tick), trade update, or timer event in the market. Whenever new data arrives, it re-runs its internal logic to see if the current market conditions align with your chosen thresholds, ensuring that the strategy is constantly active and responsive to live movements.
//+------------------------------------------------------------------+
//| Expert_AMS_ES_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\ACMS_ES_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_AMS_ES_CCI"; // Document name
ulong Expert_MagicNumber =7663; //
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 =25; // CMS_ES_CCI(25,5) Period of CCI
input int Signal__PeriodMA =5; // CMS_ES_CCI(25,5) Period of MA
input double Signal__Weight =1.0; // CMS_ES_CCI(25,5) 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 CMS_ES_CCI
CMS_ES_CCI *filter0=new CMS_ES_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(0);
}
//+------------------------------------------------------------------+
//| 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