Bronzew_pan_v1

Okay, here's a breakdown of what this MetaTrader script does, explained in a way that doesn't require any programming knowledge.

Overall Goal:

The script is designed to automatically trade in the Forex market based on several technical indicators and some risk management rules. It aims to identify potential entry points for buy or sell orders and manage those trades.

Key Components and Logic:

  1. Settings (External Parameters):

    • The script starts with a section that allows the user to set various parameters. Think of these as knobs and dials you can adjust to fine-tune how the script operates. Important settings include:

      • MagicNumber: A unique identifier for trades placed by this particular script. This helps the script distinguish its trades from others.
      • Lots: The size of the trades the script will place (e.g., 0.1 standard lots). This controls the amount of currency bought or sold in each trade.
      • Slippage: The maximum acceptable difference between the requested price and the actual price when placing an order. This helps avoid unexpected price changes during order execution.
      • lTakeProfit and sTakeProfit: defines take profit points for long(buy) and short(sell) positions respectively, in points
      • lStopLoss and sStopLoss: defines stop loss points for long(buy) and short(sell) positions respectively, in points
      • lTrailingStop and sTrailingStop: defines trailing stop points for long(buy) and short(sell) positions respectively, in points
      • FrMarg: Minimum free margin required to make new trades.
      • porog: Profit threshold to close all positions.
      • per: Period parameter for the indicators.
      • d: Another parameter for the indicators.
      • test: A debugging flag.
      • workb: Parameter for buy condition.
      • works: Parameter for sell condition.
      • pred: Profit threshold for some conditions.
      • sliv: Loss threshold to close all positions.
      • mm: Multiplier for lot size in some conditions.
  2. Initialization (init() function):

    • This part runs once when the script is loaded onto a chart. In this case, it doesn't do anything (it just returns 0), but it's a standard place to put setup code.
  3. Deinitialization (deinit() function):

    • This part runs when the script is removed from the chart or when the trading platform closes. Like the initialization function, it's currently empty.
  4. Main Logic (start() function):

    • This is the heart of the script. It runs repeatedly, checking market conditions and making trading decisions. Here's a breakdown of what it does:

      a. Trade Information:

      • It first counts the number of open and pending orders (buy and sell).
      • It calculates the total profit of all open trades managed by the script.
      • It tracks the maximum drawdown (the largest loss experienced) in the current trading session.

      b. Closing Positions Based on Profit/Loss:

      • If the total profit exceeds the porog value, it closes all open buy and sell orders. The aim is to secure profits.
      • If the total profit falls below the sliv value (a significant loss), it closes all open buy and sell orders. This is a stop-loss mechanism to limit losses.

      c. Trading Conditions:

      • The script checks if the account has sufficient free margin (AccountFreeMargin() >= FrMarg) and if the total number of open positions is less than 2. This helps ensure the script doesn't over-leverage the account.

      • It uses several technical indicators to determine when to open new positions:

        • DayImpuls (Custom Indicator): The script retrieves values from a custom indicator named "DayImpuls". The values of this indicator in the current and previous bar are used to determine the trading conditions.
        • WPR (Williams Percent Range): This indicator helps identify overbought or oversold conditions.
        • CCI (Commodity Channel Index): Another indicator to gauge the strength and direction of a trend.
        • ZigZag (Not used, but calculated): Used to determine potential support and resistance levels.

      d. Buy/Sell Logic:

      • Sell Condition: If the DayImpuls indicator is above a certain threshold (works), rising, the WPR is high, and the CCI is very high, and there are no open sell positions, the script places a sell order.
      • Buy Condition: If the DayImpuls indicator is below a certain threshold (workb), falling, the WPR is low, and the CCI is very low, and there are no open buy positions, the script places a buy order.
      • The conditions include a check s==1 && (summa<=-pred/2 || summa>=pred) or b==1 && (summa<=-pred/2 || summa>=pred), wich opens a new position (buy if last was sell and viceversa) if the condition above is met and the unrealized profit is greather than pred or smaller than -pred/2. This is a safety meassure to avoid losses by closing previous trades

      e. Order Placement:

      • The script uses the OrderSend() function to place buy or sell orders based on the conditions described above.
      • It sets stop-loss and take-profit levels for each order based on the user-defined parameters (e.g., lStopLoss, lTakeProfit).

In simpler terms:

The script is like an automated trader that follows a set of rules. It watches several indicators to find moments when the price might go up or down. If the indicators suggest a price increase, it buys (goes long). If they suggest a price decrease, it sells (goes short). It also has rules to close trades if they become too profitable or too loss-making, to protect the account balance.

Important Considerations:

  • Risk: This script can make trades automatically, which means it can also lose money automatically. It's crucial to understand the settings and how they affect the script's behavior.
  • Testing: Before using this script with real money, it's highly recommended to test it extensively on a demo account to see how it performs under different market conditions.
  • Optimization: The settings of the script (e.g., the values of per, d, works, workb) might need to be adjusted (optimized) for different currency pairs or market conditions.
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
3 Views
0 Downloads
0 Favorites

Profitability Reports

USD/CAD Oct 2024 - Jan 2025
349.00 %
Total Trades 8
Won Trades 4
Lost trades 4
Win Rate 50.00 %
Expected payoff 189.72
Gross Profit 2126.10
Gross Loss -608.34
Total Net Profit 1517.76
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
184.00 %
Total Trades 4
Won Trades 2
Lost trades 2
Win Rate 50.00 %
Expected payoff 126.50
Gross Profit 1107.30
Gross Loss -601.30
Total Net Profit 506.00
-100%
-50%
0%
50%
100%
Bronzew_pan_v1
//+------------------------------------------------------------------+
//|                               Name := BronzeWarrioir01           |
//|                               converted to MT4 by suffic369@yahoo|
//|                               http://www.metaquotes.ru           |
//+------------------------------------------------------------------+
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 ---