[ea]XRSI47_MT4_Ron_v03c

Download script
Author: George Toffolo - MT4 code by Ron Thompson
Profit factor:
0.27

This automated trading script is designed for "scalping"—a strategy focused on capturing small, rapid price movements in the forex market. It operates as a continuous "always-in" system, meaning it aims to have an active position open at all times by constantly switching between buying and selling based on momentum shifts.

Core Trading Logic

The script relies on a mathematical indicator called the Relative Strength Index (RSI). To determine market direction, it compares two different versions of this indicator simultaneously:

  1. Fast RSI: Reacts quickly to recent price changes.
  2. Slow RSI: Provides a smoother, longer-term view of the trend.

The logic is triggered by "crossovers." When the Fast RSI line crosses over the Slow RSI line, it signals a change in momentum:

  • Buy Signal: If the Fast RSI moves from below to above the Slow RSI, the system identifies an upward momentum shift.
  • Sell Signal: If the Fast RSI moves from above to below the Slow RSI, the system identifies a downward momentum shift.

Execution Strategy

The script follows a "Stop and Reverse" protocol:

  • Initial Entry: If there are no open positions, the script checks the current indicators. If it detects a "Rising" crossover, it opens a Buy trade. If it detects a "Falling" crossover, it opens a Sell trade.
  • Reversal: If you currently have an open Buy position and a "Falling" signal occurs, the script will automatically close the Buy and immediately open a Sell. Conversely, if you have a Sell open and a "Rising" signal occurs, it closes the Sell and opens a Buy.

Technical Safeguards

While the primary strategy is based on momentum shifts rather than fixed profit targets, the script includes built-in safety measures:

  • Failure Protection: Every trade is automatically equipped with a standard stop-loss and take-profit buffer. This ensures that if your internet connection drops or your computer loses power, the trade will still be closed automatically by the broker to prevent unlimited losses.
  • Margin Check: Before attempting to enter a trade, the script verifies that your account has sufficient funds to cover the required margin.

Summary for the User

This tool is designed for active trading environments (specifically suggested for 5-minute charts) where the goal is to stay in the market at all times, riding the waves of price momentum as the indicators cross paths. It removes the emotional difficulty of deciding when to "flip" a position by automating the exit of one trade and the entry of the opposite one instantly.

Price Data Components
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Relative strength index
10 Views
0 Downloads
0 Favorites
[ea]XRSI47_MT4_Ron_v03c
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------+
//|       XRSI N by N      |
//+------------------------+
//

/*
Theory of operation
-------------------
This is a scalping expert based on cross of RSISlow & RSIFast
This is a STOP/REVERSE system (which means always-in)


TIME FRAME
----------
5 MINUTES suggested but may support 15MIN with tweaks


SUGGESTED PAIRS
---------------
GBPUSD


ENTRY LONG
----------
RSIFast(Bar[2]) less than RSISlow(Bar[2]) and RSIFast(Bar[1]) greater than RSISlow(Bar[1])

(if RSIType=1, i.e. PRICE_OPEN, then)
RSIFast(Bar[1]) less than RSISlow(Bar[1]) and RSIFast(Bar[0]) greater than RSISlow(Bar[0])


ENTRY SHORT
-----------
RSIFast([2]) greater than RSISlow(Bar[2]) and RSIFast(bar[1]) less than RSISlow(Bar[1])

(if RSIType=1, i.e. PRICE_OPEN, then)
RSIFast(Bar[1]) greater than RSISlow(Bar[1]) and RSIFast(Bar[0]) less than RSISlow(Bar[0])


EXIT
----
Sell on cross and take opposite trade


MONEY MANAGEMENT
----------------
-none-


RISK MANAGEMENT
---------------
-none-


FAILURE PROTECTION
------------------
Orders are opened with stoploss and takeprofit of 50 
since it's unlikely to affect scalping, and is safe 
enough in case of power failure or the internet disruption


*/


#property copyright "George Toffolo - MT4 code by Ron Thompson"
#property link      "http://www.lightpatch.com/forex"


/*
For RSIType, use the following:
-------------------------------
PRICE_CLOSE 0 Close price. 
PRICE_OPEN 1 Open price. 
PRICE_HIGH 2 High price. 
PRICE_LOW 3 Low price. 
PRICE_MEDIAN 4 Median price, (high+low)/2. 
PRICE_TYPICAL 5 Typical price, (high+low+close)/3. 
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 
*/

// generic user input
extern double Lots=0.1;
extern int    Slippage=2;
extern int    Slow_RSI=14;
extern int    Fast_RSI=7;
extern int    Type_RSI=6;
extern bool   UseBar0=false;


// Bar handling
datetime bartime=0;
int      bartick=0;




//+------------------------------------+
//| EA load code                       |
//+------------------------------------+

int init()
  {
   Print("Init happened ",CurTime());
   Comment(" ");
  }


//+------------------------------------+
//| EA unload code                     |
//+------------------------------------+

int deinit()
  {
   Print("DE-Init happened ",CurTime());
   Comment(" ");
  }



//+------------------------------------+
//| EA main code                       |
//+------------------------------------+

int start()
  {
   double p=Point();
   int      cnt=0;
   int      gle=0;

   int      OrdersPerSymbol=0;

   double  pRSIFast=0,  RSIFast=0;
   double  pRSISlow=0,  RSISlow=0;
   bool    Rising=false, Falling=false;
   
   string TradeComment = "XRSI47";

   // Error checking & bar counting
   if(AccountFreeMargin()<(1000*Lots))        {Print("-----NO MONEY"); return(0);}
   if(Bars<100)                               {Print("-----NO BARS "); return(0);}

   // RSI and previous RSI for crossover
   if(UseBar0) 
     { 
      RSIFast=iRSI(Symbol(),0,Fast_RSI,Type_RSI,0);
      pRSIFast=iRSI(Symbol(),0,Fast_RSI,Type_RSI,1);
      RSISlow=iRSI(Symbol(),0,Slow_RSI,Type_RSI,0);
      pRSISlow=iRSI(Symbol(),0,Slow_RSI,Type_RSI,1);
     }
      else
     { 
      RSIFast=iRSI(Symbol(),0,Fast_RSI,Type_RSI,1);
      pRSIFast=iRSI(Symbol(),0,Fast_RSI,Type_RSI,2);
      RSISlow=iRSI(Symbol(),0,Slow_RSI,Type_RSI,1);
      pRSISlow=iRSI(Symbol(),0,Slow_RSI,Type_RSI,2);
     }

   // Determine if there was a cross
   if(pRSIFast<pRSISlow && RSIFast>RSISlow) {Rising=true;  Falling=false;}
   if(pRSIFast>pRSISlow && RSIFast<RSISlow) {Rising=false; Falling=true;}
   
   // count the open orders for this symbol 
   OrdersPerSymbol=0;
   for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if ( OrderSymbol() == Symbol())
        {
         OrdersPerSymbol++;
        }
     }
     
   // count the open orders for this symbol 
   OrdersPerSymbol=0;
   for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if ( OrderSymbol() == Symbol())
        {
         OrdersPerSymbol++;
        }
     }
     
   // Initial order placement
   if(OrdersPerSymbol==0)
     {
      Print("No Pending orders for ",Symbol()," Rising=",Rising," Falling=",Falling," bartick=",bartick);
     
      //ENTRY Ask(buy, long) 
      if(Rising)
		  {
		   Print("Placing initial BUY order on RISING indicator");
		   Print("pRSIFast=",pRSIFast," RSIFast=",RSIFast,"   pRSISlow=",pRSISlow," RSISlow=",RSISlow);
         OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-(50*p),Ask+(50*p),TradeComment,10101,White);
         gle=GetLastError();
         if(gle==0) {PrintAsk("BUY "); bartick=0;} else {PrintAskErr("BUY ",gle);}
        }
        
      //ENTRY Bid (sell, short)
      if(Falling)
        {
		   Print("Placing initial SELL order on FALLING indicator");
		   Print("pRSIFast=",pRSIFast," RSIFast=",RSIFast,"   pRSISlow=",pRSISlow," RSISlow=",RSISlow);
         OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+(50*p),Bid-(50*p),TradeComment,10101,Red);
         gle=GetLastError();
         if(gle==0) {PrintBid("SELL"); bartick=0;} else {PrintBidErr("SELL",gle);}
        }
     } //if


   // Existing order, determine if direction changed
   for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if ( OrderSymbol()==Symbol())
        {

         // RSI crossed down, so swap BUY for SELL
         if (OrderType() == OP_BUY && Falling)
           {
            OrderClose(OrderTicket(),Lots,Bid,Slippage,White);
            gle=GetLastError();
            if(gle==0) {PrintBid("CLOSE BUY "); bartick=0;} else {PrintBidErr("CLOSE BUY ",gle);}
            OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+(50*p),Bid-(50*p),TradeComment,10101,Red);
            gle=GetLastError();
            if(gle==0) {PrintBid("SELL"); bartick=0;} else {PrintBidErr("SELL",gle);}
           } // if BUY


         // RSI crossed up, so swap SELL for BUY
         if (OrderType() == OP_SELL && Rising)
           {
            OrderClose(OrderTicket(),Lots,Ask,Slippage,Red);
            gle=GetLastError();
            if(gle==0) {PrintAsk("CLOSE SELL");} else {PrintAskErr("CLOSE SELL",gle);}
            OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-(50*p),Ask+(50*p),TradeComment,10101,White);
            gle=GetLastError();
            if(gle==0) {PrintAsk("BUY "); bartick=0;} else {PrintAskErr("BUY ",gle);}
           } //if SELL

        }//if OrderSymbol...
     }//for


   return(0);
  } // start()


void PrintAsk(string msg)
  {
   Print(msg," ",Symbol(),"Ask=",Ask," Ticks=",bartick," ",CurTime());
  }

void PrintAskErr(string msg, int gle)
  {
   Print(msg," ",Symbol()," Err=",gle," Order -------FAILED-------  ",Ask," Ticks=",bartick," ",CurTime());
  }

void PrintBid(string msg)
  {
   Print(msg," ",Symbol(),"Ask=",Ask," Ticks=",bartick," ",CurTime());
  }

void PrintBidErr(string msg, int gle)
  {
   Print(msg," ",Symbol(),"Ask=",Ask," Ticks=",bartick," ",CurTime());
  }


Profitability Reports

PERFORMANCE BY SYMBOL

Expected payoff

Average expected payoff across the available backtests for each symbol.

Positive Negative
4 reports
USD/CAD Oct 2024 - Jan 2025
0.49
Total Trades 1239
Won Trades 405
Lost trades 834
Win Rate 32.69 %
Expected payoff -1.19
Gross Profit 1398.61
Gross Loss -2876.66
Total Net Profit -1478.05
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.26
Total Trades 1207
Won Trades 246
Lost trades 961
Win Rate 20.38 %
Expected payoff -2.84
Gross Profit 1197.90
Gross Loss -4625.10
Total Net Profit -3427.20
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2024 - Jan 2025
0.16
Total Trades 3815
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -2.58
Gross Profit 1939.61
Gross Loss -11780.09
Total Net Profit -9840.48
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.15
Total Trades 2697
Won Trades 353
Lost trades 2344
Win Rate 13.09 %
Expected payoff -3.67
Gross Profit 1738.40
Gross Loss -11642.10
Total Net Profit -9903.70
-100%
-50%
0%
50%
100%

Comments