ComFracti_v2.1

Author: mich99@o2.pl
Profit factor:
1.19

Professional Description of the ComFracti.mq4 Script Logic

Overview

The ComFracti.mq4 script is an Expert Advisor (EA) designed for use in MetaTrader 4, a popular trading platform. It automates trading decisions based on specific technical indicators and conditions. The EA operates by placing buy or sell orders when certain criteria are met and manages open positions using trailing stops.

Key Features

  1. Trade Entry Conditions:

    • The script uses fractals, SAR (Parabolic Stop and Reverse) values, and RSI (Relative Strength Index) to determine trade entry points.
    • It places a buy order if the conditions for an upward trend are met or a sell order for a downward trend.
  2. Fractals:

    • Fractals are patterns that indicate potential reversal points in the market.
    • The script checks specific time frames and levels to identify these patterns.
  3. SAR (Parabolic Stop and Reverse):

    • SAR is used to determine the direction of the trend and potential entry points.
    • Two different SAR values are compared to refine trade signals.
  4. RSI (Relative Strength Index):

    • RSI is a momentum oscillator that measures the speed and change of price movements.
    • The script uses RSI to avoid trades when the market is overbought or oversold.
  5. Trailing Stop Management:

    • The EA adjusts stop-loss levels dynamically as prices move in favor of open positions, locking in profits while allowing room for further gains.
  6. Order Management:

    • It checks for existing orders to avoid duplication and manages them based on current market conditions.
    • Optionally closes positions if they are not performing well.
  7. Risk Management:

    • The script calculates lot sizes based on account free margin and predefined risk levels, ensuring that trades do not exceed a certain percentage of the trader's capital.
  8. Customizable Parameters:

    • Users can adjust various parameters such as stop-loss, take-profit, trailing stops, and risk level to suit their trading strategy.

Operation

  • The script runs continuously in the background, checking market conditions at each tick.
  • If the time has not changed since the last check, it exits early to save resources.
  • It evaluates the market using the defined indicators and decides whether to open a new position or adjust existing ones.
  • The EA is designed to be user-friendly, allowing traders with varying levels of experience to implement automated trading strategies.

Conclusion

The ComFracti.mq4 script leverages technical analysis tools like fractals, SAR, and RSI to automate trading decisions in MetaTrader 4. It offers features for trade entry, exit, and risk management, making it a versatile tool for traders looking to automate their strategies while maintaining control over key parameters.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Indicators Used
FractalsParabolic Stop and Reverse systemRelative strength index
9 Views
1 Downloads
0 Favorites
ComFracti_v2.1
//+---------------------------------------------------------------------------------+
//|                                 ComFracti.mq4                                   |
//|                                                                                 |
//| If You make too much money with this EA - some gift or donations accepted [:-)  |
//+---------------------------------------------------------------------------------+
#property copyright " mich99@o2.pl "
#property link      " "

//---- input parameters 
extern int          mn = 818;
extern double       tp = 2000; // ( for 5 digits brokers )
extern double       sl = 1000;
extern double       TrailingStop=300;
extern double       lots = 0.1;
extern bool         MM = false;
extern double       Risk= 0.005;
extern double       multilot=0;
extern bool         closeby = false;
static int          prevtime = 0;


extern int          sh2 = 3; 
extern int          sh3 = 3;
extern int          sh4 = 3;
extern int          sh5 = 3;

extern int          per_rsi=3; // rsi1440 period 

extern double       sars1=0.02; // if sar1 = sar2,that sar filter is with out mining.
extern double       sars2=0.03;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   if (Time[0] == prevtime) return(0);
   prevtime = Time[0];
   
   if (! IsTradeAllowed()) {
      again();
      return(0);
   }
//----
   int total = OrdersTotal();
   for (int i = 0; i < total; i++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == mn) {
      
      if(OrderType()<=OP_SELL && TrailingStop>0)
          {
             
              TrailingPositions();

          }
          
           if(OrderType() == OP_BUY && psv()  < 0 && closeby )
          {
             
              OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),30,GreenYellow);

          }
          if(OrderType() == OP_SELL && psv()  > 0 && closeby)
          {
             
              OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),30,GreenYellow);

          }
         return(0);
      } 
   }
   
 
   
   int ticket = -1;
   
   RefreshRates();
   
   if (psv()  > 0) {
      ticket = OrderSend(Symbol(), OP_BUY, LotSize(), Ask, 30, Bid - sl * Point, Bid + tp * Point, WindowExpertName(), mn, 0, Blue); 
      if (ticket < 0) {
         again();      
      }
   } if (psv()  < 0) {
      ticket = OrderSend(Symbol(), OP_SELL, LotSize(), Bid, 30, Ask + sl * Point, Ask - tp * Point, WindowExpertName(), mn, 0, Red); 
      if (ticket < 0) {
         again();
      }
   }
//-- Exit --
   return(0);
}


 double Crof(int t , int s)
    
    
   {
     
   double frup = iFractals(NULL, t, MODE_UPPER, s);
   double frdw = iFractals(NULL, t, MODE_LOWER, s);

  
    
    if ( (frup==0 ) && frdw!=0 ) return (1); 
    if ( (frdw==0 ) && frup!=0 ) return (-1); 
   
    
     
     return (0); //elsewhere
   }    


 

 

      

double psv()   {

    double  s1 = iSAR(NULL, 0, sars1, 0.2, 0);
    double  s2 = iSAR(NULL, 0, sars2, 0.2, 0);
 
    double m6=iRSI(NULL, 1440, per_rsi, PRICE_OPEN, 0);

   if ( Crof(0 , sh2)>0  && Crof(60 , sh3)>0  && m6<50  && s1>=s2 )  return(1);
    
   if ( Crof(0 , sh4)<0  && Crof(60 , sh5)<0  && m6>50  && s1<=s2 ) return(-1);
      
      
   return(0);
  
}

//+--------------------------- getLots ----------------------------------+
   
  double LotSize()
  {
  double DecreaseFactor=multilot;
  
   double lot=lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
//---- select lot size
   lot=MathCeil(AccountFreeMargin() * Risk / 1000)/10;
//---- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
         //----
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>0) lot=NormalizeDouble(lot-(-1)*lot*DecreaseFactor,1);
     }
//---- return lot size
   if(lot<0.01) lot=MarketInfo(Symbol(), MODE_MINLOT);
   if(!MM) lot=lots;
   return(lot);
  }
  
  
void TrailingPositions() {
  double pp;
  int TrailingStep = 1;
  bool ProfitTrailing = true;
  pp = Point;
  if (OrderType()==OP_BUY) 
  {
    
    if (!ProfitTrailing || (Bid-OrderOpenPrice())>TrailingStop*pp*2) 
    {
      if (OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*pp) 
      {
        ModifyStopLoss(Bid-TrailingStop*pp);
        return;
      }
    }
  }
  if (OrderType()==OP_SELL) 
  {
  
    if (!ProfitTrailing || OrderOpenPrice()-Ask>TrailingStop*pp*2) 
    {
      if (OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) 
      {
        ModifyStopLoss(Ask+TrailingStop*pp);
        return;
      }
    }
  }
}
//--------------------------------------------------------------------------------------// 
void ModifyStopLoss(double ldStopLoss) {
  bool fm;

  fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,Yellow);
  
}
//-------------------------



void again() {
   prevtime = Time[1];
   Sleep(10000);
}

Profitability Reports

GBP/AUD Jul 2025 - Sep 2025
0.75
Total Trades 31
Won Trades 18
Lost trades 13
Win Rate 58.06 %
Expected payoff -7.12
Gross Profit 672.88
Gross Loss -893.70
Total Net Profit -220.82
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
3.77
Total Trades 20
Won Trades 16
Lost trades 4
Win Rate 80.00 %
Expected payoff 56.08
Gross Profit 1526.70
Gross Loss -405.20
Total Net Profit 1121.50
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
3.50
Total Trades 7
Won Trades 6
Lost trades 1
Win Rate 85.71 %
Expected payoff 36.23
Gross Profit 355.00
Gross Loss -101.40
Total Net Profit 253.60
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
1.24
Total Trades 92
Won Trades 55
Lost trades 37
Win Rate 59.78 %
Expected payoff 6.41
Gross Profit 3097.00
Gross Loss -2507.50
Total Net Profit 589.50
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
1.12
Total Trades 42
Won Trades 26
Lost trades 16
Win Rate 61.90 %
Expected payoff 5.37
Gross Profit 2093.82
Gross Loss -1868.17
Total Net Profit 225.65
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
1.08
Total Trades 46
Won Trades 29
Lost trades 17
Win Rate 63.04 %
Expected payoff 2.06
Gross Profit 1305.97
Gross Loss -1211.08
Total Net Profit 94.89
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
1.39
Total Trades 47
Won Trades 30
Lost trades 17
Win Rate 63.83 %
Expected payoff 13.96
Gross Profit 2336.70
Gross Loss -1680.60
Total Net Profit 656.10
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.71
Total Trades 67
Won Trades 33
Lost trades 34
Win Rate 49.25 %
Expected payoff -10.98
Gross Profit 1814.98
Gross Loss -2550.68
Total Net Profit -735.70
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.83
Total Trades 87
Won Trades 47
Lost trades 40
Win Rate 54.02 %
Expected payoff -5.36
Gross Profit 2271.73
Gross Loss -2738.31
Total Net Profit -466.58
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.76
Total Trades 56
Won Trades 31
Lost trades 25
Win Rate 55.36 %
Expected payoff -10.82
Gross Profit 1896.30
Gross Loss -2502.10
Total Net Profit -605.80
-100%
-50%
0%
50%
100%

Comments