Smc_hilo_v11.1_www.forex-instruments.info

Download script
Profit factor:
15.86

Technical Logic Overview: SMC MaxMin at 1200

This document provides a professional explanation of the logic contained within the provided trading script. The script is designed to automate specific entry and management rules based on time, price levels, and basic risk parameters.


1. Initialization and Safety Checks

Before the script begins executing trades, it performs several "sanity checks" to ensure the environment is suitable for operation:

  • Data Integrity: It verifies that there are at least 100 historical bars available on the chart.
  • Parameter Validation: It ensures that the user-defined Take Profit value is set to a logical minimum (at least 10 points) to prevent execution errors.

2. Time-Based Order Cleanup

The script monitors the server time to perform maintenance:

  • Order Removal: At a specific hour defined by the user (SetHour + 2), the script scans for any "Pending Orders" (specifically Buy Stops and Sell Stops). If it finds these, it deletes them. This serves as a mechanism to clear out stale orders that were not triggered by the time of execution.

3. Trade Management & Trailing Stops

The script includes logic to manage active positions to protect capital:

  • Trailing Stop Logic: For both Buy and Sell positions, the script monitors the price movement. If the price moves in favor of the trade by a specific distance (defined by TrailingStop), the script automatically adjusts the Stop Loss to "trail" behind the current price. This locks in profits while allowing the trade room to continue moving in the desired direction.
  • Profit Protection: There is an internal logic block designed to move Stop Losses closer to the entry price if a certain distance is met, aiming to ensure the trade stays in a profit state.

4. Entry Restrictions

To prevent over-leveraging and ensure systematic execution, the script enforces several restrictions before opening new trades:

  • Single Position Rule: The script checks if an order already exists for the current currency symbol. It will not open a second position if one is already active.
  • Margin Check: It verifies that the account has sufficient "Free Margin" (available funds) to support the required lot size before attempting to place a trade.
  • Historical Cooling (Optional): There is a placeholder logic section intended to prevent the script from opening new trades if one was closed too recently (within the same timeframe).

5. Execution Strategy (The Entry Logic)

The core trading activity occurs at the specific hour designated by SetHour. When that time is reached, the script attempts to place four distinct types of orders:

A. Buy Side (Long):

  • It calculates a high price point based on the previous candle's high and minimum allowed distance.
  • Primary Action: It attempts to place a Buy Stop order slightly above this high price.
  • Fallback: If the Buy Stop cannot be placed (e.g., due to broker restrictions), it immediately tries to open a standard Buy market order at the current price.

B. Sell Side (Short):

  • It calculates a low price point based on the previous candle's low and minimum allowed distance.
  • Primary Action: It attempts to place a Sell Stop order slightly below this low price.
  • Fallback: If the Sell Stop cannot be placed, it immediately tries to open a standard Sell market order at the current price.

6. Summary of Visual Feedback

The script uses color-coded logging (Orange, Red, Yellow, Pink, etc.) in the terminal and on the charts to provide the user with visual confirmation of whether Buy/Sell orders were successfully placed or if errors occurred during execution.

Price Data Components
Series array that contains open time of each bar
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
15 Views
0 Downloads
0 Favorites
Smc_hilo_v11.1_www.forex-instruments.info
//+------------------------------------------------------------------+
//|                                      SMC MaxMin at 1200.mq4      |
//+------------------------------------------------------------------+
 double TakeProfit=500;
 double Lots=0.1;
 double InitialStop=10;
 double TrailingStop=30;
 int SetHour=15;
 int cnt,total,ticket,MinDist;
 int SigPos;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int Flag;
   double Spread;
   double ATR;
   double StopMA;
   int cnt, tmp;
   double SetupHigh, SetupLow;
   // initial data checks
   // it is important to make sure that the expert works with a normal
   // chart and the user did not make any mistakes setting external 
   // variables (Lots, StopLoss, TakeProfit, 
   // TrailingStop) in our case, we check TakeProfit
   // on a chart of less than 100 bars
   Spread=(Ask-Bid);
     if(Bars<100)
     {
      Print("bars less than 100");
      return(0);
     }
     if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
   //TrailingStop=iATR(NULL,0,10,0)*2; // BE CAREFUL OF EFFECTING THE AUTO TRAIL STOPS
   StopMA=iMA(NULL,0,24,0,MODE_SMA,PRICE_CLOSE,0);
   if (TimeHour(CurTime())==SetHour+2)
     {
      if (total>0)
        {
         for(cnt=0;cnt<total;cnt++)
           {
            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
            if(OrderType()==OP_BUYSTOP && OrderSymbol()==Symbol())
              {OrderDelete(OrderTicket() );
              Print("BUYSTOP Deleted" );
              }
            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
            if(OrderType()==OP_SELLSTOP && OrderSymbol()==Symbol())
              {OrderDelete(OrderTicket() );
               Print("BUYSTOP Deleted" );
              }
             } 
            }
           }
   //ALWAYS TRY TO COME OUT WITH A PROFIT:
   if(0==1)
     {
      total=OrdersTotal();
      if (total>0)
        {
         for(cnt=0;cnt<total;cnt++)
           {
            //LONG
            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
            if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
              {
               if(OrderStopLoss() < OrderOpenPrice())
                 {
                  if (OrderStopLoss() < Bid -(Point*(MinDist*2)))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid -(Point*(2*MinDist)),OrderTakeProfit(),0,Lime);
                    }
                 }
              }
            // SHORT
            OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
            if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
              {
               if(OrderStopLoss() > OrderOpenPrice())
                 {
                  if (OrderStopLoss() > Ask + (Point*(MinDist*2)))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Point*(MinDist*2)),OrderTakeProfit(),0,Lime);
                    }
                 }
              }
           }
        }
     }
   // If Orders are in force then check for closure against Technicals LONG & SHORT
   //CLOSE LONG Entries
   total=OrdersTotal();
   if(total>0)
     {
      for(cnt=0;cnt<total;cnt++)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
            //##   LONG Closure Rules   ###
           {
            if(0==1)
              {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close LONG position
               return(0);
              }
           }
         //CLOSE SHORT ENTRIES: 
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_SELL && OrderSymbol()==Symbol()) // check for symbol
            //##  SHORT Closure Rules  ##
           {
            if(0==1)               
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close SHORT position
               return(0);
              }
           }
        }  // for loop return
     }   // close 1st if 
   //TRAILING STOP: LONG
   total=OrdersTotal();
   if(total>0)
     {
      for(cnt=0;cnt<total;cnt++)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
           {
            if(TrailingStop>0)
              {
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,White);
                    }
                 }
              }
           }
        }
     }
   //TRAILING STOP: SHORT
   total=OrdersTotal();
   if(total>0)
     {
      for(cnt=0;cnt<total;cnt++)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
           {
            if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
              {
               if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                 {
                  OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,White);
                 }
              }
           }
        }
     }
   //#########################  NEW POSITIONS ?  ######################################
   //Possibly add in timer to stop multiple entries within Period
   // Check Margin available
   // ONLY ONE ORDER per SYMBOL
   // ADD in code to elimante spikes
   // Loop around orders to check symbol doesn't appear more than once
   // Check for elapsed time from last entry
   tmp= TimeHour(CurTime());
   // Print(" time ",tmp);
   if (0==1) // switch to turn ON/OFF history check
     {
      total=HistoryTotal();
      if(total>0)
        {
         for(cnt=0;cnt<total;cnt++)
           {
            OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY);
            if(OrderSymbol()==Symbol()
            && CurTime()- OrderCloseTime() < (Period() * 60 )
            )
              {
               return(0);
              }
           }
        }
     }
   total=OrdersTotal();
   if(total>0)
     {
      for(cnt=0;cnt<total;cnt++)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if(OrderSymbol()==Symbol()) return(0);
        }
     }
   if(AccountFreeMargin()<(1000*Lots))
     {Print("We have no money. Free Margin = ", AccountFreeMargin());
     return(0);}
   //ENTRY RULES: LONG 
   double MinDist=(MarketInfo(Symbol(),MODE_STOPLEVEL)*Point);
   double HighPrice, LowPrice;
   if(MinDist-(High[1] - Ask) > 0) HighPrice=High[1]+ (MinDist-(High[1] - Ask));
   if(MinDist-(High[1] - Ask) < 0) HighPrice=High[1];
   if(MinDist-(Bid -Low[1]) > 0) LowPrice=Low[1]+ (MinDist-(Bid -Low[1]));
   if(MinDist-(Bid -Low[1]) < 0) LowPrice=Low[1];
   //Print(SetHour," ",LowPrice," ",HighPrice);
   if (TimeHour(CurTime())==SetHour)
     {
      //Place BUY Stop order 
      ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,HighPrice+(1*Point),3,Low[1]-(30*Point),Ask+(TakeProfit*Point),"MaxMin Long",16384,0,Orange);
      if(ticket>0)
        {
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUYSTOP order opened : ",OrderOpenPrice());
        }
      else // Place  actual Order
        {
         Print("Error opening BUYSTOP order : ",GetLastError());
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Low[1]-(30*Point),Ask+(TakeProfit*Point),"MaxMin Long",16384,0,Yellow);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError());
        }
      ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,LowPrice-(1*Point),3,Ask+(30*Point),Bid-(TakeProfit*Point),"MaxMin Long",16384,0,Red);
      if(ticket>0)
        {
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELLSTOP order opened : ",OrderOpenPrice());
        }
      else
        {
         Print("Error opening SELLSTOP order : ",GetLastError());
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+(30*Point),Bid-(TakeProfit*Point),"MaxMin Long",16384,0,Pink);
//----
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError());
        }
      return(0);
     }
   return(0);
  }
//+------------------------------------------------------------------+

Profitability Reports

PERFORMANCE BY SYMBOL

Expected payoff

Average expected payoff across the available backtests for each symbol.

Positive Negative
16 reports
EUR/USD Jul 2025 - Sep 2025
243.08
Total Trades 124
Won Trades 84
Lost trades 40
Win Rate 67.74 %
Expected payoff 848.83
Gross Profit 105689.90
Gross Loss -434.80
Total Net Profit 105255.10
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
1.69
Total Trades 149
Won Trades 106
Lost trades 43
Win Rate 71.14 %
Expected payoff 1.53
Gross Profit 558.12
Gross Loss -330.61
Total Net Profit 227.51
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
1.19
Total Trades 122
Won Trades 82
Lost trades 40
Win Rate 67.21 %
Expected payoff 0.73
Gross Profit 562.37
Gross Loss -473.50
Total Net Profit 88.87
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.10
Total Trades 144
Won Trades 92
Lost trades 52
Win Rate 63.89 %
Expected payoff 0.39
Gross Profit 644.10
Gross Loss -587.60
Total Net Profit 56.50
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.91
Total Trades 126
Won Trades 80
Lost trades 46
Win Rate 63.49 %
Expected payoff -0.24
Gross Profit 299.23
Gross Loss -329.89
Total Net Profit -30.66
-100%
-50%
0%
50%
100%
EUR/USD Oct 2025 - Feb 2026
0.91
Total Trades 213
Won Trades 140
Lost trades 73
Win Rate 65.73 %
Expected payoff -0.30
Gross Profit 663.10
Gross Loss -728.00
Total Net Profit -64.90
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.87
Total Trades 131
Won Trades 78
Lost trades 53
Win Rate 59.54 %
Expected payoff -0.43
Gross Profit 376.10
Gross Loss -431.80
Total Net Profit -55.70
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.83
Total Trades 119
Won Trades 86
Lost trades 33
Win Rate 72.27 %
Expected payoff -0.53
Gross Profit 312.00
Gross Loss -374.70
Total Net Profit -62.70
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.63
Total Trades 122
Won Trades 71
Lost trades 51
Win Rate 58.20 %
Expected payoff -1.31
Gross Profit 268.00
Gross Loss -428.30
Total Net Profit -160.30
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2025 - Feb 2026
0.52
Total Trades 227
Won Trades 133
Lost trades 94
Win Rate 58.59 %
Expected payoff -2.28
Gross Profit 557.97
Gross Loss -1076.44
Total Net Profit -518.47
-100%
-50%
0%
50%
100%
GBP/AUD Oct 2025 - Feb 2026
0.51
Total Trades 241
Won Trades 145
Lost trades 96
Win Rate 60.17 %
Expected payoff -2.24
Gross Profit 565.75
Gross Loss -1104.95
Total Net Profit -539.20
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.48
Total Trades 129
Won Trades 78
Lost trades 51
Win Rate 60.47 %
Expected payoff -1.92
Gross Profit 231.54
Gross Loss -478.87
Total Net Profit -247.33
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.42
Total Trades 121
Won Trades 70
Lost trades 51
Win Rate 57.85 %
Expected payoff -3.00
Gross Profit 258.70
Gross Loss -622.20
Total Net Profit -363.50
-100%
-50%
0%
50%
100%
AUD/USD Oct 2025 - Feb 2026
0.40
Total Trades 204
Won Trades 103
Lost trades 101
Win Rate 50.49 %
Expected payoff -3.28
Gross Profit 437.60
Gross Loss -1106.00
Total Net Profit -668.40
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.13
Total Trades 146
Won Trades 59
Lost trades 87
Win Rate 40.41 %
Expected payoff -7.96
Gross Profit 167.97
Gross Loss -1330.16
Total Net Profit -1162.19
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.12
Total Trades 159
Won Trades 54
Lost trades 105
Win Rate 33.96 %
Expected payoff -9.94
Gross Profit 224.08
Gross Loss -1803.97
Total Net Profit -1579.89
-100%
-50%
0%
50%
100%

Comments