FT_CCI_0.4(+MA)mq4

Author: FORTRADER.RU, ����, ftyuriy@gmail.com
Profit factor:
0.91

This script is designed to automatically trade on the Metatrader platform, using a combination of technical indicators to identify potential buy or sell opportunities. It's like having a robotic assistant that watches the market and makes trades according to a set of pre-defined rules.

Here's a breakdown of how it works:

  1. Key Ingredients (External Parameters):

    • It uses several external parameters that can be adjusted by the user. These parameters define how the trading robot will behave. Some important ones include the periods of indicators such as CCI and Moving Average. These affect the responsiveness and sensitivity of the system. Thresholds that define the boundaries for buying and selling signals are also used. Stop Loss and Take Profit values for managing risk and reward are also external parameters.
  2. Monitoring the Market:

    • The script continuously checks the current market conditions, specifically the price of the currency pair it's trading on.
  3. Analyzing the Data (Technical Indicators):

    • It uses two technical indicators:
      • CCI (Commodity Channel Index): This indicator helps to identify when an asset is overbought or oversold, potentially signaling a price reversal. Think of it as a measure of how far the current price is deviating from its average.
      • Moving Average: This calculates the average price of an asset over a specific period. It helps to smooth out price fluctuations and identify the overall trend (whether the price is generally going up or down).
  4. Decision Making (Trading Logic):

    • The script's core logic revolves around comparing the current price and the CCI value to the moving average and the threshold levels. It uses these comparisons to determine whether to buy or sell.

    • Buy Signals:

      • The robot looks for specific instances in the market. First, a previous close is greater than a Moving Average. If this happens and the CCI is low, below a threshold, then the script stores this in memory. If after that, CCI then rises above the low threshold, then the robot will buy (if time conditions are met). This aims to buy when the CCI rises again after a low point (after conditions are met). Then, it will immediately close all sell trades.

      • There is another condition for buying. If the close is less than the moving average, and the CCI is below its low threshold, then the robot stores this in memory. Then if the CCI then rises above the low threshold, then the robot will buy (if time conditions are met). This aims to buy when the CCI rises again after a low point (after conditions are met). Then, it will immediately close all sell trades.

    • Sell Signals:

      • The script looks for specific instances in the market. First, a previous close is less than a Moving Average. If this happens and the CCI is high, above a threshold, then the script stores this in memory. If after that, CCI then falls below the high threshold, then the robot will sell (if time conditions are met). This aims to sell when the CCI falls again after a high point (after conditions are met). Then, it will immediately close all buy trades.

      • There is another condition for selling. If the close is greater than the moving average, and the CCI is above its high threshold, then the robot stores this in memory. Then if the CCI then falls below the high threshold, then the robot will sell (if time conditions are met). This aims to sell when the CCI falls again after a high point (after conditions are met). Then, it will immediately close all buy trades.

  5. Order Execution (Trading):

    • When the script identifies a valid buy or sell signal (based on the indicator values crossing specific levels), it automatically sends an order to the trading platform to open a position.
    • It can also set a "stop loss" (to limit potential losses) and a "take profit" (to automatically close the trade when a specific profit target is reached).
  6. Time Restrictions:

    • The script has a feature to only trade during certain hours of the day. This can be useful to avoid trading during periods of low volatility or when specific news events are expected.
  7. Closing Existing Trades:

    • Based on the logic, it will close positions based on Buy/Sell signals.

In essence, this script automates a trading strategy that uses a combination of moving averages and the CCI indicator to identify potential trading opportunities and execute trades automatically. The user can adjust the parameters to fine-tune the strategy to their preferences and risk tolerance.

Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt Closes Orders by itself
Indicators Used
Moving average indicatorCommodity channel index
6 Views
2 Downloads
0 Favorites
FT_CCI_0.4(+MA)mq4
//+------------------------------------------------------------------+
//|                                                       FT_CCI.mq4 |
//|                            FORTRADER.RU, Þðèé, ftyuriy@gmail.com |
//|                          http://FORTRADER.RU, Ôðàêòàëû + Ñðåäíèå |
//+------------------------------------------------------------------+
#property copyright "FORTRADER.RU, Þðèé, ftyuriy@gmail.com"
#property link      "http://FORTRADER.RU, CCI"
/*Ðàçðàáîòàíî äëÿ 50 âûïóñêà æóðíàëà FORTRADER.Ru. Ñèñòåìà ïî CCI. 
Îò÷åòû: http://finfile.ru/index.php/files/get/4LvxA6u0UY/ft-cci-result2.zip
Ñåò ôàéëû:http://finfile.ru/index.php/files/get/Kz2LK5Gnj6/eurusdh1.set 
Îáñóæäåíèå: http://fxnow.ru/group_discussion_view.php?group_id=49&grouptopic_id=409&grouppost_id=3439#post_3439
Àðõèâ æóðíàëà: http://www.fortrader.ru/arhiv.php
50 âûïóñê: http://www.fortrader.ru/

v0.3 - ìîäèôèêàöèÿ äëÿ îäèíàêîâûõ òåñòîâ ïî êîíòðîëüíûì òî÷êàì/öåíàì îòêðûòèÿ/ïî òèêàì
*/


extern int cciper=14;
extern int ccUPur=200;
extern int ccDWur=-200;

extern int maper=200;
extern int tByuUr=-100;
extern int tsellUr=100;

extern int SL=0;
extern int TP=0;

extern int mn=1;
int err;

extern int MG=564651;
extern double Lots=0.1;

int bars;
int start()
  {
  if(Bars!=bars && Bars>400)
  {bars=Bars;
  OpenPattern();//îòêðûâàåì ñäåëêè ïðè ìåðåñå÷åíèè
  }
   return(0);
  }
  
int okbuy,oksell,okbuy1,oksell1;

void OpenPattern()
{
 double op,sl,tp;
 double ma=iMA(NULL,0,maper,0,MODE_SMA,PRICE_CLOSE,1);
 double CCICurr=iCCI(Symbol(),0,cciper,PRICE_TYPICAL,1);
 
 if(Close[1]>ma)
   if(CCICurr<tByuUr) {okbuy1=1;}
   if(CCICurr>tByuUr && okbuy1==1 ) {okbuy1=0;
      if(timecontrol()==1)
      {
      op=Ask;if(SL>0){sl=Ask-SL*Point*mn;}if(TP>0){tp=Ask+TP*Point*mn;}
      err=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(op,Digits),3,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),"6 FORTRADER.RU",MG,0,Red);
      if(err<0){Print("OrderSend()-  Îøèáêà OP_BUY.  op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);}
      }
  CloseAllPos(0);
   }
   
    if(Close[1]<ma)
   if(CCICurr<ccDWur) {okbuy=1;}
   if(CCICurr>ccDWur && okbuy==1 ) {okbuy=0;
      if(timecontrol()==1)
      {
      op=Ask;if(SL>0){sl=Ask-SL*Point*mn;}if(TP>0){tp=Ask+TP*Point*mn;}
      err=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(op,Digits),3,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),"6 FORTRADER.RU",MG,0,Red);
      if(err<0){Print("OrderSend()-  Îøèáêà OP_BUY.  op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);}
      }
  CloseAllPos(0);
   }
   
 if(Close[1]<ma)
 {
   if(CCICurr>tsellUr) {oksell1=1;}
   if(CCICurr<tsellUr && oksell1==1) {oksell1=0;
      if(timecontrol()==1)
      {
      op=Bid;if(SL>0){sl=Bid+SL*Point*mn;}if(TP>0){tp=Bid-TP*Point*mn;}
      err=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(op,Digits),3,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),"4 FORTRADER.RU",MG,0,Red);
      if(err<0){Print("OrderSend()-  Îøèáêà OP_SELL.  op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);}
      }
  CloseAllPos(1);
  }
 }
 
  if(Close[1]>ma)
 {
   if(CCICurr>ccUPur) {oksell=1;}
   if(CCICurr<ccUPur && oksell==1) {oksell=0;
      if(timecontrol()==1)
      {
      op=Bid;if(SL>0){sl=Bid+SL*Point*mn;}if(TP>0){tp=Bid-TP*Point*mn;}
      err=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(op,Digits),3,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),"4 FORTRADER.RU",MG,0,Red);
      if(err<0){Print("OrderSend()-  Îøèáêà OP_SELL.  op "+op+" sl "+sl+" tp "+tp+" "+GetLastError());return(-1);}
      }
  CloseAllPos(1);
  }
 }
}



//Çàêðûâàåì âñå ïîçèöèè ïî òèïó
int CloseAllPos(int type)
{//Îïèñàíèå ôóíêöèè: http://fxnow.ru/blog.php?user=Yuriy&blogentry_id=72
int buy=1; int sell=1;
int i,b=0;int ordertiket;
 
 if(type==1)
   {
   while(buy==1)
     {
        buy=0;
        for( i=0;i<OrdersTotal();i++)
         {
           if(true==OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
           {
           if(OrderType()==OP_BUY && OrderSymbol()==Symbol() ){buy=1; OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);}
           }else{buy=0;}
         }  
         if(buy==0){return(0);}
      } 
   }
   
   if(type==0 )
   {
      while(sell==1)
     {
        sell=0;
        for( i=0;i<OrdersTotal();i++)
         {
           if(true==OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
           {
           if(OrderType()==OP_SELL && OrderSymbol()==Symbol() ){sell=1;OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); }
           }else{sell=0;}
         }  
         
        if(sell==0){return(0);}
      } 
     }
   return(0);
   }

 //ïðîâåðÿåò åñòü ëè îòêðûòûå îðäåðà
int ChPos(int type) 
{//ïîäðîáíîå îïèñàíèå: http://fxnow.ru/blog.php?user=Yuriy&blogentry_id=100

   int i;int col;
   for( i=1; i<=OrdersTotal(); i++)         
   {
      if(OrderSelect(i-1,SELECT_BY_POS)==true) 
       {                                   
           if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && type==1&& OrderMagicNumber()==MG){col=1;}
           if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && type==0&& OrderMagicNumber()==MG){col=1;}
       }
    }   
return(col);
}

 //ñóììèðóåò ðåçóëüòàò ïîçèöèé ïî òèïó
int SummPos(int type) 
{//ïîäðîáíîå îïèñàíèå: http://fxnow.ru/blog.php?user=Yuriy&blogentry_id=100

   int i;double summ;
   for( i=1; i<=OrdersTotal(); i++)         
   {
      if(OrderSelect(i-1,SELECT_BY_POS)==true) 
       {                                   
           if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && type==1&& OrderMagicNumber()==MG){summ=summ+OrderProfit();}
           if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && type==0&& OrderMagicNumber()==MG){summ=summ+OrderProfit();}
       }
    }   
return(summ);
}

extern int time=0; //1 - âêëþ÷åíî, 0 - âûêëþ÷åíî.
extern int starttime = 7; 
extern int stoptime = 17; 

//Îãðàíè÷åíèå ïî âðåìåíè
int timecontrol()
{// Ïîäðîáíîå îïèñàíèå http://fxnow.ru/blog.php?user=Yuriy&blogentry_id=1
   if ( ( (Hour()>=0 && Hour()<=stoptime-1) ||  (Hour()>=starttime && Hour()<=23)) && starttime>stoptime)
      {
      return(1);
      }  
      if ( (Hour()>=starttime && Hour()<=stoptime-1) && starttime<stoptime)
      {
      return(1);
      }  
      
   if(time==0){ return(1);}
     
return(0);
}

Profitability Reports

GBP/AUD Jul 2025 - Sep 2025
1.10
Total Trades 96
Won Trades 46
Lost trades 50
Win Rate 47.92 %
Expected payoff 2.01
Gross Profit 2212.79
Gross Loss -2019.66
Total Net Profit 193.13
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 10
Won Trades 6
Lost trades 4
Win Rate 60.00 %
Expected payoff -10556.09
Gross Profit 124.00
Gross Loss -105684.90
Total Net Profit -105560.90
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.52
Total Trades 108
Won Trades 47
Lost trades 61
Win Rate 43.52 %
Expected payoff -10.69
Gross Profit 1240.50
Gross Loss -2395.10
Total Net Profit -1154.60
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
1.17
Total Trades 201
Won Trades 121
Lost trades 80
Win Rate 60.20 %
Expected payoff 4.45
Gross Profit 6236.47
Gross Loss -5342.59
Total Net Profit 893.88
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.74
Total Trades 202
Won Trades 97
Lost trades 105
Win Rate 48.02 %
Expected payoff -8.70
Gross Profit 4964.50
Gross Loss -6721.12
Total Net Profit -1756.62
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.86
Total Trades 239
Won Trades 137
Lost trades 102
Win Rate 57.32 %
Expected payoff -2.30
Gross Profit 3379.24
Gross Loss -3927.87
Total Net Profit -548.63
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.96
Total Trades 213
Won Trades 124
Lost trades 89
Win Rate 58.22 %
Expected payoff -0.70
Gross Profit 3634.30
Gross Loss -3782.70
Total Net Profit -148.40
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.64
Total Trades 220
Won Trades 127
Lost trades 93
Win Rate 57.73 %
Expected payoff -11.85
Gross Profit 4706.80
Gross Loss -7313.60
Total Net Profit -2606.80
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.68
Total Trades 223
Won Trades 116
Lost trades 107
Win Rate 52.02 %
Expected payoff -8.39
Gross Profit 3919.73
Gross Loss -5789.85
Total Net Profit -1870.12
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.94
Total Trades 226
Won Trades 126
Lost trades 100
Win Rate 55.75 %
Expected payoff -1.39
Gross Profit 5216.19
Gross Loss -5530.77
Total Net Profit -314.58
-100%
-50%
0%
50%
100%

Comments