BronzeW_Pan

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
0 Views
0 Downloads
0 Favorites

Profitability Reports

NZD/USD Oct 2024 - Jan 2025
184.00 %
Total Trades 4
Won Trades 2
Lost trades 2
Win Rate 0.50 %
Expected payoff 126.50
Gross Profit 1107.30
Gross Loss -601.30
Total Net Profit 506.00
-100%
-50%
0%
50%
100%
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);
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---