FT_CCI_0.4(+MA)mq4

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

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
9 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

USD/CAD Oct 2024 - Jan 2025
2.20
Total Trades 96
Won Trades 69
Lost trades 27
Win Rate 71.88 %
Expected payoff 9.30
Gross Profit 1634.21
Gross Loss -741.78
Total Net Profit 892.43
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
2.15
Total Trades 107
Won Trades 74
Lost trades 33
Win Rate 69.16 %
Expected payoff 11.32
Gross Profit 2263.47
Gross Loss -1051.89
Total Net Profit 1211.58
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
1.54
Total Trades 81
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 7.59
Gross Profit 1762.80
Gross Loss -1148.40
Total Net Profit 614.40
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
1.40
Total Trades 85
Won Trades 53
Lost trades 32
Win Rate 62.35 %
Expected payoff 4.16
Gross Profit 1230.00
Gross Loss -876.10
Total Net Profit 353.90
-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%
GBP/USD Jul 2025 - Sep 2025
1.17
Total Trades 197
Won Trades 115
Lost trades 82
Win Rate 58.38 %
Expected payoff 2.94
Gross Profit 3958.30
Gross Loss -3379.60
Total Net Profit 578.70
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
1.16
Total Trades 210
Won Trades 115
Lost trades 95
Win Rate 54.76 %
Expected payoff 2.11
Gross Profit 3156.25
Gross Loss -2714.18
Total Net Profit 442.07
-100%
-50%
0%
50%
100%
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%
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/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%
AUD/USD Jul 2025 - Sep 2025
0.93
Total Trades 206
Won Trades 109
Lost trades 97
Win Rate 52.91 %
Expected payoff -0.63
Gross Profit 1696.80
Gross Loss -1825.80
Total Net Profit -129.00
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.89
Total Trades 210
Won Trades 119
Lost trades 91
Win Rate 56.67 %
Expected payoff -1.79
Gross Profit 3197.11
Gross Loss -3573.01
Total Net Profit -375.90
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.88
Total Trades 192
Won Trades 103
Lost trades 89
Win Rate 53.65 %
Expected payoff -1.13
Gross Profit 1568.54
Gross Loss -1784.65
Total Net Profit -216.11
-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%
GBP/USD Jul 2025 - Sep 2025
0.76
Total Trades 104
Won Trades 56
Lost trades 48
Win Rate 53.85 %
Expected payoff -6.80
Gross Profit 2215.40
Gross Loss -2922.10
Total Net Profit -706.70
-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%
GBP/USD Oct 2024 - Jan 2025
0.68
Total Trades 97
Won Trades 55
Lost trades 42
Win Rate 56.70 %
Expected payoff -8.19
Gross Profit 1690.80
Gross Loss -2485.10
Total Net Profit -794.30
-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%
USD/CHF Jul 2025 - Sep 2025
0.66
Total Trades 200
Won Trades 99
Lost trades 101
Win Rate 49.50 %
Expected payoff -5.42
Gross Profit 2141.75
Gross Loss -3224.96
Total Net Profit -1083.21
-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%
USD/JPY Jul 2025 - Sep 2025
0.57
Total Trades 105
Won Trades 54
Lost trades 51
Win Rate 51.43 %
Expected payoff -11.74
Gross Profit 1649.41
Gross Loss -2882.13
Total Net Profit -1232.72
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.57
Total Trades 209
Won Trades 100
Lost trades 109
Win Rate 47.85 %
Expected payoff -7.33
Gross Profit 2026.10
Gross Loss -3557.20
Total Net Profit -1531.10
-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/CHF Jul 2025 - Sep 2025
0.48
Total Trades 118
Won Trades 56
Lost trades 62
Win Rate 47.46 %
Expected payoff -15.29
Gross Profit 1646.93
Gross Loss -3451.59
Total Net Profit -1804.66
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.26
Total Trades 105
Won Trades 40
Lost trades 65
Win Rate 38.10 %
Expected payoff -17.62
Gross Profit 654.30
Gross Loss -2504.70
Total Net Profit -1850.40
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.24
Total Trades 212
Won Trades 69
Lost trades 143
Win Rate 32.55 %
Expected payoff -15.90
Gross Profit 1042.57
Gross Loss -4413.13
Total Net Profit -3370.56
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.02
Total Trades 125
Won Trades 65
Lost trades 60
Win Rate 52.00 %
Expected payoff -927.75
Gross Profit 1837.60
Gross Loss -117806.90
Total Net Profit -115969.30
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.01
Total Trades 87
Won Trades 47
Lost trades 40
Win Rate 54.02 %
Expected payoff -2196.99
Gross Profit 1737.10
Gross Loss -192875.40
Total Net Profit -191138.30
-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%

Comments