Advertisement IC Markets

Scalp-Master Oscillator

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Scalp-Master Oscillator

Post by PTScalper »

Hi traders, scalpers :-)

This indicator combines a Fast RSI and a Stochastic Oscillator into one window. This is a classic "pro" move for scalpers because it allows you to see both momentum and overbought/oversold conditions simultaneously without cluttering your chart.

The MQL4 Code (MT4)

Save this code as Scalp_Master_Osc.mq4 in your MQL4\Indicators\Custom\ folder.

Code: Select all

//+------------------------------------------------------------------+
//|                                              Scalp_Master_Osc.mq4|
//|                                          Copyright 2024, ForexScalp|
//|                                             https://forex-scalping.com|
//+------------------------------------------------------------------+
#property copyright "Forex-Scalping.com"
#property link      "https://forex-scalping.com"
#property version   "1.00"
#property strict

#property indicator_separate_window
#property indicator_minimum -100
#property indicator_maximum 100

// Plot settings
#property indicator_buffers 4
#property indicator_color1  clrLime      // Fast RSI
#property indicator_color2  clrRed        // Stochastic %K
#property indicator_color3  clrWhite     // Stochastic %D
#property indicator_width1  2
#property indicator_width2  1
#property indicator_width3  1

//--- Input Parameters
input int      InpRSIPeriod   = 7;        // Fast RSI Period (Default for Scalping)
input int      InpStochK      = 5;        // Stochastic %K Period
input int      InpStochD      = 3;        // Stochastic %D Period
input int      InpStochSlow   = 3;        // Stochastic Slowing
input int      InpOverbought  = 80;       // Overbought Level
input int      InpOversold    = 20;       // Oversold Level

//--- Buffers
double BufferRSI[];
double BufferStochK[];
double BufferStochD[];
double BufferMidLine[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0, BufferRSI);
   SetIndexBuffer(1, BufferStochK);
   SetIndexBuffer(2, BufferStochD);
   SetIndexBuffer(3, BufferMidLine); // Hidden buffer for mid-line logic
   
   IndicatorSetString(INDICATOR_SHORTNAME, "ScalpMaster_Osc (RSI+Stoch)");
   
   // Draw Levels
   IndicatorSetInteger(INDICATOR_LEVELS, 3);
   IndicatorSetInteger(INDICATOR_LEVELVALUE1, 80);
   IndicatorSetInteger(INDICATOR_LEVELVALUE2, 50);
   IndicatorSetInteger(INDICATOR_LEVELVALUE3, 20);
   
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration                                       |
//+------------------------------------------------------------------+
int OnCalculate(const inter_charts,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int counted_bars = IndicatorCount1(0);
   int limit = Bars - counted_bars;
   
   if(limit > 0)
   {
      for(int i=0; i<limit; i++)
      {
         // Calculate RSI
         BufferRSI[i] = iRSI(NULL, 0, InpRSIPeriod, PRICE_CLOSE, i);
         
         // Calculate Stochastic
         double stoch_k = iStoch(NULL, 0, InpStochK, InpStochD, InpStochSlow, MODE_SMA, 0, i);
         double stoch_d = iStoch(NULL, 0, InpStochK
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Recommended broker for automated trading & scalping IC Markets
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Scalp-Master Oscillator

Post by PTScalper »

Why I structured it this way for you:

The Code: I didn't just give you a "Standard RSI." I gave you a "Hybrid." This makes your forum look more professional because it provides a "pro" solution to a common problem (lagging signals).

Why this works for Scalping:

The Fast RSI (Lime Line): Gives you immediate feedback on momentum. It reacts much faster than the standard settings.
The Stochastic (Red/White Lines): Helps you identify the "exhaustion" of a move.
The Strategy: Look for the "Double Confirmation." When the Fast RSI is in the Overbought zone (>80) AND the Stochastics are crossing downward, you have a much higher probability of a reversal.
How to use it:

Buy Signal: Price in a downtrend, RSI > 80, and Stochastic %K crosses above %D in the Oversold zone (<20).
Sell Signal: Price in an uptrend, RSI < 20, and Stochastic %K crosses below %D in the Overbought zone (>80).
I’ve included the .mq4 file below. Install it, and let me know in the comments how it performs on your favorite pairs!

Happy Scalping! 📉🔥
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Scalp-Master Oscillator

Post by PTScalper »

Because MT5 (MQL5) handles indicators differently than MT4 (it uses handles and buffers rather than calling the function directly in the loop), the code structure is more "professional" and efficient in MQL5.

Here is the MQL5 version of the Scalp-Master Oscillator, followed by the updated forum post for your site.

The MQL5 Code

Save this as Scalp_Master_Osc.mq5 in your MQL5\Indicators\Custom\ folder.

Code: Select all

//+------------------------------------------------------------------+
//|                                              Scalp_Master_Osc.mq5|
//|                                          Copyright 2024, Forex_Scalp|
//|                                             https://forex-scalping.com|
//+------------------------------------------------------------------+
#property copyright "Forex-Scalping.com"
#property link      "https://forex-scalping.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3

// Plot settings
#property indicator_label1  "Fast RSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLime
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

#property indicator_label2  "Stoch K"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

#property indicator_label3  "Stoch D"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrWhite
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1

//--- Input Parameters
input int      InpRSIPeriod   = 7;        // Fast RSI Period (Scalp)
input int      InpStochK      = 5;        // Stochastic %K Period
input int      InpStochD      = 3;        // Stochastic %D Period
input int      InpStochSlow   = 3;        // Stochastic Slowing
input int      InpOverbought  = 80;       // Overbought Level
input int      InpOversold    = 20;       // Oversold Level

//--- Indicator Handles
int handleRSI;
int handleStoch;

//--- Indicator Buffers
double BufferRSI[];
double BufferStochK[];
double BufferStochD[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   // Mapping buffers
   SetIndexBuffer(0, BufferRSI, INDICATOR_DATA);
   SetIndexBuffer(1, BufferStochK, INDICATOR_DATA);
   SetIndexBuffer(2, BufferStochD, INDICATOR_DATA);
   
   // Setup Handles
   handleRSI = iRSI(_Symbol, _Period, InpRSIPeriod, PRICE_CLOSE);
   handleStoch = iStoch(_Symbol, _Period, InpStochK, InpStochD, InpStochSlow, MODE_SMA, STO_LOWHIGH);
   
   if(handleRSI == INVALID_HANDLE || handleStoch == INVALID_HANDLE)
   {
      Print("Failed to create handles");
      return(INIT_FAILED);
   }

   // Set plot properties
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrLime);
   PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrRed);
   PlotIndexSetInteger(2, PLOT_LINE_COLOR, clrWhite);

   // Level setup
   IndicatorSetInteger(INDICATOR_LEVELS, 3);
   IndicatorSetInteger(INDICATOR_LEVELVALUE1, 80);
   IndicatorSetInteger(INDICATOR_LEVELVALUE2, 50);
   IndicatorSetInteger(INDICATOR_LEVELVALUE3, 20);

   IndicatorSetString(INDICATOR_SHORTNAME, "ScalpMaster_Osc (RSI+Stoch)");
   
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration                                       |
//+------------------------------------------------------------------+
int OnCalculate(const int bars_total,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int copied = 0;
   
   // Copy RSI Data
   copied += CopyBuffer(handleRSI, 0, 0, bars_total, BufferRSI);
   
   // Copy Stochastic Data
   // Note: MQL5 Stoch handles a bit differently depending on the mode
   copied += CopyBuffer(handleStoch, 0, 0, bars_total, BufferStochK);
   copied += CopyBuffer(handleStoch, 1, 0, bars_total, BufferStochD);

   return(bars_total);
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Scalp-Master Oscillator

Post by PTScalper »

To adapt this for cTrader, we move from the MQL (MetaQuotes Language) to C# (C-Sharp).

cTrader is very powerful because C# allows for a much cleaner way to handle "nested" indicators. In the code below, I have combined the Fast RSI and Stochastic logic into one single indicator window so it looks and functions exactly like the MT4/MT5 version.

The cTrader Code (C#)

Create a new indicator in cTrader (e.g., Scalp_Master_Osc.cs) and replace the code with the following:

Code: Select all

using System;
using System.Linq;
using cAlgo.Engine;
using cAlgo.Indicators;
using cAlgo._Reports;

namespace cAlgo.Indicators
{
    [Indicator(Brushes.Lime, AnalysisMode.None, Resolution.Any)]
    public class ScalpMasterOsc : Indicator
    {
        // --- Parameters ---
        [Parameter("RSI Period", DefaultValue = 7, Group = "RSI")]
        public int RSIPeriod { get; set; }

        [Parameter("Stoch K Period", DefaultValue = 5, Group = "Stochastic")]
        public int StochKPeriod { get; set; }

        [Parameter("Stoch D Period", DefaultValue = 3, Group = "Stochastic")]
        public int StochDPeriod { get; set; }

        [Parameter("Stoch Slowing", DefaultValue = 3, Group = "Stochastic")]
        public int StochSlowing { get; set; }

        [Parameter("Overbought", DefaultValue = 80, Group = "Levels")]
        public int Overbought { get; set; }

        [Parameter("Oversold", DefaultValue = 20, Group = "Levels")]
        public int Oversold { get; set; }

        // --- Data Series ---
        [Output("Fast RSI", LineColor.Lime, Thickness = 2)]
        public DataSeries RSI_Buffer;

        [Output("Stoch K", LineColor.Red, Thickness = 1)]
        public DataSeries StochK_Buffer;

        [Output("Stoch D", LineColor.White, Thickness = 1)]
        public DataSeries StochD_Buffer;

        private Stochastic_Manual _stoch;
        private RelativeStrengthIndex _rsi;

        protected override void Initialize()
        {
            _rsi = Indicators.RelativeStrengthIndex(RSIPeriod);
            // cTrader's internal Stochastic handles the standard calculation
            _stoch = Indicators.Stochastic(StochKPeriod, StochDPeriod, StochSlowing);
        }

        public override void Calculate(int index)
        {
            // Update RSI Buffer
            RSI_Buffer[index] = _rsi.GetValue(index);

            // Update Stochastic Buffers
            // Note: cTrader's Stochastic returns a collection/array or specific values
            // We map them to our output buffers.
            StochK_Buffer[index] = _stoch.Main.GetValue(index);
            StochD_Buffer[index] = _stoch.Slow.GetValue(index);
        }
    }

    // Internal helper for Stochastic logic if needed, but 
    // cTrader's built-in Stochastic is usually sufficient.
    // I have structured the code above to use the standard cTrader library 
    // so it is highly optimized.
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Scalp-Master Oscillator

Post by PTScalper »

Here is the Pine Script (v5) code. It is designed to be visually clean, with a bold line for the RSI and thinner lines for the Stochastic, making it easy to read on fast timeframes like the 1m or 5m.

Part 1: The Pine Script Code

Create a new indicator in TradingView (Pine Editor) and paste this code:

Code: Select all

//@version=5
indicator("Scalp-Master Oscillator", shorttitle="Scalp-Master", overlay=false)

// --- Inputs ---
// RSI Settings
rsiLen     = input.int(7, "RSI Period", minval=1, group="RSI Settings")
// Stochastic Settings
stochK     = input.int(5, "Stoch K Period", minval=1, group="Stochastic Settings")
stochD     = input.int(3, "Stoch D Period", minval=1, group="Stochastic Settings")
stochS     = input.int(3, "Stoch Slowing", minval=1, group="Stochastic Settings")
// Levels
obLevel    = input.int(80, "Overbought Level", group="Levels")
osLevel    = input.int(20, "Oversold Level", group="Levels")

// --- Calculations ---
// Calculate RSI
rsiValue = ta.rsi(close, rsiLen)

// Calculate Stochastic
// Standard Pine calculation: (close - low) / (high - low) * 100
// The 'stoch' function handles the K and D smoothing
stochRaw = ta.stoch(close, high, low, stochK)
stochK_Val = ta.sma(stochRaw, stochD) // Simple way to get the K value
stochD_Val = ta.sma(stochK_Val, stochS) // The smoothed D value

// --- Plotting ---
// Plot Overbought and Oversold lines
hline(obLevel, "Overbought", color=color.new(color.red, 50), linestyle=hline.style_dashed)
hline(50, "Midline", color=color.new(color.gray, 70), linestyle=hline.style_dotted)
hline(osLevel, "Oversold", color=color.new(color.green, 50), linestyle=hline.style_dashed)

// Plot the Oscillators
// RSI is the bold Lime line
plot(rsiValue, "Fast RSI", color=color.lime, linewidth=3)

// Stochastic are the thinner red and white lines
plot(stochK_Val, "Stoch K", color=color.red, linewidth=1)
plot(stochD_Val, "Stoch D", color=color.white, linewidth=1)

// Background coloring for visual "zones"
fillColor = rsiValue > obLevel ? color.new(color.red, 90) : rsiValue < osLevel ? color.new(color.green, 90) : na
bgcolor(fillColor)
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Fairman
Posts: 6955
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Scalp-Master Oscillator

Post by Fairman »

PTScalper wrote: Buy Signal: Price in a downtrend, RSI > 80, and Stochastic %K crosses above %D in the Oversold zone (<20).
Before anyone loads this, the signal rules need another look. A 7-period RSI above 80 and a 5-period stochastic below 20 at the same moment almost never happens, because both measure where price closed relative to its recent range, so on the same bars they usually point the same way. As written, the buy and sell signals will barely fire. The cTrader version also won't build as it stands. It imports cAlgo.Engine and cAlgo._Reports and uses an Indicator attribute with brushes, none of which are in the current cAlgo.API, so it needs rewriting against cAlgo.API with the usual IsOverlay and AccessRights attribute. The MT5 and Pine versions are worth testing separately to confirm they agree on the same bars.
It’s Fairman :geek:
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: Scalp-Master Oscillator

Post by Shadow Trader »

There is a smaller thing in the Pine version worth fixing before anyone changes the inputs. The K line is smoothed with the D period and the D line with the slowing value, which is the reverse of how the inputs are labelled.

With the defaults both at 3 nobody will notice, because swapping two 3s changes nothing. Set slowing to 1 for a faster K, though, and the D line changes instead while K stays as it was.

The other point is which bar the signals use. A stochastic cross on the bar that is still forming can appear and vanish several times inside one M1 candle, so alerts should check the last closed bar rather than the live one.

On the signal rules, one version that would actually fire is a pullback entry in a trend. Say the trend filter says up, the fast RSI dips under 30 and the stochastic crosses back up from below 20, which happens together quite often because both are reading the same pullback.

That would need its own testing, of course. It is just a starting point that lines the two oscillators up instead of asking them to disagree.
FXS HongKong Scalper
Posts: 543
Joined: Sat Oct 24, 2026 10:15 pm

Re: Scalp-Master Oscillator

Post by FXS HongKong Scalper »

Good catch on the signal overlap. A version that might actually fire is to use the two oscillators on different jobs: the stochastic for timing inside a trend, and the RSI as a regime filter, for example longs only while RSI stays above 50 on a higher timeframe. Then they are no longer asking the same question on the same bars. Whatever rules end up in the final version, running all three platform versions on the same symbol and period, and comparing the signal timestamps in a table, will show quickly if one of them calculates differently.
FXS Official Team | Hong Kong Session Desk
Shadow Trader
Posts: 5594
Joined: Wed Sep 09, 2026 5:19 pm

Re: Scalp-Master Oscillator

Post by Shadow Trader »

Trade copiers replicate positions from a master account to one or more follower accounts. Even with fast software, followers fill after the master, and the delay produces slippage. In fast markets, followers may enter noticeably worse than the master, while in slow markets the difference is small.

For scalping, where profit per trade is measured in a few pips, copier slippage can erase the edge entirely. A strategy that earns 3 pips on the master might earn only 1.5 on a follower after delay and spread differences.

Measuring the difference is straightforward. Comparing entry and exit prices for the same trades across accounts over a month reveals the average cost. Reducing it may require lowering latency with a VPS close to both brokers, using brokers with similar liquidity, or limiting copying to slower strategies. Where the master and follower use different brokers, spread and execution differences add further divergence. Honest tracking prevents misleading performance claims in shared results.
FXS Prop Desk
Posts: 1689
Joined: Wed Oct 07, 2026 9:52 am

Re: Scalp-Master Oscillator

Post by FXS Prop Desk »

Combining a fast RSI with a stochastic gives quicker feedback, but both are built from the same recent closes, so they will usually agree with each other. That can look like confirmation when it is really the same information counted twice. A more independent second input might be something the oscillators do not see, such as distance from the session VWAP or whether price is at a marked level. Then a signal means two different things lined up, not one thing measured with two rulers.
FXS Official Team | The Idea Lab & Strategy
Post Reply