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

This script is designed to automatically trade on the Forex market using a strategy based on the Commodity Channel Index (CCI) indicator. Here's a breakdown of its logic:

  1. Setup:

    • The script starts by defining some settings that the user can adjust, such as the CCI period (how many past data points to consider for CCI calculation), the CCI levels for triggering buy or sell signals, stop loss and take profit values, the lot size for each trade, and a magic number to identify the trades opened by this script.
  2. Trading Logic:

    • The script continuously monitors the CCI value.
    • It uses two key CCI levels (an upper and a lower threshold) to identify potential buying or selling opportunities.
      • If the CCI goes below the lower threshold (meaning the price is potentially oversold), the script remembers that it's looking for a buy opportunity.
      • If the CCI then rises back above the lower threshold, the script executes a buy order (if trading time restrictions are fulfilled). In this case the script also tries to close all sell positions.
      • Conversely, if the CCI goes above the upper threshold (meaning the price is potentially overbought), the script remembers that it's looking for a sell opportunity.
      • If the CCI then falls back below the upper threshold, the script executes a sell order (if trading time restrictions are fulfilled). In this case the script also tries to close all buy positions.
    • This ensures trades are opened when the CCI crosses back from extreme overbought or oversold areas.
    • The script manages open trades based on the CCI indicator.
  3. Order Execution:

    • When a buy or sell signal is triggered, the script sends an order to the broker to open a position. It includes the desired lot size, stop loss (if defined), and take profit (if defined).
  4. Time Restrictions:

    • The script includes optional time-based restrictions. It can be configured to only trade during specific hours of the day.
  5. Position Management:

    • The script can close all existing buy or sell positions when a new signal in the opposite direction is generated. This function is controlled by the signals generated by the CCI.
  6. Additional Functions:

    • It has functions to check if there are already open positions of a certain type (buy or sell).
    • It can calculate the total profit or loss of all open positions of a specific type.
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt Closes Orders by itself
Indicators Used
Commodity channel index
5 Views
1 Downloads
0 Favorites
FT_CCI
//+------------------------------------------------------------------+
//|                                                       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/
*/

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

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

extern int mn=1;
int err;

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


int start()
  {
  
  OpenPattern();//îòêðûâàåì ñäåëêè ïðè ìåðåñå÷åíèè

   return(0);
  }
  
int okbuy,oksell;

void OpenPattern()
{
 double op,sl,tp;
 double CCICurr=iCCI(Symbol(),0,cciper,PRICE_TYPICAL,1);
   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(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.35
Total Trades 44
Won Trades 26
Lost trades 18
Win Rate 59.09 %
Expected payoff 8.64
Gross Profit 1458.38
Gross Loss -1078.35
Total Net Profit 380.03
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 6
Won Trades 3
Lost trades 3
Win Rate 50.00 %
Expected payoff -17608.48
Gross Profit 76.00
Gross Loss -105726.90
Total Net Profit -105650.90
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.08
Total Trades 49
Won Trades 27
Lost trades 22
Win Rate 55.10 %
Expected payoff 1.44
Gross Profit 1007.10
Gross Loss -936.40
Total Net Profit 70.70
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
1.92
Total Trades 103
Won Trades 71
Lost trades 32
Win Rate 68.93 %
Expected payoff 20.23
Gross Profit 4350.88
Gross Loss -2267.50
Total Net Profit 2083.38
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
1.35
Total Trades 113
Won Trades 73
Lost trades 40
Win Rate 64.60 %
Expected payoff 5.62
Gross Profit 2436.13
Gross Loss -1800.97
Total Net Profit 635.16
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.82
Total Trades 114
Won Trades 69
Lost trades 45
Win Rate 60.53 %
Expected payoff -6.24
Gross Profit 3313.10
Gross Loss -4024.40
Total Net Profit -711.30
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.52
Total Trades 123
Won Trades 58
Lost trades 65
Win Rate 47.15 %
Expected payoff -18.67
Gross Profit 2466.97
Gross Loss -4763.03
Total Net Profit -2296.06
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
1.14
Total Trades 109
Won Trades 70
Lost trades 39
Win Rate 64.22 %
Expected payoff 4.36
Gross Profit 3830.69
Gross Loss -3355.95
Total Net Profit 474.74
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.01
Total Trades 52
Won Trades 30
Lost trades 22
Win Rate 57.69 %
Expected payoff -5502.43
Gross Profit 1627.70
Gross Loss -287754.00
Total Net Profit -286126.30
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.01
Total Trades 61
Won Trades 38
Lost trades 23
Win Rate 62.30 %
Expected payoff -2802.61
Gross Profit 1559.40
Gross Loss -172518.50
Total Net Profit -170959.10
-100%
-50%
0%
50%
100%

Comments