bands r2
//+------------------------------------------------------------------+
//| Bands.mq4 |
//| // // Copyright ?2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//+------------------------------------------------------------------+
//| |
//| 2008 Speech. Speech.tplRev.2a 2008 ( itemsdepot@hotmail.com)|
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Gray
#property indicator_color2 OliveDrab
#property indicator_color3 Brown
#property indicator_width1 1
#property indicator_width2 3
#property indicator_width3 3
////
//---- indicator parameters
extern bool BBDrawBands=True;
extern int BandsDrawRange=100;
extern int BandsShift=0;
extern double BandsDeviations=2.0;
extern bool BandsAlertBoxOn=False;
extern bool BandSoundAlertHighOn=True;
extern bool BandSoundAlertLowOn=True;
extern string WaveBandName="bandup.wav";
extern string WaveBandName2="banddown.wav";
extern double BBAlarmDelay=22;
extern int BBCandleAlertRange=2;
extern int BandsMAPeriod=7;
extern int BBMovingAverage=0;
extern string BBMovingAverageSettings="0-SMA,1-EMA,2-SMMA,3-LWMA"; // simple, exponential, smoothed , linear
extern int BBAppliedPrice=0;
extern string BBAppliedPriceSettings1="0-Close,1-Open,2-High,3-Low";
extern string BBAppliedPriceSettings2="4-Median,5-Typical,6-Weighted";
extern double BBTime;
//----------------- buffers
double MovingBuffer[];
double UpperBuffer[];
double LowerBuffer[];
double BBBreachLog[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators ------------------------------------------------
IndicatorShortName("Bands R2");
if (BBDrawBands) SetIndexStyle(0,0,0,indicator_width1,indicator_color1);
else SetIndexStyle(0,12,0,indicator_width1,indicator_color1);
SetIndexBuffer(0,MovingBuffer);
SetIndexDrawBegin(0,BandsDrawRange);
if (BBDrawBands) SetIndexStyle(1,0,0,indicator_width2,indicator_color2);
else SetIndexStyle(1,12,0,indicator_width2,indicator_color2);
SetIndexBuffer(1,UpperBuffer);
SetIndexDrawBegin(1,BandsDrawRange);
if (BBDrawBands) SetIndexStyle(2,0,0,indicator_width3,indicator_color3);
else SetIndexStyle(2,12,0,indicator_width3,indicator_color3);
SetIndexBuffer(2,LowerBuffer);
SetIndexDrawBegin(2,BandsDrawRange);
BBTime=TimeLocal();
return(0);
}
//+------------------------------------------------------------------+
//| Bollinger Bands |
//+------------------------------------------------------------------+
int start()
{
int i,k;
bool BBSpeak=False;
double deviation;
double sum,oldval,newres;
double BBFinishTime=TimeCurrent();
//----
if(Bars<=BandsDrawRange) return(0);
//------------------------------------------------------------ Draw
for(i=BandsDrawRange; i>=0; i--)
{
if (BBMovingAverage>3 && BBMovingAverage<0) BBMovingAverage=0;
if (BBAppliedPrice>6 && BBAppliedPrice<6 ) BBAppliedPrice=0;
MovingBuffer=iMA(NULL,0,BandsMAPeriod,BandsShift,BBMovingAverage,BBAppliedPrice,i);
//---------------------
sum=0.0;
k=i+BandsMAPeriod-1;
oldval=MovingBuffer;
while(k>=i)
{
newres=Close-oldval;
sum+=newres*newres;
k--;
}
deviation=BandsDeviations*MathSqrt(sum/BandsMAPeriod);
if (oldval>0) UpperBuffer=oldval+deviation;
if (oldval>0) LowerBuffer=oldval-deviation;
} // ----------------------------------------- End Draw
//-------------------------------------------- Start Speak
BBSpeak=False;
BBFinishTime=TimeLocal();
if ((BBFinishTime - BBTime) >= BBAlarmDelay ) // && pos==0)
{
BBFinishTime=TimeLocal();
BBTime=TimeLocal();
BBSpeak=True;
}
while (BBSpeak==True)
{
for(i=0; i<=BBCandleAlertRange; i++)
{
//--------------------------
if (High > UpperBuffer)
{
if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" High Band Cross: "+High);
if (BandSoundAlertHighOn==True) PlaySound(WaveBandName);
BBSpeak=False;
}
if (Low < LowerBuffer)
{
if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" Low Band Cross: "+Low);
if (BandSoundAlertLowOn==True) PlaySound(WaveBandName2);
BBSpeak=False;
}
if (i >= BBCandleAlertRange) BBSpeak=False;
}
}
//--------------------------------------------- End Speak
return(0);
}
//+------------------------------------------------- End initStart()
LZ说的很不错 我是来刷分的,嘿嘿 帮帮顶顶!! 谢谢楼主分享 帮你顶下哈!! 学习了,不错 谢谢楼主分享 谢谢楼主分享 {:1_186:}
页:
[1]
2