Bollinger Bands + RSI + STOCH High Win Rate %99 Indicator

 
Hello,

I'm coding a strategy based on 3 indicators Bollinger, RSI and STOCH! The win rate can be %99! The strategy is simple but effective! Since I'm newbie in MQL4 language, please help to code this and then we can use its signal all together :)

The Logic is like this:

When the candles touch lower bands and RSI above 30 and Stoch cross above 30, we will Buy!

When the candles touch Upper bands and RSI below 70 and Stoch cross above 70, we will Sell!


I'm trying to code an indicator to generate signals when the conditions meet :) Please help to correct my code!


//+------------------------------------------------------------------+
//|                                                BBRSI Signals.mq4 |
//|                        Copyright 2022, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2

double R;//RSI
double BBUP;//Upper Bands
double BBLOW;//Lowe Bands
double buffer1[]; 
double buffer2[];

double m_2,m_1,s_1,s_2;//Stoch
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer (0,buffer1);
   SetIndexStyle (0,DRAW_ARROW,EMPTY,3,clrBlue);
   SetIndexArrow (0,233);
   
         
   SetIndexBuffer (1,buffer2);
   SetIndexStyle (1,DRAW_ARROW,EMPTY,3,clrRed);
   SetIndexArrow (1,234);
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                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[])
  {
  
//---
for(int i=1;i<3000;i++)
   {
    arrow(i);
     
    if(  Open[1] < BBLOW && BBLOW > Close[1] && Low[1]>BBLOW && R>30 && m_2 < s_2 && m_1 > s_1)
      {
       buffer1[i]= Low[i];
      }
        
    if(   Open[1] > BBUP && BBUP > Close[1] && Low[1]>BBUP && R<70 &&  m_2 > s_2 && m_1 < s_1)
      {
       buffer2[i]= Low[i]; 
      }
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+\
   void arrow ( int i ) 
         {    
    R = iRSI(NULL,0,14,PRICE_CLOSE,i);
        
    BBUP = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,i);        
    BBLOW = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,+i);
    
             
    m_1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,i);    
    s_1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,i);  
    
    m_2 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,i+1);    
    s_2 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,i+1);    

  } 
  
  




Thank you :)
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2022.05.22
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Files:
 

Mistakes corrected

Open[1]  refers to bar 1 only and should be [i]  to be indexed.

BBLOW= had a + sign that wasn't being used. 

indicator was recalculating every tick for a closed bar signal.

Files:
 
Sure, the 99 of winratio with a strategy that even my grandfather knows. Sure.
 
forextastic #:
Sure, the 99 of winratio with a strategy that even my grandfather knows. Sure.

99% winratio with 3 pips of TP and 30000 pips of SL :-D

 
Fabio Cavalloni #:

99% winratio with 3 pips of TP and 30000 pips of SL :-D

Add the grid and martingale, it's the special sauce for the strategy! 

 
maximo #:

Mistakes corrected

Open[1]  refers to bar 1 only and should be [i]  to be indexed.

BBLOW= had a + sign that wasn't being used. 

indicator was recalculating every tick for a closed bar signal.

Thank you so much for helping! I need to write extra code to make it generate better signals and I'll share it here :)

 
Fabio Cavalloni #:

99% winratio with 3 pips of TP and 30000 pips of SL :-D

There are a few things you need to cover first before you can implement such a strategy. 

Spread: are you sure targets will get hit with a high spread? Some sessions have volatile spreads hence it wouldn’t make any sense to implement a strategy with a 3000 point stop loss. 

Time: are you considering what days and times are you trading ? These you must consider because once again you can be entering at a high spread and get wiped with just 1 trade.

Frequency of trades: another factor. Bollinger and rsi is a good combination but settings and how many times you trade per week or per month will drastically measure you performance. 

Backtesting quality: you can’t just backtest one year of your own brokers information because of inaccuracies. There are ways to get 99% modelling quality with 20+ years of backtesting. 

This strategy is destined to blow your account. You need to optimise the strategy in a way where it is realistic. Not every condition should be an entry. 

Factors to also include:
Average volatility. 
Average price range. 
Economic events. 
 
Adj007 #:
There are a few things you need to cover first before you can implement such a strategy. 

Spread: are you sure targets will get hit with a high spread? Some sessions have volatile spreads hence it wouldn’t make any sense to implement a strategy with a 3000 point stop loss. 

Time: are you considering what days and times are you trading ? These you must consider because once again you can be entering at a high spread and get wiped with just 1 trade.

Frequency of trades: another factor. Bollinger and rsi is a good combination but settings and how many times you trade per week or per month will drastically measure you performance. 

Backtesting quality: you can’t just backtest one year of your own brokers information because of inaccuracies. There are ways to get 99% modelling quality with 20+ years of backtesting. 

This strategy is destined to blow your account. You need to optimise the strategy in a way where it is realistic. Not every condition should be an entry. 

Factors to also include:
Average volatility. 
Average price range. 
Economic events. 

I totally agree with all your wrote.

My message was ironical, joking about people who talk about "winratio" that in trading is totally meaningless! They should probably go to a casino instead of doing trading.
 
forextastic #:

Add the grid and martingale, it's the special sauce for the strategy! 

hahahahah ..... exactly

 
maximo #:

Mistakes corrected

Open[1]  refers to bar 1 only and should be [i]  to be indexed.

BBLOW= had a + sign that wasn't being used. 

indicator was recalculating every tick for a closed bar signal.

Thanks for your helping again!

I wrote some codes and added a new rule :) Please check it if it is correct!

The rule: If candles goes out of the bands for 100 points, it will show Buy or Sell arrows.

Thanks

for(int i=1; i<inpBarsToCalculate; i++)

   {

      arrow(i);

  

      if( Open[i+1]>BBUP && Low[i+1]<BBUP  && Close[i] < BBUP &&(Close[i]>BBUP+100*Point())) 

      if(!UseRsi || RSI<70)

      if(!UseStochastic || (m_2 > s_2 && m_1 < s_1))

      {

         buffer2[i]= High[i]+20*_Point; //red down arrow

      }

      

      if( Open[i+1]<BBLOW && High[i+1]>BBLOW && Close[i] > BBLOW && (Close[i]>BBLOW+100*Point()))

      if(!UseRsi || RSI>30)

      if(!UseStochastic || ( m_2 < s_2 && m_1 > s_1))

      {

         buffer1[i]= Low[i]-20*_Point; //blue up arrow

      }

   }

   

   return(rates_total);

Files:
Reason: