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

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

USD/JPY Jul 2025 - Sep 2025
1.80
Total Trades 49
Won Trades 31
Lost trades 18
Win Rate 63.27 %
Expected payoff 13.19
Gross Profit 1449.59
Gross Loss -803.29
Total Net Profit 646.30
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.74
Total Trades 44
Won Trades 23
Lost trades 21
Win Rate 52.27 %
Expected payoff -7.61
Gross Profit 953.02
Gross Loss -1287.88
Total Net Profit -334.86
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.62
Total Trades 53
Won Trades 24
Lost trades 29
Win Rate 45.28 %
Expected payoff -6.58
Gross Profit 578.56
Gross Loss -927.19
Total Net Profit -348.63
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.78
Total Trades 43
Won Trades 23
Lost trades 20
Win Rate 53.49 %
Expected payoff -3.75
Gross Profit 563.10
Gross Loss -724.50
Total Net Profit -161.40
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.54
Total Trades 52
Won Trades 27
Lost trades 25
Win Rate 51.92 %
Expected payoff -22.76
Gross Profit 1404.70
Gross Loss -2588.40
Total Net Profit -1183.70
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.63
Total Trades 61
Won Trades 36
Lost trades 25
Win Rate 59.02 %
Expected payoff -11.31
Gross Profit 1189.15
Gross Loss -1878.93
Total Net Profit -689.78
-100%
-50%
0%
50%
100%
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%

Comments