// define the properties of the CCI EA
int CCIDefinition =iCCI(_Symbol,_Period,14,PRICE_CLOSE);
// sort the price array from the current candle downwards
ArraySetAsSeries(myPriceArray,true);
// Defined MA1, one line,current candle,3 candles, store result
CopyBuffer(CCIDefinition,0,0,3,myPriceArray);
// Get the value of the current candle
float CCIValue=(myPriceArray[0]);
// if it is above the upper line
if (CCIValue> 100)
Comment ("OVERBOUGHT");
// if it is below the lower line
if (CCIValue< -100)
Comment ("OVERSOLD");
// if it is between the lines
if ((CCIValue > -100) &&(CCIValue<100))
Comment ("");
Note: This is a basic implementation of a CCI-based Expert Advisor. You may need to adjust the code to fit your specific needs.
Video Time Stamps
0:00 – Introduction to Commodity Channel Index
0:30 – Overbought and Oversold Conditions
0:50 – Creating an Expert Advisor in MQL5
1:03 – Selecting File > New > Expert Advisor
1:13 – Naming the Expert Advisor
1:20 – Removing Unnecessary Code
1:30 – Creating a Double Array for Prices
1:41 – Defining the Commodity Channel Index
1:56 – Selecting the Current Symbol and Period
2:01 – Calculating for 14 Candles
2:12 – Inserting the Commodity Channel Index Indicator
2:23 – Calculating Based on Close Prices
2:35 – Sorting the Price Array
2:42 – Copying the CCI Buffer
2:46 – Getting the CCI Value for the Current Candle
3:13 – Outputting Overbought or Oversold on the Chart
3:36 – Outputting an Empty Signal for No Signal
3:48 – Compiling the Expert Advisor
4:01 – Bringing Up MetaTrader
4:11 – Selecting View > Strategy Tester
4:23 – Selecting the Simple Commodity Channel Index Expert Advisor
4:30 – Marking the Visualization Option
4:34 – Starting the Expert Advisor
4:41 – Observing the Expert Advisor in Action
4:52 – Using the Commodity Channel Index Indicator for Entry Signals
5:02 – Conclusion



