Navigation:Home > Content >

RPoint_3_.mq4

Time: 2011-08-18 | Download file:RPoint_3_.mq4

//+------------------------------------------------------------------+
//|                                                        RPoint.mq4 |
//|                               Copyright © 2004, Poul_Trade_Forum |
//|                                                         Aborigen |
//|                                          http://forex.kbpauk.ru/ |
//+------------------------------------------------------------------+
#property copyright "Poul Trade Forum"
#property link      "http://forex.kbpauk.ru/"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 clrDodgerBlue
#property indicator_width1 2
#property indicator_color2 clrDeepPink
#property indicator_width2 2
#property indicator_color3 clrLime
#property indicator_width3 1
#property indicator_color4 clrRed
#property indicator_width4 1
#property indicator_color5 clrBlue
#property indicator_width5 2
#property indicator_color6 clrMagenta
#property indicator_width6 2


//---- input parameters
extern int  ReversPoint1   = 12;
bool AlertsMessage1 = true;
bool AlertsSound1   = false;
extern int  ReversPoint2   = 60;
bool AlertsMessage2 = true;
bool AlertsSound2   = false;

//---- buffers
double RBuffer1[],RBuffer2[];
double R_1_UP[],R_1_DN[];
double R_2_UP[],R_2_DN[];

int Trend1=1, Trend2=1, InTrend1, InTrend2, ttime, Last_Trend1=-1, Last_Trend2=-1;
double Points, Last_High1, Last_Low1, Last_High2, Last_Low2;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   Points = MarketInfo (Symbol(), MODE_POINT);
   if(Digits==3 || Digits==5)    Points = Points*10;
//---- indicator line
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexStyle(1,DRAW_SECTION);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexBuffer(0,RBuffer1);
   SetIndexBuffer(1,RBuffer2);
   SetIndexBuffer(2,R_1_UP);
   SetIndexBuffer(3,R_1_DN);
   SetIndexBuffer(4,R_2_UP);
   SetIndexBuffer(5,R_2_DN);
   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
   SetIndexEmptyValue(2,0);
   SetIndexEmptyValue(3,0);
   SetIndexEmptyValue(4,0);
   SetIndexEmptyValue(5,0);
   SetIndexArrow(2,233);
   SetIndexArrow(3,234);
   SetIndexArrow(4,233);
   SetIndexArrow(5,234);
   
   //---- name for DataWindow and indicator subwindow label
   IndicatorShortName("RPoint");
   SetIndexLabel(0,"RPoint1");
   SetIndexLabel(1,"RPoint2");
   SetIndexLabel(2,"Up1");
   SetIndexLabel(3,"Down1");
   SetIndexLabel(4,"Up2");
   SetIndexLabel(5,"Down2");

//----
   SetIndexDrawBegin(0,2*ReversPoint1);
   SetIndexDrawBegin(1,2*ReversPoint2);
   SetIndexDrawBegin(2,2*ReversPoint1);
   SetIndexDrawBegin(3,2*ReversPoint1);
   SetIndexDrawBegin(4,2*ReversPoint2);
   SetIndexDrawBegin(5,2*ReversPoint2);
//----

   return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int    counted_bars=IndicatorCounted(),i,shift;
   string objectName;

//---- TODO: add your code here
   i=(Bars-counted_bars)-1;

   for (shift=i; shift>=0;shift--)
   {
      if (Time[shift]!=ttime)
      {
         InTrend1=InTrend1+1;
         InTrend2=InTrend2+1;
      }
      ttime=Time[shift];
      
      //1
      RBuffer1[shift]=0;
      if (High[shift+1] > Last_High1 && Trend1==1)  InTrend1=1;
      if (Low [shift+1] < Last_Low1  && Trend1==0)  InTrend1=1;
      if (High[shift+1] > Last_High1)  Last_High1 = High[shift+1];
      if (Low [shift+1] < Last_Low1)   Last_Low1  = Low [shift+1];

      if (Trend1==1 && Low[shift+1]1)
      {
         Trend1=0;
         RBuffer1[shift+InTrend1]=High[shift+InTrend1];
         Last_High1=Low[shift+1];
         Last_Low1=Low[shift+1];
         InTrend1=1; 
         R_1_DN[shift]=High[shift]+2*Points;
      }

      if (Trend1==0 && High[shift+1]>Last_Low1+ReversPoint1*Points && InTrend1>1)
      {
         Trend1=1;
         RBuffer1[shift+InTrend1]=Low[shift+InTrend1];
         Last_Low1=High[shift+1];
         Last_High1=High[shift+1];
         InTrend1=1;
         R_1_UP[shift]=Low[shift]-2*Points;
      }   

      RBuffer2[shift]=0;
      if (High[shift+1]>Last_High2 && Trend2==1)  InTrend2=1;
      if (Low[shift+1]Last_High2) Last_High2=High[shift+1];
      if (Low[shift+1]1)
      {
         Trend2=0;
         RBuffer2[shift+InTrend2]=High[shift+InTrend2];
         Last_High2=Low[shift+1];
         Last_Low2=Low[shift+1];
         InTrend2=1; 
         R_2_DN[shift]=High[shift]+5*Points;
      }

      if (Trend2==0 && High[shift+1]>Last_Low2+ReversPoint2*Points && InTrend2>1)
      {
         Trend2=1;
         RBuffer2[shift+InTrend2]=Low[shift+InTrend2];
         Last_Low2=High[shift+1];
         Last_High2=High[shift+1];
         InTrend2=1;
         R_2_UP[shift]=Low[shift]-5*Points;
      }   
//----
   }
   
   // Сигналы
   if(Trend2!=Last_Trend2)
   {
      if (AlertsMessage2)
      {
         if(Trend2==0)
            Alert     ( Symbol()+" "+Period()+": trend DOWN");
         else
            Alert     ( Symbol()+" "+Period()+": trend UP");
      }
      if (AlertsSound2)   PlaySound ( "alert2.wav");
      Last_Trend2=Trend2;
      objectName = "R_Point_Text_2";
      if ( ObjectFind ( objectName ) == -1 )
      {
         ObjectCreate ( objectName, OBJ_LABEL, 0, 0, 0 );
      }
      ObjectSet ( objectName, OBJPROP_CORNER, 1 );
      ObjectSet ( objectName, OBJPROP_XDISTANCE, 40 );
      ObjectSet ( objectName, OBJPROP_YDISTANCE, 20 );
      if(Trend2==0)
         ObjectSetText ( objectName, CharToStr(234), 14, "Wingdings", clrRed );
      else
         ObjectSetText ( objectName, CharToStr(233), 14, "Wingdings", clrLime );
   } 

   if(Trend1!=Last_Trend1)
   {
      if (AlertsMessage1)
      {
         if(Trend1==0)
            Alert     ( Symbol()+" "+Period()+": DOWN");
         else
            Alert     ( Symbol()+" "+Period()+": UP");
      }
      if (AlertsSound1)   PlaySound ( "alert.wav");
      Last_Trend1=Trend1;
      objectName = "R_Point_Text_1";
      if ( ObjectFind ( objectName ) == -1 )
      {
         ObjectCreate ( objectName, OBJ_LABEL, 0, 0, 0 );
      }
      ObjectSet ( objectName, OBJPROP_CORNER, 1 );
      ObjectSet ( objectName, OBJPROP_XDISTANCE, 20 );
      ObjectSet ( objectName, OBJPROP_YDISTANCE, 23 );
      if(Trend1==0)
         ObjectSetText ( objectName, CharToStr(234), 12, "Wingdings", clrRed );
      else
         ObjectSetText ( objectName, CharToStr(233), 12, "Wingdings", clrLime );
   } 

   return(0);
}
//+------------------------------------------------------------------+

Recommend