0
код часть 2:

void InitialiseBuffers(){
   IndicatorBuffers(3);
   IndicatorDigits(Digits);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,BufferSMA);
   SetIndexShift(0,0);
   SetIndexLabel(0,"Bands SMA");
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,BufferUpperBand);
   SetIndexShift(1,0);
   SetIndexLabel(1,"Bands Upper");
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,BufferLowerBand);
   SetIndexShift(2,0);
   SetIndexLabel(2,"Bands Lower");
   SetIndexDrawBegin(0,InpBandsPeriod+InpBandsShift);
   SetIndexDrawBegin(1,InpBandsPeriod+InpBandsShift);
   SetIndexDrawBegin(2,InpBandsPeriod+InpBandsShift);

}


datetime NewCandleTime=TimeCurrent();
bool CheckIfNewCandle(){
   if(NewCandleTime==iTime(Symbol(),0,0)) return false;
   else{
      NewCandleTime=iTime(Symbol(),0,0);
      return true;
   }
}


//Check if it is a trade Signla 0 - Neutral, 1 - Buy, -1 - Sell
ENUM_TRADE_SIGNAL IsSignal(int i){
   int j=i+Shift;
   if(AlertSignal==ON_BREAK_OUT){
      if(Open[j]<BufferUpperBand[j] && Close[j]>BufferUpperBand[j]) return SIGNAL_BUY;
      if(Open[j]>BufferLowerBand[j] && Close[j]<BufferLowerBand[j]) return SIGNAL_SELL;
      if(Close[j+1]<BufferUpperBand[j+1] && Close[j]>BufferUpperBand[j]) return SIGNAL_BUY;
      if(Close[j+1]>BufferLowerBand[j+1] && Close[j]<BufferLowerBand[j]) return SIGNAL_SELL;
   }
   if(AlertSignal==ON_BOUNCE_IN){
      if(Open[j]<BufferLowerBand[j] && Close[j]>BufferLowerBand[j]) return SIGNAL_BUY;
      if(Open[j]>BufferUpperBand[j] && Close[j]<BufferUpperBand[j]) return SIGNAL_SELL;
      if(Close[j+1]<BufferLowerBand[j+1] && Close[j]>BufferLowerBand[j]) return SIGNAL_BUY;
      if(Close[j+1]>BufferUpperBand[j+1] && Close[j]<BufferUpperBand[j]) return SIGNAL_SELL;
   }
   return SIGNAL_NEUTRAL;
}


datetime LastNotification=TimeCurrent()-WaitTimeNotify*60;

void NotifyHit(){
   if(!EnableNotify || TimeCurrent()<(LastNotification+WaitTimeNotify*60)) return;
   if(!SendAlert && !SendApp && !SendEmail) return;
   if(Time[0]==LastNotificationTime) return;
   ENUM_TRADE_SIGNAL Signal=IsSignal(0);
   if(Signal==SIGNAL_NEUTRAL) return;
   string EmailSubject=IndicatorName+" "+Symbol()+" Notification ";
   string EmailBody="\r\n"+AccountCompany()+" - "+AccountName()+" - "+IntegerToString(AccountNumber())+"\r\n\r\n"+IndicatorName+" Notification for "+Symbol()+"\r\n\r\n";
   string AlertText=IndicatorName+" - "+Symbol()+" Notification\r\n";
   string AppText=AccountCompany()+" - "+AccountName()+" - "+IntegerToString(AccountNumber())+" - "+IndicatorName+" - "+Symbol()+" - ";
   
   if(AlertSignal==ON_BREAK_OUT && Signal!=SIGNAL_NEUTRAL){
      EmailBody+="Price broke outside the Bollinger Band\r\n\r\n";
      AlertText+="Price broke outside the Bollinger Band\r\n";
      AppText+="Price broke outside the Bollinger Band";
   }
   if(AlertSignal==ON_BOUNCE_IN && Signal!=SIGNAL_NEUTRAL){
      EmailBody+="Price came back inside the Bollinger Band\r\n\r\n";
      AlertText+="Price came back inside the Bollinger Band\r\n";
      AppText+="Price came back inside the Bollinger Band";
   }
   
   if(SendAlert) Alert(AlertText);
   if(SendEmail){
      if(!SendMail(EmailSubject,EmailBody)) Print("Error sending email "+IntegerToString(GetLastError()));
   }
   if(SendApp){
      if(!SendNotification(AppText)) Print("Error sending notification "+IntegerToString(GetLastError()));
   }
   LastNotification=TimeCurrent();
   Print(IndicatorName+"-"+Symbol()+" last notification sent "+TimeToString(LastNotification));
}


void DrawArrows(){
   RemoveArrows();
   if(!EnableDrawArrows || BarsToScan==0) return;
   int MaxBars=Bars(Symbol(),PERIOD_CURRENT);
   if(MaxBars>BarsToScan) MaxBars=BarsToScan;
   for(int i=MaxBars-2;i>=1;i--){
      DrawArrow(i);
   }
}


void RemoveArrows(){
   int Window=-1;
   for(int i=ObjectsTotal(ChartID(),Window,-1)-1;i>=0;i--){
      if(StringFind(ObjectName(i),IndicatorName+"-ARWS-",0)>=0){
         ObjectDelete(ObjectName(i));
      }
   }
}

int SignalWidth=0;

void DrawArrow(int i){
   RemoveArrowCurr();
   if(!EnableDrawArrows){
      RemoveArrows();
      return;
   }
   ENUM_TRADE_SIGNAL Signal=IsSignal(i);
   if(Signal==SIGNAL_NEUTRAL) return;
   datetime ArrowDate=iTime(Symbol(),0,i);
   string ArrowName=IndicatorName+"-ARWS-"+IntegerToString(ArrowDate);
   double ArrowPrice=0;
   int ArrowType=0;
   color ArrowColor=0;
   int ArrowAnchor=0;
   string ArrowDesc="";
   if(Signal==SIGNAL_BUY){
      ArrowPrice=Low[i];
      ArrowType=ArrowBuy; 
      ArrowColor=clrGreen;  
      ArrowAnchor=ANCHOR_TOP;
      ArrowDesc="BUY";
   }
   if(Signal==SIGNAL_SELL){
      ArrowPrice=High[i];
      ArrowType=ArrowSell;
      ArrowColor=clrRed;
      ArrowAnchor=ANCHOR_BOTTOM;
      ArrowDesc="SELL";
   }
   ObjectCreate(0,ArrowName,OBJ_ARROW,0,ArrowDate,ArrowPrice);
   ObjectSetInteger(0,ArrowName,OBJPROP_COLOR,ArrowColor);
   ObjectSetInteger(0,ArrowName,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,ArrowName,OBJPROP_HIDDEN,true);
   ObjectSetInteger(0,ArrowName,OBJPROP_ANCHOR,ArrowAnchor);
   ObjectSetInteger(0,ArrowName,OBJPROP_ARROWCODE,ArrowType);
   SignalWidth=ArrowSize;
   ObjectSetInteger(0,ArrowName,OBJPROP_WIDTH,SignalWidth);
   ObjectSetInteger(0,ArrowName,OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,ArrowName,OBJPROP_BGCOLOR,ArrowColor);
   ObjectSetString(0,ArrowName,OBJPROP_TEXT,ArrowDesc);
   datetime CurrTime=iTime(Symbol(),0,0);
}


void RemoveArrowCurr(){
   datetime ArrowDate=iTime(Symbol(),0,Shift);
   string ArrowName=IndicatorName+"-ARWS-"+IntegerToString(ArrowDate);
   ObjectDelete(0,ArrowName);
}

avatar

Tony-Montana

  • 8 апреля 2021, 18:28
0
код часть 1:
#property link          "https://www.earnforex.com/metatrader-indicators/bollinger-bands-breakout-alert/"
#property version       "1.02"
#property strict
#property copyright     "EarnForex.com - 2019-2020"
#property description   "The classic Bollinger Bands with more features"
#property description   " "
#property description   "WARNING : You use this software at your own risk."
#property description   "The creator of these plugins cannot be held responsible for damage or loss."
#property description   " "
#property description   "Find More on EarnForex.com"
//#property icon          "\\Files\\EF-Icon-64x64px.ico"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LightSeaGreen
#property indicator_color2 LightSeaGreen
#property indicator_color3 LightSeaGreen

//#include <MQLTA ErrorHandling.mqh>
//#include <MQLTA Utils.mqh>

enum ENUM_TRADE_SIGNAL{
   SIGNAL_BUY=1,     //BUY
   SIGNAL_SELL=-1,   //SELL
   SIGNAL_NEUTRAL=0  //NEUTRAL
};

enum ENUM_CANDLE_TO_CHECK{
   CURRENT_CANDLE=0,    //CURRENT CANDLE
   CLOSED_CANDLE=1      //PREVIOUS CANDLE
};

enum ENUM_ALERT_SIGNAL{
   ON_BREAK_OUT=0,      //ON BREAK OUT OF BANDS
   ON_BOUNCE_IN=1,      //ON RE-ENTER IN BANDS
};

enum ENUM_ARROW_SIZE{
   ARROW_SIZE_AUTO=0,      //AUTOMATIC SIZE
   ARROW_SIZE_VERYSMALL=1, //VERY SMALL
   ARROW_SIZE_SMALL=2,     //SMALL
   ARROW_SIZE_MEDIUM=3,    //MEDIUM
   ARROW_SIZE_BIG=4,       //BIG
   ARROW_SIZE_VERYBIG=5,   //VERY BIG
};

input string Comment1="========================";   //MQLTA Bollinger Bands With Alert
input string IndicatorName="MQLTA-BBWA";    //Indicator Short Name

input string Comment2="========================";   //Indicator Parameters
input int    InpBandsPeriod=20;      // Bands Period
input int    InpBandsShift=0;        // Bands Shift
input double InpBandsDeviations=2.0; // Bands Deviations
input ENUM_APPLIED_PRICE InpBandsAppliedPrice=PRICE_CLOSE;  //Bands Applied Price
input ENUM_ALERT_SIGNAL AlertSignal=ON_BREAK_OUT;           //Alert Signal When
input ENUM_CANDLE_TO_CHECK CandleToCheck=CURRENT_CANDLE;    //Candle To Use For Analysis
input int BarsToScan=500;                                   //Number Of Candles To Analyse

input string Comment_3="====================";     //Notification Options
extern bool EnableNotify=false;                    //Enable Notifications Feature
extern bool SendAlert=true;                        //Send Alert Notification
extern bool SendApp=true;                          //Send Notification to Mobile
extern bool SendEmail=true;                        //Send Notification via Email
input int WaitTimeNotify=5;                        //Wait time between notifications (Minutes)

input string Comment_4="====================";     //Drawing Options
input bool EnableDrawArrows=true;                  //Draw Signal Arrows
input int ArrowBuy=241;                            //Buy Arrow Code
input int ArrowSell=242;                           //Sell Arrow Code
input int ArrowSize=3;                             //Arrow Size (1-5)

double BufferUpperBand[];
double BufferLowerBand[];
double BufferSMA[];

datetime LastNotificationTime;
int Shift=0;


int OnInit(void){

   IndicatorSetString(INDICATOR_SHORTNAME,IndicatorName);

   OnInitInitialization();
   if(!OnInitPreChecksPass()){
      return(INIT_FAILED);
   }   

   InitialiseBuffers();

   return(INIT_SUCCEEDED);
}


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[]){

   bool IsNewCandle=CheckIfNewCandle();
   int i,pos,upTo;

   pos=0;
   if(prev_calculated==0 || IsNewCandle)
      upTo=BarsToScan-1;
   else
      upTo=0;

   for(i=pos; i<=upTo && !IsStopped(); i++){
      BufferSMA[i]=iBands(Symbol(),PERIOD_CURRENT,InpBandsPeriod,InpBandsDeviations,InpBandsShift,InpBandsAppliedPrice,MODE_MAIN,i);
      BufferUpperBand[i]=iBands(Symbol(),PERIOD_CURRENT,InpBandsPeriod,InpBandsDeviations,InpBandsShift,InpBandsAppliedPrice,MODE_UPPER,i);
      BufferLowerBand[i]=iBands(Symbol(),PERIOD_CURRENT,InpBandsPeriod,InpBandsDeviations,InpBandsShift,InpBandsAppliedPrice,MODE_LOWER,i);
   }
     
   if(IsNewCandle || prev_calculated==0){
      if(EnableDrawArrows) DrawArrows();
   }
   
   if(EnableDrawArrows)
      DrawArrow(0);

   if(EnableNotify)
      NotifyHit();
      
   return(rates_total);
}
  
  
void OnDeinit(const int reason){
   CleanChart();
}  


void OnInitInitialization(){
   LastNotificationTime=TimeCurrent();
   Shift=CandleToCheck;
}


bool OnInitPreChecksPass(){
   if(InpBandsPeriod<=0){
      Print("Wrong input parameter Bands Period=",InpBandsPeriod);
      return false;
   }   
   if(Bars(Symbol(),PERIOD_CURRENT)<InpBandsPeriod+InpBandsShift){
      Print("Not Enough Historical Candles");
      return false;
   }   
   return true;
}


void CleanChart(){
   int Window=0;
   for(int i=ObjectsTotal(ChartID(),Window,-1)-1;i>=0;i--){
      if(StringFind(ObjectName(i),IndicatorName,0)>=0){
         ObjectDelete(ObjectName(i));
      }
   }
}

avatar

Tony-Montana

  • 8 апреля 2021, 18:27
0
Есть такой индикатор.


avatar

Tony-Montana

  • 8 апреля 2021, 18:24
Начать торговлю с Альпари