PriceSound_Parabolic_standart2

Author: Roll
Miscellaneous
Implements a curve of type %1It plays sound alerts
0 Views
0 Downloads
0 Favorites
PriceSound_Parabolic_standart2
//+------------------------------------------------------------------+
//|                               PriceSound_Parabolic_standart2.mq4 |
//|                                                            Roll  |
//+------------------------------------------------------------------+
#property copyright "Roll"
#property link      "http://www.mql4.com/ru/users/Roll"
/*Èñòî÷íèêè:1.- èíäèêàòîð Parabolic_standart2/àâòîð Ëóêàøóê Â.Ã./lukas1/http://codebase.mql4.com/ru/5102
            2.- èíäèêàòîð PriceSound_trendline http://codebase.mql4.com/ru/7601 */
#property indicator_chart_window
#property indicator_color1 Orchid
extern double Step=0.02;
extern double Maximum=0.2;
extern bool   Sound_Play=true;      //ðàçðåøèòü çâóê
extern int    trendline_Bar_Shift=1;//ñäâèã òðåíäîâîé ëèíèè ïî áàðàì 
extern string UniqueName1="TL1";    //íàçâàíèå òðåíäîâîé ëèíèè
extern color  LineColor_UP=Yellow;  //öâåò òðåíäîâîé ëèíèè(íàïðàâëåíèå ââåðõ)
extern color  LineColor_DN=Magenta; //öâåò òðåíäîâîé ëèíèè(íàïðàâëåíèå âíèç)
extern int    LineWidth1=2;         //øèðèíà òðåíäîâîé ëèíèè
extern string Sound1="ready.wav";   //íàçâàíèå çâóêîâîãî ôàéëà äëÿ òðåíäîâîé ëèíèè
extern string Sound2="news.wav";    //íàçâàíèå çâóêîâîãî ôàéëà äëÿ ñìåíû íàïðàâëåíèÿ Ïàðàáîëèêà ïî êîíòðîëüíîìó áàðó
extern int    Ind_Bar=0;            //íîìåð áàðà(ñìåùåíèå)äëÿ èíäèêàöèè ïóíêòîâ
extern int    DistPips=0;           //Åñëè ìåíüøå 10-àâò.óñòàíîâêà.Ðåãóëèðîâêà ðàññòîÿíèÿ îò èçîáðàæåíèÿ ÷èñëà ïóíêòîâ äî ñîîòâ.ïðÿìîé
int ArrShift,t;bool Active,dirlong;string PipsTextName;
double SarBuffer[],start,last_high,last_low,ep,sar,price_low,price_high,LastLevel,LastPrice,TradePoint;
static double lastLevel_1,lastPrice_1;static bool dir_dn,dir_up,first=false;
//+------------------------------------------------------------------+
int init()
  {
   if(Digits==3 || Digits==5)TradePoint=Point*10;else TradePoint=Point;
   LastPrice=0;lastLevel_1=0;
   IndicatorDigits(Digits);
   string SS=DoubleToStr(Step,4),MM=DoubleToStr(Maximum,4);
   SetIndexLabel(0,"Step= "+SS+", Max= "+MM);SetIndexStyle(0,DRAW_ARROW);SetIndexArrow(0,159);
   SetIndexBuffer(0,SarBuffer);SetIndexDrawBegin(0,4/Step);dir_dn=-1; dir_up=-1;
   switch(Period())
     {
      case PERIOD_M1: ArrShift=10;break;case PERIOD_M5: ArrShift=12;break;
      case PERIOD_M15:ArrShift=15;break;case PERIOD_M30:ArrShift=30;break;
      case PERIOD_H1: ArrShift=50;break;case PERIOD_H4:ArrShift=100;break;
      case PERIOD_D1: ArrShift=200;break;case PERIOD_W1:ArrShift=500;break;
      case PERIOD_MN1:ArrShift=1000;break;
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   if(UninitializeReason()==REASON_REMOVE)
     {
      ObjectDelete(UniqueName1);PipsTextName=UniqueName1+" Pips";ObjectDelete(PipsTextName);
      lastLevel_1=0;lastPrice_1=0;
     }
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   if(Bars<5)return(0);if(trendline_Bar_Shift<0)trendline_Bar_Shift=0;
   dirlong=true;start=Step;int i=Bars-4;static datetime New_Time;
   while(i>=0)
     {
      price_low=Low[i];price_high=High[i];sar=SarBuffer[i+1]+start*(ep-SarBuffer[i+1]);
      if(dirlong)
        {
         if(ep<price_high && (start+Step)<=Maximum)start+=Step;
         if(sar>=price_low)
           {
            start=Step;dirlong=false;ep=price_low;last_low=price_low;
            if(High[i]<last_high)SarBuffer[i]=last_high;else SarBuffer[i]=High[i];i--;continue;
           }
         else
           {
            if(ep<price_low && (start+Step)<=Maximum)start+=Step;
            if(ep<price_high){last_high=price_high;ep=price_high;}
           }
        }
      else
        {
         if(ep>price_low && (start+Step)<=Maximum)start+=Step;
         if(sar<=price_high)
           {
            start=Step;dirlong=true;ep=price_high;last_high=price_high;
            if(Low[i]>last_low)SarBuffer[i]=last_low;else SarBuffer[i]=Low[i];i--;continue;
           }
         else
           {
            if(ep>price_high && (start+Step)<=Maximum)start+=Step;
            if(ep>price_low){last_low=price_low;ep=price_low;}
           }
        }SarBuffer[i]=sar;i--;
     }
   double c1=SarBuffer[trendline_Bar_Shift],c3=SarBuffer[trendline_Bar_Shift+1],c2=Close[1];
   datetime c0=Time[0]+3*Period()*60;color LineColor;if(c1>c2)LineColor=LineColor_DN;if(c1<c2)LineColor=LineColor_UP;
   if(ObjectFind(UniqueName1)!=0)
     {
      ObjectCreate(UniqueName1,OBJ_TREND,0,Time[0],c1,c0,c1);ObjectSetText(UniqueName1,"Price alert level1",0);
      ObjectSet(UniqueName1,OBJPROP_COLOR,LineColor);ObjectSet(UniqueName1,OBJPROP_WIDTH,LineWidth1);
     }
   if(ObjectFind(UniqueName1)==0)
     {
      ObjectMove(UniqueName1,0,Time[2],c1);ObjectMove(UniqueName1,1,c0,c1);
      PriceSound_trendline(UniqueName1,LineColor,Sound1,ArrShift,lastLevel_1,lastPrice_1);
     }
   if(New_Time!=Time[0]){New_Time=Time[0];dir_dn=false;dir_up=false;}
   if(c1>c2&&c3<c1&&dir_dn==0){for(i=0;i<3;i++)PlaySound (Sound2);dir_dn=1;return(0);}
   if(c1<c2&&c3>c1&&dir_up==0){for(i=0;i<3;i++)PlaySound (Sound2);dir_up=1;return(0);}return(0);
  }
//+------------------------------------------------------------------+
void PriceSound_trendline(string UniqueName,color LineColor,string Sound,int arrShift,double lastLevel,double lastPrice)
  {
   PipsTextName=StringConcatenate(UniqueName," ","Pips");if(DistPips>=10)ArrShift=DistPips;else ArrShift=arrShift;
   LastLevel=lastLevel;LastPrice=lastPrice;
   if(ObjectFind(PipsTextName)==-1)
     {
      double cp=LastLevel;if(cp==0)cp=LastLevel+(10+ArrShift)*TradePoint;
      ObjectCreate(PipsTextName,OBJ_TEXT,0,Time[0],cp);
     }
   if(Ind_Bar>0)t=Ind_Bar;else t=0;
   ObjectSet(PipsTextName,OBJPROP_TIME1,Time[t]);double newlevel=ObjectGetValueByShift(UniqueName,0);
   if(Active)
     {
      ObjectSet(UniqueName,OBJPROP_COLOR,LineColor);ObjectSetText(UniqueName,"Price sound level - Active",0);
      double Pips=MathAbs(NormalizeDouble((newlevel-Close[0])/TradePoint,Digits));
      if(Digits==3 || Digits==5)ObjectSetText(PipsTextName,DoubleToStr(Pips,1),14,"Terminal",LineColor);
      else ObjectSetText(PipsTextName,DoubleToStr(Pips,0),14,"Terminal",LineColor);
     }
   if(Close[0]>newlevel)ObjectSet(PipsTextName,OBJPROP_PRICE1,newlevel-ArrShift*TradePoint);
   if(Close[0]<newlevel)ObjectSet(PipsTextName,OBJPROP_PRICE1,newlevel+ArrShift*TradePoint);
   if(LastLevel!=newlevel){LastLevel=newlevel;LastPrice=0;ObjectSetText(UniqueName,"Price sound level - Active",0);Active=true;}
   if(Active && LastPrice!=0 && ((LastPrice<LastLevel && Close[0]>=LastLevel) || (LastPrice>LastLevel && Close[0]<=LastLevel)))
     {
      if(Sound_Play)PlaySound(Sound);else Active=false;ObjectSetText(PipsTextName,"",14,"Terminal",LineColor);
      ObjectSetText(UniqueName,"Price sound level - Inactive",0);ObjectSet(UniqueName,OBJPROP_COLOR,Blue);
     }
   if(UniqueName==UniqueName1){lastLevel_1=LastLevel;lastPrice_1=Close[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 ---