ARROW_RSI-8_CROSS-55 45_v2

Author: AHGduP
ARROW_RSI-8_CROSS-55 45_v2
Indicators Used
Relative strength index
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screenIt plays sound alerts
0 Views
0 Downloads
0 Favorites
ARROW_RSI-8_CROSS-55 45_v2
//+------------------------------------------------------------------+
//|                              ARROW_RSI_CROSS50.mq4                                                             
//+------------------------------------------------------------------+
/* Modified by Zen_Leow 
   1. To ensure only one alert per cross 
   2. Tidied up the codes
*/

#property copyright "AHGduP"
#property link      "ARROW_RSI_CROSS-70"

#property indicator_chart_window
#include <WinUser32.mqh>
#property indicator_buffers 2
#property indicator_color1 LimeGreen //LimeGreen
#property indicator_width1 1
#property indicator_color2 Red //Red
#property indicator_width2 1

//====================================================

extern int        TF               = 0 ;

extern string     RSI              = "== RSI ===";           
extern int        RSIPeriod        = 8 ; //14

//====================================================

extern bool   Alarm_On       =  True ; 
extern int    Move_Arrow     = 10 ;
extern int    CountBars      = 500 ;//500    

bool   StepTF_Up   =  true; 

double RSI1_up , RSI1_dn ; 

double up1, down1 ;

double bBuffer1[];
double sBuffer1[];

datetime LastAlertTime = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW,0, 2);//LineSize);
   SetIndexBuffer(0,bBuffer1);
   SetIndexEmptyValue(0,0);
   SetIndexArrow(0,233);// 233
   
   SetIndexStyle(1,DRAW_ARROW,0, 2);//LineSize);
   SetIndexBuffer(1,sBuffer1);
   SetIndexEmptyValue(1,0);
   SetIndexArrow(1,234);//234
  
   up1   = 0 ;
   down1 = 0 ;
 
//========================================================================================
   switch(TF)   
   {    
      case 1 : string TimeFrameStr60="Period_M1"; break;
      case 5 : TimeFrameStr60="Period_M5"; break;
      case 15 : TimeFrameStr60="Period_M15"; break;
      case 30 : TimeFrameStr60="Period_M30"; break;
      case 60 : TimeFrameStr60="Period_H1"; break;
      case 240 : TimeFrameStr60="Period_H4"; break;
      case 1440 : TimeFrameStr60="Period_D1"; break;
      case 10080 : TimeFrameStr60="Period_W1"; break;
      case 43200 : TimeFrameStr60="Period_MN1"; break;
      default : TimeFrameStr60="Current Timeframe";
      SetStepTF_Up();
   }

//=======================================================================================  
   string  ThisName = "Rsi_55/45";// Rsi_246 ??? 
   string Text=ThisName;
   Text=Text+"  ("+TF;
   Text=Text+")";
   Text=Text+"( ";
   Text=Text+" "+DoubleToStr(RSIPeriod,0);
   Text=Text+")  ";
   IndicatorShortName(Text);
   
   return(0);
}
          
//+--------------------------------------------------------------------------------------+
int start()
{
   static int last_bar = 0;
   if(last_bar==Bars) return (0);
   last_bar = Bars;
   int limit,y=0,counted_bars=IndicatorCounted();
   
   limit=Bars-counted_bars+TF/Period();
   
   if(counted_bars>0) limit++; else if (limit>100) limit=CountBars;  
   SetIndexDrawBegin(0,Bars-CountBars);
   SetIndexDrawBegin(1,Bars-CountBars);

   for(int i=CountBars;i>0;i--)
   {  
      int p1;
      p1 = iBarShift( NULL, TF, Time[i], false );
      
      bBuffer1[i] = EMPTY_VALUE; 
      sBuffer1[i] = EMPTY_VALUE;
//=================================================================================================                   
//===================== RSI 55 / 45 =============================================================    

      double RSI1_rsi  = iRSI(NULL,TF,RSIPeriod,PRICE_CLOSE,p1);  
      if ((RSI1_rsi > 55))
      { 
         RSI1_up = 1; 
         RSI1_dn = 0; 
      }//  <<<<<<<<<< NB >>>>>>>>>>>>
         
      if ((RSI1_rsi < 45))
      { 
         RSI1_up = 0; 
         RSI1_dn = 1; 
      }// NB
         

//====================================================================================================
//======== ARROWS   ARROWS   ARROWS   ARROWS   ARROWS   ARROWS   ARROWS ==============================   
      
      if( up1 == 0 && RSI1_up == 1)
      {   
         bBuffer1[i] = Low[i]- Move_Arrow*Point;
         
         up1   = 1;  
         down1 = 0;
      }    
//-------------------------------------------------------------------------------------------------         
      if( down1 == 0 && RSI1_dn == 1)
      {   
         sBuffer1[i] = High[i]+ Move_Arrow*Point;
         
         down1 = 1;   
         up1   = 0;
      }
//===========cancel signal  and re enter in same direction===========================    
  
      if ( up1 == 1 && RSI1_up != 1 )
      { 
         up1 = 0;   
         down1 = 0;
      }    
         
      if ( down1 == 1 && RSI1_dn != 1 )
      {  
         up1 = 0;   
         down1 = 0;
      }    
 //=====================================================================================
   }
   if (Alarm_On)
   {
      ProcessAlert();
   }
   return(0);
}
 //========================step timeframe up TF60====================================== ++       
void SetValues60(int p1)  
{  
   TF = p1;        
}

void SetStepTF_Up()     
{  
   switch (Period())                
   {  
      case PERIOD_M1  :  SetValues60(PERIOD_M1);    break;       
      case PERIOD_M5  :  SetValues60(PERIOD_M5);    break;         
      case PERIOD_M15 :  SetValues60(PERIOD_M15);   break;     
      case PERIOD_M30 :  SetValues60(PERIOD_M30);   break;            
      case PERIOD_H1  :  SetValues60(PERIOD_H1);    break;               
      case PERIOD_H4  :  SetValues60(PERIOD_H4);    break;                
      case PERIOD_D1  :  SetValues60(PERIOD_D1);    break;                
      case PERIOD_W1  :  SetValues60(PERIOD_W1);    break;             
      case PERIOD_MN1 :  SetValues60(PERIOD_MN1);   break;                   
   } 
}

void ProcessAlert()
{
   if (bBuffer1[1] != EMPTY_VALUE && LastAlertTime != Time[0])
   {
      Alert(Symbol() + " M("+Period()+") - VM BUY");
      PlaySound("RSI_CROSS+CCI+BUY.wav");
      LastAlertTime = Time[0];
   }
   
   if (sBuffer1[1] != EMPTY_VALUE && LastAlertTime != Time[0])
   {
      Alert(Symbol() + " M("+Period()+") - VM SELL");
      PlaySound("RSI_CROSS+CCI+SELL.wav");
      LastAlertTime = Time[0];
   }
}
//================================================================================== ++  
 

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---