BronzeW_Pan

Profit factor:
1.70

The provided code is a script for an Expert Advisor (EA) designed to automate trading on the MetaTrader platform. It uses various technical indicators and conditions to make buy or sell decisions based on predefined parameters.

Here's a breakdown of the key components:

Initialization

  • Parameters: The EA initializes several input parameters like FrMarg, pred, sStopLoss, etc., which determine the behavior and constraints for trading.
  • Global Variables: These include variables like mm (margin multiplier), mlot (lot size), sliv, works, and workb that define trading thresholds and limits.

Trading Logic

  1. Account Margin Check:

    • The EA checks if the account's free margin is greater than or equal to FrMarg.
  2. Position Management:

    • If the sum of open buy (s) and sell (b) positions is less than 2, it evaluates trading conditions.
  3. Sell Conditions:

    • A new short position (sell) can be opened if:
      • The indicator values inul and ione are above certain thresholds.
      • Other indicators like wpr and cci meet specific criteria.
      • There are no existing sell positions (s == 0).
    • If there is an open buy position and the profit or loss reaches a threshold, it closes the position.
  4. Buy Conditions:

    • A new long position (buy) can be opened if:
      • The indicator values inul and ione are below certain thresholds.
      • Other indicators like wpr and cci meet specific criteria.
      • There are no existing buy positions (b == 0).
    • If there is an open sell position and the profit or loss reaches a threshold, it closes the position.
  5. Order Management:

    • The EA uses OrderSend() to execute trades with specified stop-loss (sl) and take-profit (tp) levels.
    • It also includes logic to close existing positions if certain conditions are met.

Considerations

  • Risk Management: The EA incorporates risk management through parameters like FrMarg, sStopLoss, and lTakeProfit.
  • Indicator Usage: It relies on technical indicators such as wpr (Williams %R) and cci (Commodity Channel Index) to make trading decisions.
  • Customization: Parameters can be adjusted to fit different trading strategies or risk preferences.

Improvements

  • Error Handling: Add error handling for order execution failures.
  • Logging: Implement logging for better tracking of trades and decision-making processes.
  • Backtesting: Thoroughly backtest the EA with historical data to ensure its effectiveness before live deployment.
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Larry William percent range indicatorCommodity channel index
10 Views
1 Downloads
0 Favorites
BronzeW_Pan
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/


//Name := BronzeWarrioir01
//converted to MT4 by suffic369@yahoo

extern int MagicNumber=6290102;
extern double Lots=0.1;
extern int Slippage = 3; 

extern double lTakeProfit = 0;
extern double sTakeProfit = 0;
extern double lStopLoss = 0;
extern double sStopLoss = 0;

extern double lTrailingStop = 0;
extern double sTrailingStop = 0;

//extern int mgod=2005;
extern int FrMarg=3000;
extern int porog=500;
extern int per=14;
extern int d=3;
extern int test=0;
extern int workb=-50;
extern int works=50;
extern int pred=100;
extern int sliv=-2000;
extern int mm=30;

 //bool ft=true, first=true,two=false ;
 
 //int mlot=0,j=0,s=0,b=0,os=0,ob=0,pr=4,summa=0,sell=0,buy=0;
 
 //int cnt=0,//Top=0,
// inul=0,ione=0,pm=0,down=0,bloks=0,blokb=0,ps=0,wpr=0,cci=0,zz=0;

int down=0;

int init() {
   return (0);
}

int deinit() {
   return (0);
}

int start() {
//if mgod!=year then exit;

//j=j+1;

//if j>=1000 then j=0;

double mlot=Lots; 

/*
if (ft) {  
   if (Point>0.002) { 
      pr=2;ft=false;
   }
} // pr: 2 or 4,¼Û¸ñСÊýµãºóµÄ¶àÉÙλÊý
*/

int Total = OrdersTotal();

int sbo=0; int s=0; int b=0; int pendings=0; int bpendings=0;int spendings=0;int summa=0; int ssum=0; int bsum=0;
	
   for ( int i=0; i<Total; i++) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if ( (OrderType()==OP_SELLSTOP || OrderType()==OP_BUYSTOP) 
            && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) pendings=pendings+1;
            
         if ( OrderType()==OP_BUYSTOP 
            && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) bpendings=bpendings+1;   
            
         if ( OrderType()==OP_SELLSTOP 
            && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) spendings=spendings+1;
            
         if ( OrderType()<=OP_SELL 
            && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) sbo=sbo+1;//have open trades
       
         if (OrderMagicNumber() == MagicNumber && OrderSymbol()==Symbol() && (OrderType()==OP_SELL || OrderType()==OP_BUY)) {
            summa=summa+OrderProfit();// profit of open trade
         }
      
         if (OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) { 
            s=s+1;//open trade is sell
            //ssum=ssum+OrderProfit();//sell trade profit
         }
         if (OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)  { 
            b=b+1;//have open buy
            //bsum=bsum+OrderProfit();//buy trade profit
         }
      }
   }
 
 
if (b+s==0 ) {
   int pm=0;int ps=0;
}

  	      
if (summa<0 && summa< down)     down=MathRound(summa);
    
//If (CurTime-LastTradeTime<15)  return(0);    
        
if (s+b+bpendings+spendings==0 && AccountBalance()==AccountFreeMargin() && AccountBalance()<5000) {
   Comment(" ");return(0);
}

double inul=iCustom(NULL,0,"DayImpuls",per,d,0,0);
double ione=iCustom(NULL,0,"DayImpuls",per,d,0,1);
double wpr=iWPR(NULL,0,per,0);
double cci=iCCI(NULL,0,per,PRICE_CLOSE,0);
double zz=0; // ZZ2=iCustom(NULL,0,"ZigZag",depth,deviation,backstep,0,0);

if (test==1) {  //default test=0
   Print("Data: ",Year(),".",Month(),".",Day(),"  Pozz=",s+b,"  Impuls=",MathRound(inul),
      "  WPR=",MathRound(wpr),"  CCI=",MathRound(cci),"  ZZ=",zz,"  Price=",Open[0],"  Prof=",MathRound(summa),"  Down=",MathAbs(down));
   //if j<=2 then Comment("  ");
}  

if (test==0) { 
   Comment("Data: ",Year(),".",Month(),".",Day(),"  Time ",Hour(),":",Minute(),"\n","Pozz=",s+b,"  Impuls=",MathRound(inul),
        "  WPR=",MathRound(wpr),"  CCI=",MathRound(cci),"  Price=",Open[0],"  Prof=",MathRound(summa),"  Down=",MathAbs(down));
}


if (summa>=porog)  pm=1;

if (pm==1) { 

   for ( i=0; i<Total; i++) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) {
            OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
            return(0);
         } 
         if (OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)  { 
            OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
            return(0);
         }
      }
   }
}

if (summa<sliv)  ps=1;

if (ps==1) {

   for ( i=0; i<Total; i++) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) {
            OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
            return(0);
          }
         if (OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)  { 
            OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
            return(0);
         }
      } 
   }
}

   if (s+b==0) { int bloks=0;int blokb=0;}
   

   if (AccountFreeMargin()>=FrMarg && s+b<2) {

      if (bloks==0) { 
         if (inul>works && ione>inul && wpr>-15 && cci>150 && s==0) {
            //Top=Bid;
            blokb=1; 
            if (sStopLoss>0)  double sl= Bid+sStopLoss*Point; else sl= 0;
    	      if (sTakeProfit>0)  double tp= Bid-sTakeProfit*Point; else tp= 0;
            OrderSend(Symbol(),OP_SELL,mlot,Bid,Slippage,sl,tp,"sell"+MagicNumber,MagicNumber,0,Red);
            //Setorder(OP_SELL,mlot,PriceBid,3,Bid+StopLoss*point,Bid-TakeProfit*point,Gold);
            return(0);
         } 
         if (b==0 && s==1 && (summa<=-pred/2 || summa>=pred)) {  
            if (lStopLoss>0)   sl= Ask-lStopLoss*Point; else sl= 0;
    	      if (lTakeProfit>0)   tp= Ask+lTakeProfit*Point; else tp= 0;
            OrderSend(Symbol(),OP_BUY,mm*mlot,Ask,Slippage,sl,tp,"buy"+MagicNumber,MagicNumber,0,Blue);
            //Setorder(OP_BUY,mm*mlot,PriceAsk,3,Ask-StopLoss*point,Ask+TakeProfit*point,Gold);
            return(0);
         }
      }
   
      if (blokb==0) { 
         if (inul<workb && ione<inul && wpr<-85 && cci<-150 && b==0) { 
            //Top=Ask;
            bloks=1; 
            if (lStopLoss>0)   sl= Ask-lStopLoss*Point; else sl= 0;
    	      if (lTakeProfit>0)   tp= Ask+lTakeProfit*Point; else tp= 0;
            OrderSend(Symbol(),OP_BUY,mlot,Ask,Slippage,sl,tp,"buy"+MagicNumber,MagicNumber,0,Blue);
            //Setorder(OP_BUY,mlot,PriceAsk,3,Ask-StopLoss*point,Ask+TakeProfit*point,Gold);
            return(0);
         } 
         if (s==0 && b==1 && (summa<=-pred/2 || summa>=pred)) {
            if (sStopLoss>0)  sl= Bid+sStopLoss*Point; else sl= 0;
    	      if (sTakeProfit>0)  tp= Bid-sTakeProfit*Point; else tp= 0;
            OrderSend(Symbol(),OP_SELL,mm*mlot,Bid,Slippage,sl,tp,"sell"+MagicNumber,MagicNumber,0,Red);
            //Setorder(OP_SELL,mm*mlot,PriceBid,3,Bid+StopLoss*point,Bid-TakeProfit*point,Gold);
            return(0);
         }
      }
   }
  
  
return(0);
}

Profitability Reports

GBP/USD Jul 2025 - Sep 2025
1.41
Total Trades 2
Won Trades 1
Lost trades 1
Win Rate 50.00 %
Expected payoff 29.95
Gross Profit 205.50
Gross Loss -145.60
Total Net Profit 59.90
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
1.39
Total Trades 2
Won Trades 1
Lost trades 1
Win Rate 50.00 %
Expected payoff 2.10
Gross Profit 14.97
Gross Loss -10.77
Total Net Profit 4.20
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
3.40
Total Trades 6
Won Trades 3
Lost trades 3
Win Rate 50.00 %
Expected payoff 169.83
Gross Profit 1443.62
Gross Loss -424.65
Total Net Profit 1018.97
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 2
Won Trades 2
Lost trades 0
Win Rate 100.00 %
Expected payoff 22.75
Gross Profit 45.50
Gross Loss 0.00
Total Net Profit 45.50
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.04
Total Trades 4
Won Trades 2
Lost trades 2
Win Rate 50.00 %
Expected payoff -493.22
Gross Profit 77.80
Gross Loss -2050.70
Total Net Profit -1972.90
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
1.59
Total Trades 4
Won Trades 2
Lost trades 2
Win Rate 50.00 %
Expected payoff 146.23
Gross Profit 1582.38
Gross Loss -997.47
Total Net Profit 584.91
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
1.03
Total Trades 2
Won Trades 1
Lost trades 1
Win Rate 50.00 %
Expected payoff 19.50
Gross Profit 1490.98
Gross Loss -1451.97
Total Net Profit 39.01
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
1.03
Total Trades 3
Won Trades 2
Lost trades 1
Win Rate 66.67 %
Expected payoff 162.03
Gross Profit 15943.58
Gross Loss -15457.49
Total Net Profit 486.09
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
1.04
Total Trades 2
Won Trades 1
Lost trades 1
Win Rate 50.00 %
Expected payoff 9.55
Gross Profit 499.70
Gross Loss -480.60
Total Net Profit 19.10
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
2.13
Total Trades 8
Won Trades 4
Lost trades 4
Win Rate 50.00 %
Expected payoff 200.44
Gross Profit 3018.30
Gross Loss -1414.80
Total Net Profit 1603.50
-100%
-50%
0%
50%
100%

Comments