SupportResistTrader[MODIFIED]

Author: Copyright � 2008, Gryb Alexander
Profit factor:
3.55

This script is designed to automate trading based on support and resistance levels in the market, while also considering the overall trend. Here's a breakdown of what it does:

  1. Setup:

    • When the script starts, it creates visual aids on the chart:
      • A blue line represents the "support" level, which is generally a price level where the price tends to stop falling.
      • A red line represents the "resistance" level, which is generally a price level where the price tends to stop rising.
      • A label on the chart displays whether the script believes the market trend is "bullish" (generally rising) or "bearish" (generally falling).
  2. Market Analysis:

    • The script continuously analyzes the market to determine the support and resistance levels. It looks at the lowest and highest prices over a certain number of past time periods (defined by the 'numBars' setting). The lowest price found becomes the support level, and the highest price becomes the resistance level.
    • It also determines the overall market trend. It does this by comparing the current market opening price to a moving average (a way of smoothing out price fluctuations over time, using the 'maPeriod' setting). If the opening price is above the moving average, the trend is considered "bullish"; otherwise, it's "bearish".
  3. Opening Trades:

    • If there are no open trades, the script checks whether it should open a new trade based on the analyzed support/resistance levels and the trend:
      • Bullish Trend: If the script believes the market is in a bullish trend and the current market asking price (the price you'd pay to buy) is above the resistance level, it opens a "buy" order, anticipating the price will continue to rise.
      • Bearish Trend: If the script believes the market is in a bearish trend and the current market bidding price (the price you'd get to sell) is below the support level, it opens a "sell" order, anticipating the price will continue to fall.
    • The script uses a pre-defined lot size ('Lots' setting) for its trades.
  4. Closing Trades:

    • If there are open trades, the script checks if they should be closed:
      • If a profitable "buy" order is open, it closes the order if the current bidding price falls below the support level.
      • If a profitable "sell" order is open, it closes the order if the current asking price rises above the resistance level.
  5. Trailing Stop Loss:

    • The script also implements a "trailing stop" mechanism to protect profits and limit losses. This adjusts the stop-loss order (an order to automatically close the trade if the price moves against you) as the price moves favorably:
      • Buy Order: If the market price rises a certain distance above the opening price of a buy order (defined by the 'TrailingStop' setting), the stop-loss order is moved up to a new level that locks in some profit. The stop-loss will only move up, never down, to ensure any gains are protected.
      • Sell Order: If the market price falls a certain distance below the opening price of a sell order (defined by the 'TrailingStop' setting), the stop-loss order is moved down to a new level that locks in some profit. The stop-loss will only move down, never up, to ensure any gains are protected.

In essence, the script tries to automatically buy when the price breaks above resistance during an uptrend and sell when the price breaks below support during a downtrend, aiming to profit from these movements while using stop-loss orders to manage risk.

Price Data Components
Series array that contains the lowest prices of each barSeries array that contains the highest prices of each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Indicators Used
Moving average indicator
9 Views
1 Downloads
0 Favorites
SupportResistTrader[MODIFIED]

//+------------------------------------------------------------------+
//|                                           SupportResistTrade.mq4 |
//|                                 Copyright © 2008, Gryb Alexander |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Gryb Alexander"
#property link      ""
 
extern int numBars  = 55;
extern int maPeriod = 500;
extern int Lots     = 1;
extern double   TrailingStop = 50;
 
 
double support;
double resist;
string trendType;
int timeFrame = 1;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
    ObjectCreate("lineSupport",OBJ_HLINE,0,0,0);
    ObjectSet("lineSupport",OBJPROP_COLOR,Blue);
    
    ObjectCreate("lineResist",OBJ_HLINE,0,0,0);
    ObjectSet("lineResist",OBJPROP_COLOR,Red);
    
    ObjectCreate("lblTrendType",OBJ_LABEL,0,0,0,0,0);
    ObjectSet("lblTrendType",OBJPROP_XDISTANCE,50);
    ObjectSet("lblTrendType",OBJPROP_YDISTANCE,50);
    ObjectSetText("lblTrendType","TrendType",14,"Tahoma",Red);
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    ObjectsDeleteAll();
    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
  MarketAnalize();
  if(OrdersTotal()==0)
   CheckForOpen();
  else
   CheckForClose();
//----
   return(0);
  }
 
void MarketAnalize()
{
  // ---------------------------------------
  support = 10000;
  resist = 0;  
  for(int k = 1;k<=numBars;k++)
  {
   if(support>iLow(Symbol(),timeFrame,k))
     support = iLow(Symbol(),timeFrame,k);
   if(resist<iHigh(Symbol(),timeFrame,k))
     resist = iHigh(Symbol(),timeFrame,k);
  }   
  ObjectSet("lineSupport",OBJPROP_PRICE1,support);
  ObjectSet("lineResist",OBJPROP_PRICE1,resist);
  
  //-----------------------------------------------------------
  double ma = iMA(Symbol(),0,maPeriod,0,MODE_EMA,PRICE_OPEN,0);
  
  if(Open[0]>ma)
  {
    trendType = "bullish";
  }
  if(Open[0]<ma)
  {
    trendType = "bearish";
  }
  ObjectSetText("lblTrendType",trendType);
}
 
void CheckForOpen()
{
 
  if(trendType=="bullish")
  {
    if(Ask>resist) OrderSend(Symbol(),OP_BUY,Lots,Ask,3,support,0,"Support & Resistance trader",0,0,Green);
  }
  if(trendType=="bearish")
  {
    if(Bid<support)  OrderSend(Symbol(),OP_SELL,Lots,Bid,3,resist,0,"Support & Resistance trader",0,0,Red);
  }
}
void CheckForClose()
{
 OrderSelect(0,SELECT_BY_POS);
 if(OrderProfit()>0)
 {
   if(OrderType()==OP_BUY)
   {
     if(Bid<support) OrderClose(OrderTicket(),OrderLots(),Bid,3);
   }
   if(OrderType()==OP_SELL)
   { 
      if(Ask>resist)  OrderClose(OrderTicket(),OrderLots(),Ask,3);
   }
 }
//Trailing
 if(OrderType()==OP_BUY)
 {
    if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
  }
  // if((Ask>OrderOpenPrice()+Point*20)&&(OrderStopLoss()<(OrderOpenPrice()+Point*10)))
  //  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*10,OrderTakeProfit(),0,Blue);
  // if((Ask>OrderOpenPrice()+Point*40)&&(OrderStopLoss()<(OrderOpenPrice()+Point*20)))
  //  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*20,OrderTakeProfit(),0,Blue);    
  // if((Ask>OrderOpenPrice()+Point*60)&&(OrderStopLoss()<(OrderOpenPrice()+Point*30)))
  //  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point*30,OrderTakeProfit(),0,Blue);
 // }
 if(OrderType()==OP_SELL)
 {
    if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
  // if((Bid<OrderOpenPrice()-Point*20)&&(OrderStopLoss()>(OrderOpenPrice()-Point*10)))
  //  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*10,OrderTakeProfit(),0,Blue);     
 //  if((Bid<OrderOpenPrice()-Point*40)&&(OrderStopLoss()>(OrderOpenPrice()-Point*20)))
 //   OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*20,OrderTakeProfit(),0,Blue);     
 //  if((Bid<OrderOpenPrice()-Point*60)&&(OrderStopLoss()>(OrderOpenPrice()-Point*30)))
 //   OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*30,OrderTakeProfit(),0,Blue);     
 
 }
 }
 

Profitability Reports

USD/JPY Jul 2025 - Sep 2025
0.45
Total Trades 57
Won Trades 47
Lost trades 10
Win Rate 82.46 %
Expected payoff -66.44
Gross Profit 3093.08
Gross Loss -6880.16
Total Net Profit -3787.08
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.53
Total Trades 51
Won Trades 37
Lost trades 14
Win Rate 72.55 %
Expected payoff -57.89
Gross Profit 3272.32
Gross Loss -6224.60
Total Net Profit -2952.28
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.69
Total Trades 98
Won Trades 77
Lost trades 21
Win Rate 78.57 %
Expected payoff -14.59
Gross Profit 3230.58
Gross Loss -4660.46
Total Net Profit -1429.88
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
1.27
Total Trades 53
Won Trades 44
Lost trades 9
Win Rate 83.02 %
Expected payoff 8.11
Gross Profit 2017.00
Gross Loss -1587.00
Total Net Profit 430.00
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.95
Total Trades 59
Won Trades 55
Lost trades 4
Win Rate 93.22 %
Expected payoff -3.64
Gross Profit 4285.00
Gross Loss -4500.00
Total Net Profit -215.00
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.42
Total Trades 258
Won Trades 159
Lost trades 99
Win Rate 61.63 %
Expected payoff -37.39
Gross Profit 6889.80
Gross Loss -16535.21
Total Net Profit -9645.41
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
46.22
Total Trades 179
Won Trades 117
Lost trades 62
Win Rate 65.36 %
Expected payoff 5818.72
Gross Profit 1064585.00
Gross Loss -23035.00
Total Net Profit 1041550.00
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.57
Total Trades 96
Won Trades 83
Lost trades 13
Win Rate 86.46 %
Expected payoff -35.22
Gross Profit 4480.00
Gross Loss -7861.00
Total Net Profit -3381.00
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.74
Total Trades 987
Won Trades 769
Lost trades 218
Win Rate 77.91 %
Expected payoff -9.88
Gross Profit 27293.39
Gross Loss -37044.35
Total Net Profit -9750.96
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.48
Total Trades 338
Won Trades 166
Lost trades 172
Win Rate 49.11 %
Expected payoff -28.11
Gross Profit 8718.14
Gross Loss -18218.37
Total Net Profit -9500.23
-100%
-50%
0%
50%
100%

Comments