TRUE Forex

Просмотр кода форекс индикатора !!X10-MT4 RSI #2.mq4

#property indicator_separate_window
#property indicator_buffers   3
#property indicator_color1 DimGray
#property indicator_color2 Aqua
#property indicator_color3 Yellow
#property indicator_width1 2
#property indicator_width2 3
#property indicator_width3 3

#property indicator_level1 60
#property indicator_level2 55
#property indicator_level3 45
#property indicator_level4 40
#property indicator_level5 70
#property indicator_level6 30
#property indicator_levelstyle 0
#property indicator_levelcolor DimGray

//---- input parameters
//
//
//
//

extern int       RSIPeriod     =  14;
extern int       PriceType     =   0;
extern string    timeFrame     =  "Current time frame";
extern int       overBought    =  55;
extern int       overSold      =  45;
extern bool      showArrows    = false;
extern bool      alertsOn      = true;
extern bool      alertsMessage = true;
extern bool      alertsSound   = false;
extern bool      alertsEmail   = false;




//---- buffers
//
//
//
//
//

double   RSIBuffer[];
double   Upper[];
double   Lower[];

//
//
//
//
//

int      TimeFrame;
datetime TimeArray[];
int      maxArrows;


bool     show.extra.digit  =  false;  
double      DecNos;

double buffer.name, XARD;

color       color3            = White;
int         FontSize          =  11;
string      FontType          =  "Arial Black";
double      myPoint;
double      SetPoint() 



   { 
   double mPoint; 
   
   if (Digits < 4) 
   mPoint = 0.01; 
   else 
   mPoint = 0.0001; 
   
   return(mPoint); 
   }


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
      SetIndexBuffer(0,RSIBuffer);
      SetIndexBuffer(1,Upper);
      SetIndexBuffer(2,Lower);
      SetIndexLabel(0,NULL);//"RSI");
      SetIndexLabel(1,NULL);
      SetIndexLabel(2,NULL);
         
         //
         //
         //
         //
         //
         
         
      TimeFrame         = stringToTimeFrame(timeFrame);
      string shortName  = "  ";//RSI ("+TimeFrameToString(TimeFrame)+","+RSIPeriod+","+PriceTypeToString(PriceType);
        //    if (overBought < overSold) overBought = overSold;
        //    if (overBought < 100)      shortName  = shortName+","+overBought;
        //    if (overSold   >   0)      shortName  = shortName+","+overSold;
      IndicatorShortName(shortName);//+")");
      
      buffer.name=XARD;
   

   myPoint = SetPoint();
      
   return(0);
}

//
//
//
//
//

int deinit()
{
   DeleteArrows();
   
   ObjectDelete(buffer.name+"Panel01");
  ObjectDelete(buffer.name+"Panel02");
  ObjectDelete("RSI14");
  ObjectDelete("Spread");
  ObjectDelete("x2");
  ObjectDelete("x2b");
   
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{

  RefreshRates();

  if(show.extra.digit){int digit=1;int digitshift=-3;int digitshift1=-5;int digitshift2=3;int fontsize=4;int sprd=1;}
   else{ digitshift=0;digitshift1=0;digitshift2=0;fontsize=0;sprd=0;}

   if (StringFind (Symbol(), "JPY", 0) != -1){ DecNos = 2+digit;}
   else if(Symbol()=="XAUUSD" || Symbol()=="XAUUSDm"){ DecNos = 1+digit; }
   else if(Symbol()=="XAGUSD" || Symbol()=="XAGUSDm"){ DecNos = 2+digit; }
   else { DecNos = 4+digit; } 

   CreateFX3_Labels(buffer.name+"Panel01", 6, 1, "gg", 28, "Webdings", Gray);
   CreateFX3_Labels(buffer.name+"Panel02", 6,30, "gg", 28, "Webdings", Gray);
   
   double RSI14=iRSI(NULL,0,14,PRICE_CLOSE,0);
   CreateXX3_Labels( "RSI14",15,21);
   ObjectSetText("RSI14", "RSI: "+DoubleToStr(RSI14,0), FontSize, FontType, Black);

   double spread = (Ask-Bid)/myPoint;
   CreateXX3_Labels("Spread",11,7); 
   ObjectSetText("Spread", "SPD: "+DoubleToStr(spread,1), FontSize-1, FontType, Black);

   CreateXX3_Labels("x2", 10,34);
   ObjectSetText("x2",DoubleToStr(Bid,DecNos) , 14, "Arial Black", White);
   
   CreateXX3_Labels("x2b", 9,53);
   ObjectSetText("x2b",Symbol() , 12, "Arial Bold", Black);




   int    counted_bars=IndicatorCounted();
   int    limit;
   int    i,y;
   
   
   
   
   if(counted_bars<0) return(-1);
   limit=Bars-counted_bars;
         ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame);
            
      
   //
   //
   //
   //
   //
   
   for(i=0,y=0; i<limit; i++)
      {
            if(Time[i]<TimeArray[y]) y++;
               RSIBuffer[i] = iRSI(NULL,TimeFrame,RSIPeriod,PriceType,y);
      }

   //
   //
   //
   //
   //
   
   for(i=limit; i>=0; i--)
      {
            if (RSIBuffer[i] > overBought) { Upper[i] = RSIBuffer[i]; Upper[i+1] = RSIBuffer[i+1]; }
            else                           { Upper[i] = EMPTY_VALUE;
                                           if (Upper[i+2] == EMPTY_VALUE)
                                               Upper[i+1]  = EMPTY_VALUE; }
            if (RSIBuffer[i] < overSold)   { Lower[i] = RSIBuffer[i]; Lower[i+1] = RSIBuffer[i+1]; }
            else                           { Lower[i] = EMPTY_VALUE;
                                           if (Lower[i+2] == EMPTY_VALUE)
                                               Lower[i+1]  = EMPTY_VALUE; }
      }
   
   //
   //
   //
   //
   //
   
   if (showArrows)
      for (i=0; i<WindowBarsPerChart() ;i++)
         {
            if (RSIBuffer[i]>overBought && RSIBuffer[i+1]<overBought) DrawArrow(i,"UP");
            if (RSIBuffer[i]<overSold   && RSIBuffer[i+1]>overSold)   DrawArrow(i,"DOWN");
         }
   if (alertsOn)
      {
         if (RSIBuffer[0]>overBought && RSIBuffer[1]<overBought) doAlert(overBought+" line crossed UP");
         if (RSIBuffer[0]<overSold   && RSIBuffer[1]>overSold)   doAlert(overSold+" line crossed DOWN");
      }


   //
   //
   //
   //
   //
 
   return(0);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//
//
//
//
//

void DrawArrow(int i,string type)
{
   maxArrows++;
      ObjectCreate("RSISignal"+maxArrows,OBJ_ARROW,0,Time[i],0);
      if (type=="up")
         {
            ObjectSet("RSISignal"+maxArrows,OBJPROP_PRICE1,High[i]+(8*Point));
            ObjectSet("RSISignal"+maxArrows,OBJPROP_ARROWCODE,242);
            ObjectSet("RSISignal"+maxArrows,OBJPROP_COLOR,Yellow);
            ObjectSet("RSISignal"+maxArrows,OBJPROP_WIDTH,6);
         }
      else
         {
            ObjectSet("RSISignal"+maxArrows,OBJPROP_PRICE1,Low[i]-(6*Point));
            ObjectSet("RSISignal"+maxArrows,OBJPROP_ARROWCODE,241);
            ObjectSet("RSISignal"+maxArrows,OBJPROP_COLOR,LimeGreen);
            ObjectSet("RSISignal"+maxArrows,OBJPROP_WIDTH,6);
         }
}
void DeleteArrows()
{
   while(maxArrows>0) { ObjectDelete("RSISignal"+maxArrows); maxArrows--; }
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

void doAlert(string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
      if (previousAlert != doWhat || previousTime != Time[0]) {
          previousAlert  = doWhat;
          previousTime   = Time[0];
      
          //
          //
          //
          //
          //
            
          message =  StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_MINUTES)," RSI ",doWhat);
             if (alertsMessage) Alert(message);
             if (alertsSound)   PlaySound("alert2.wav");
             if (alertsEmail)   SendMail(StringConcatenate(Symbol()," RSI crossing"),message);
      }        
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//
//
//
//
//

string PriceTypeToString(int pt)
{
   string answer;
   switch(pt)
   {
      case 0:  answer = "Close"    ; break; 
      case 1:  answer = "Open"     ; break;
      case 2:  answer = "High"     ; break;
      case 3:  answer = "Low"      ; break;
      case 4:  answer = "Median"   ; break;
      case 5:  answer = "Typical"  ; break;
      case 6:  answer = "Wighted"  ; break;
      default: answer = "Invalid price field requested";
                                    Alert(answer);
   }
   return(answer);
}
int stringToTimeFrame(string tfs)
{
   int tf=0;
       tfs = StringUpperCase(tfs);
         if (tfs=="M1" || tfs=="1")     tf=PERIOD_M1;
         if (tfs=="M5" || tfs=="5")     tf=PERIOD_M5;
         if (tfs=="M15"|| tfs=="15")    tf=PERIOD_M15;
         if (tfs=="M30"|| tfs=="30")    tf=PERIOD_M30;
         if (tfs=="H1" || tfs=="60")    tf=PERIOD_H1;
         if (tfs=="H4" || tfs=="240")   tf=PERIOD_H4;
         if (tfs=="D1" || tfs=="1440")  tf=PERIOD_D1;
         if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;
         if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;
         if (tf<Period()) tf=Period();
  return(tf);
}
string TimeFrameToString(int tf)
{
   string tfs="Current time frame";
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN1";
   }
   return(tfs);
}

//
//
//
//
//

string StringUpperCase(string str)
{
   string   s = str;
   int      lenght = StringLen(str) - 1;
   int      char;
   
   while(lenght >= 0)
      {
         char = StringGetChar(s, lenght);
         
         //
         //
         //
         //
         //
         
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                  s = StringSetChar(s, lenght, char - 32);
          else 
              if(char > -33 && char < 0)
                  s = StringSetChar(s, lenght, char + 224);
                  
         //
         //
         //
         //
         //
                                 
         lenght--;
   }
   
   //
   //
   //
   //
   //
   
   return(s);
}

int CreateXX3_Labels( string c, int x2, int y2 ) {
   ObjectCreate( c, OBJ_LABEL,0, 0, 0 );
   ObjectSet( c, OBJPROP_CORNER, 2 );
   ObjectSet( c, OBJPROP_XDISTANCE,x2-6);
   ObjectSet( c, OBJPROP_YDISTANCE,y2-5);
   ObjectSet( c, OBJPROP_BACK, false );
   }
   
   int CreateFX3_Labels( string K, int x, int y, string Text, int FontSize, string Font, color Color ) 
   {
   ObjectCreate( K, OBJ_LABEL, 0, 0, 0 );
   ObjectSet( K, OBJPROP_CORNER, 2);
   ObjectSet( K, OBJPROP_XDISTANCE,x-4);
   ObjectSet( K, OBJPROP_YDISTANCE,y);
   ObjectSet( K, OBJPROP_BACK, false );
   ObjectSetText(K, Text, FontSize, Font, Color);
   }

Комментарии к исходному коду форекс индикатора !!X10-MT4 RSI #2.mq4
В целях безопасности и борьбы со спамом в тексте комментариев запрещено размещать html-теги и ссылки. Благодарим за понимание.

  • X
  • 0% загружено
« индикатор !!X08-MT4 HISTO MA.mq4
индикатор !!X12-MT4 4XTRAP v2.mq4 »