Precipice_MartIn

Author: Maximus_genuine
Profit factor:
1.47

Okay, here's a breakdown of what the provided script does, explained in a way that's easy to understand even if you don't know programming.

This script is designed to automatically place buy and sell orders in the Forex market. It's an automated trading system (often called an "Expert Advisor" or EA) for the MetaTrader platform.

Here's the gist of its operation:

  1. Overall Goal: The script aims to generate profits by automatically executing trades based on certain conditions. It focuses on both buying (going long) and selling (going short).

  2. Initial Setup:

    • The script starts by reading in some settings that you can adjust. These settings include:
      • Whether to enable buying ("In_BUY")
      • Whether to enable selling ("In_SELL")
      • Distance for Buy and Sell orders to be placed on the price chart.
      • Probability of the EA entering into a BUY or SELL order.
    • It also sets up some internal variables for tracking time and identifying trades placed by the script.
  3. Trading Logic (The start() Function):

    • The core of the script runs within the start() function, which is executed repeatedly by MetaTrader.
    • Time Check: It first checks if the current time is the same as the last time it ran. If so, it does nothing (to avoid repeating actions on the same price tick).
    • Trade Allowed Check: It then verifies whether trading is allowed at the moment (e.g., the market isn't closed).
    • Buy/Sell Execution (My_Play() function): The most important part is calling the My_Play() function twice ? once for buying and once for selling. The My_Play() function determines if conditions are right to initiate a trade and then places the order.
    • It uses random numbers to create a probability that is compared with the level parameters to open positions.
    • It defines Stop Loss and Take Profit levels for the operations.
  4. The My_Play() Function (Detailed): This is where the actual trade placement logic resides.

    • Order Check: It scans through all existing orders to see if there are already orders placed by this script for the current currency pair.
    • Conditions to Open a Trade: The script then checks several conditions:
      • Is buying (or selling) enabled? (flag)
      • Are there any open orders? (OrdersTotal()==0)
      • Does a random number meet a certain threshold? This adds an element of randomness to the entry. level*327.68 > MathRand()
      • Is trading allowed?
    • Order Placement: If all the conditions are met, the script sends an order to the broker to either buy or sell. It sets a Stop Loss and Take Profit level to manage risk.
    • Error Handling: It checks if the order was successfully placed. If not, it pauses for a short time and tries again later.
  5. Lot Sizing (lot() function): This determines the size of the trade.

    • Martingale Feature: If the "MartIn" (Martingale) setting is enabled, this function implements a basic Martingale strategy. The Martingale strategy involves doubling the lot size after each losing trade in an attempt to recover losses quickly. If the last order has a negative profit, the lot size will be bigger.
    • Initial Lot Size: If the Martingale strategy is not enabled, it uses a default lot size, otherwise it checks if there are previous trades and increases lot size if they where negative.

In summary: This script is a basic automated trading system designed to enter buy and sell orders based on a combination of user-defined settings, random chance, and an optional Martingale lot sizing strategy. The intention is to automate a trading strategy to try to profit from price movements in the market.

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedChecks for the total of closed orders
10 Views
0 Downloads
0 Favorites
Precipice_MartIn
//+------------------------------------------------------------------+
//|                                             Precipice_MartIn.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Maximus_genuine  "
#property link      "gladmxm@bigmir.net"
 
//---- input parameters
//..........................................................................
extern bool       MartIn =true;

//..........................................................................
extern bool      In_BUY   =true;
extern int       step_BUY =89;       //---âõîäíûå ïàðàìåòðû ïî ëîíãàì
extern int       level_BUY=50;  
 
//..........................................................................
extern bool      In_SELL   =true;
extern int       step_SELL =89;      //---âõîäíûå ïàðàìåòðû ïî øîðòàì
extern int       level_SELL=50; 
 
//..........................................................................
 
//---- other parameters
   static int  prevtime=0;
          int    ticket=0;
          int         x=1;
       //-------------------------
          int Magic_BUY  =123;
          int Magic_SELL =321;
         
 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//--------------------------------
      if(Digits == 5) x=10;
      
      MathSrand(TimeCurrent());
//--------------------------------
    if (step_BUY< 20)  step_BUY=20;
    if (step_SELL<20) step_SELL=20;
    
    if( level_BUY< 1) level_BUY= 1;
    if( level_BUY>99) level_BUY=99;
    
    if( level_SELL<1 ) level_SELL= 1;
    if( level_SELL>99) level_SELL=99;
//--------------------------------
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//..........................................................................
    if (Time[0] == prevtime) return(0); 
                             prevtime = Time[0];
    if (!IsTradeAllowed()) {
     prevtime=Time[1]; Sleep(30000 + MathRand());  //--- ôîðìèðîâêà áàðà---
                           }
//..........................................................................
 
 
                My_Play( Magic_BUY, In_BUY, level_BUY, step_BUY);    //---òîðãîâëÿ ïî ëîíãàì
   
   
                My_Play(Magic_SELL,In_SELL,level_SELL,step_SELL);  //---òîðãîâëÿ  ïî øîðòàì
   
   
//..........................................................................
   return(0);//-----------âûõîä èç ñòàðòîâîé ôóíêöèè------------
  }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void  My_Play(int mn,bool flag,int level,int step) { 
 
         int total=OrdersTotal();
         
    for (int i = 0; i < total; i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES);//---ïðîõîä ïî îðäåðàì--
    
    
                if (OrderSymbol() == Symbol() && OrderMagicNumber() == mn) { 
                
            
                
                return(0);
                                                                           } 
                                    }
 
//..........................................................................
      ticket = -1;  
      
   
 
  if (  flag                           &&
  
         OrdersTotal()==0              &&
  
        level*327.68 > MathRand() &&    //----ðàíäîìíûé âõîä â ðûíîê ---
      
      
           IsTradeAllowed()) { 
           
           if (mn<200)      {
  
 ticket= OrderSend(Symbol(), OP_BUY,lot(),Ask,5*x,Bid-x*step*Point,Ask+x*step*Point,DoubleToStr(mn,0),mn,0,Blue);
                         
    
                            }
                         
                         
                         else {
                         
 ticket= OrderSend(Symbol(),OP_SELL,lot(),Bid,5*x,Ask+x*step*Point,Bid-x*step*Point,DoubleToStr(mn,0),mn,0, Red);
                        
                              }
        
   
                 RefreshRates();   
      
              if ( ticket < 0) { Sleep(30000);   prevtime = Time[1]; } 
                                           
                                           } //-- Exit ---
 
       return(0); } 
       
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 double lot() {      int k=1;  if ( !MartIn ) return (0.1);
 
       if (OrdersHistoryTotal()==0) return(0.1); 
       
       int i,accTotal=OrdersHistoryTotal()-1; 
      
     
                 for  (i=accTotal;i>-1;i--)// ïåðåáîð îðäåðîâ...
                 
                            { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
                            
                       { Print("Îøèáêà ïðè äîñòóïå ê èñòîðè÷åñêîé áàçå (",GetLastError(),")");
                       
                               break; } // ðàáîòà ñ îðäåðîì ...
                               
        if(OrderCloseTime()!=0 && OrderProfit()>0)   bool mart=true; //-------
  
        if (OrderCloseTime()!=0  && OrderProfit()<0 && !mart)  k=2*k;

                                      
     }//-end-for-
             return(k*0.1);}//-----
   //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Profitability Reports

USD/CHF Jul 2025 - Sep 2025
0.31
Total Trades 8
Won Trades 4
Lost trades 4
Win Rate 50.00 %
Expected payoff -124.51
Gross Profit 443.85
Gross Loss -1439.90
Total Net Profit -996.05
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
1.44
Total Trades 13
Won Trades 7
Lost trades 6
Win Rate 53.85 %
Expected payoff 31.16
Gross Profit 1331.84
Gross Loss -926.82
Total Net Profit 405.02
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
1.50
Total Trades 7
Won Trades 3
Lost trades 4
Win Rate 42.86 %
Expected payoff 29.53
Gross Profit 623.00
Gross Loss -416.30
Total Net Profit 206.70
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.26
Total Trades 27
Won Trades 13
Lost trades 14
Win Rate 48.15 %
Expected payoff 36.98
Gross Profit 4895.00
Gross Loss -3896.60
Total Net Profit 998.40
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
1.09
Total Trades 15
Won Trades 5
Lost trades 10
Win Rate 33.33 %
Expected payoff 14.59
Gross Profit 2638.56
Gross Loss -2419.65
Total Net Profit 218.91
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
1.15
Total Trades 38
Won Trades 19
Lost trades 19
Win Rate 50.00 %
Expected payoff 20.31
Gross Profit 5871.65
Gross Loss -5099.87
Total Net Profit 771.78
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
2.15
Total Trades 43
Won Trades 26
Lost trades 17
Win Rate 60.47 %
Expected payoff 52.05
Gross Profit 4183.00
Gross Loss -1945.00
Total Net Profit 2238.00
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.31
Total Trades 12
Won Trades 5
Lost trades 7
Win Rate 41.67 %
Expected payoff 28.35
Gross Profit 1426.20
Gross Loss -1086.00
Total Net Profit 340.20
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.41
Total Trades 213
Won Trades 108
Lost trades 105
Win Rate 50.70 %
Expected payoff -14.11
Gross Profit 2076.70
Gross Loss -5082.69
Total Net Profit -3005.99
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
1.33
Total Trades 38
Won Trades 19
Lost trades 19
Win Rate 50.00 %
Expected payoff 49.39
Gross Profit 7530.95
Gross Loss -5654.21
Total Net Profit 1876.74
-100%
-50%
0%
50%
100%

Comments