FT_CCI_0.4(+MA)mq4

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

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
2 Views
0 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%
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%
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%
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%

Comments