//+------------------------------------------------------------------+
//| MultiBBP.mq4 |
//| zfs |
//| vasbsm@mail.ru |
//+------------------------------------------------------------------+
#property copyright "©zfs"
#property link "vasbsm@mail.ru"
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 Red //USD
#property indicator_color2 SeaGreen //EUR
#property indicator_color3 Lime //GBP
#property indicator_color4 Blue //JPY
#property indicator_color5 BlueViolet //CAD
#property indicator_color6 Gold //AUD
#property indicator_color7 Aqua //NZD
#property indicator_color8 OrangeRed//CHF
extern int BBPeriod=60;
extern int TypeMA=3;
extern int Bars_Count = 1000;//êîë-âî îòîáðàæàåìûõ áàðîâ
extern bool swUSD=true;
extern bool swEUR=true;
extern bool swGBP=true;
extern bool swJPY=true;
extern bool swCAD=true;
extern bool swAUD=true;
extern bool swNZD=true;
extern bool swCHF=true;
extern int Booster_Period=60;//Ðàç â áàð
double BBP_USD[];
double BBP_EUR[];
double BBP_GBP[];
double BBP_JPY[];
double BBP_CAD[];
double BBP_AUD[];
double BBP_NZD[];
double BBP_CHF[];
string short_name;
static int prevtime = 0;int NewPeriod;
int init()
{
IndicatorDigits(5);
if (swUSD)SetIndexStyle(0,DRAW_LINE,0,2);
if (swEUR)SetIndexStyle(1,DRAW_LINE,0,2);
if (swGBP)SetIndexStyle(2,DRAW_LINE,0,2);
if (swJPY)SetIndexStyle(3,DRAW_LINE,0,2);
if (swCAD)SetIndexStyle(4,DRAW_LINE,0,2);
if (swAUD)SetIndexStyle(5,DRAW_LINE,0,2);
if (swNZD)SetIndexStyle(6,DRAW_LINE,0,2);
if (swCHF)SetIndexStyle(7,DRAW_LINE,0,2);
if (swUSD)SetIndexBuffer(0,BBP_USD);
if (swEUR)SetIndexBuffer(1,BBP_EUR);
if (swGBP)SetIndexBuffer(2,BBP_GBP);
if (swJPY)SetIndexBuffer(3,BBP_JPY);
if (swCAD)SetIndexBuffer(4,BBP_CAD);
if (swAUD)SetIndexBuffer(5,BBP_AUD);
if (swNZD)SetIndexBuffer(6,BBP_NZD);
if (swCHF)SetIndexBuffer(7,BBP_CHF);
SetIndexLabel(0,"USD");
SetIndexLabel(1,"EUR");
SetIndexLabel(2,"GBP");
SetIndexLabel(3,"JPY");
SetIndexLabel(4,"CAD");
SetIndexLabel(5,"AUD");
SetIndexLabel(6,"NZD");
SetIndexLabel(7,"CHF");
short_name="Multi BBP 1.4©zfs("+BBPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
return(0);
}
int deinit()
{
ObjectDelete("Calc1");ObjectDelete("Calc2");ObjectDelete("Calc3");
ObjectDelete("SP1");ObjectDelete("SP2");
return(0);
}
int start()
{
//ÑËÅÄÓÞÙÈÉ ÏÅÐÈÎÄ ÎÁÐÀÁÀÒÛÂÀÅÌ
if (iTime(Symbol(),Booster_Period,0)==prevtime) NewPeriod=0;
else{prevtime=iTime(Symbol(),Booster_Period,0);NewPeriod=1;}
if (NewPeriod==1){
int Window=WindowFind(short_name);
int counted_bars=IndicatorCounted();
if(Bars<=BBPeriod) return(0);
//----
int limit=Bars_Count+BBPeriod;
if(counted_bars>0) limit++;
double _eurusd,_gbpusd,_usdjpy,_eurgbp,_usdcad,_audusd,_nzdusd,_eurchf,
_usdchf,_euraud,_gbpaud,_eurnzd,_eurcad,_eurjpy,_gbpjpy,_gbpchf,_gbpcad,
_audjpy,_chfjpy,_nzdjpy,_cadjpy,_audcad,_cadchf,_nzdcad,_audchf,_nzdchf;
for(int i=0; i<limit; i++)
{
_eurusd=iCustom("EURUSD",0,"BBP",BBPeriod,TypeMA,0,i);
_gbpusd=iCustom("GBPUSD",0,"BBP",BBPeriod,TypeMA,0,i);
_audusd=iCustom("AUDUSD",0,"BBP",BBPeriod,TypeMA,0,i);
_nzdusd=iCustom("NZDUSD",0,"BBP",BBPeriod,TypeMA,0,i);
_usdchf=iCustom("USDCHF",0,"BBP",BBPeriod,TypeMA,0,i);
_usdcad=iCustom("USDCAD",0,"BBP",BBPeriod,TypeMA,0,i);
_usdjpy=iCustom("USDJPY",0,"BBP",BBPeriod,TypeMA,0,i)/100;
_euraud=iCustom("EURAUD",0,"BBP",BBPeriod,TypeMA,0,i);
_eurgbp=iCustom("EURGBP",0,"BBP",BBPeriod,TypeMA,0,i);
_eurchf=iCustom("EURCHF",0,"BBP",BBPeriod,TypeMA,0,i);
_eurnzd=iCustom("EURNZD",0,"BBP",BBPeriod,TypeMA,0,i);
_eurcad=iCustom("EURCAD",0,"BBP",BBPeriod,TypeMA,0,i);
_eurjpy=iCustom("EURJPY",0,"BBP",BBPeriod,TypeMA,0,i)/100;
_gbpaud=iCustom("GBPAUD",0,"BBP",BBPeriod,TypeMA,0,i);
_gbpchf=iCustom("GBPCHF",0,"BBP",BBPeriod,TypeMA,0,i);
_gbpcad=iCustom("GBPCAD",0,"BBP",BBPeriod,TypeMA,0,i);
_gbpjpy=iCustom("GBPJPY",0,"BBP",BBPeriod,TypeMA,0,i)/100;
_audjpy=iCustom("AUDJPY",0,"BBP",BBPeriod,TypeMA,0,i)/100;
_chfjpy=iCustom("CHFJPY",0,"BBP",BBPeriod,TypeMA,0,i)/100;
_nzdjpy=iCustom("NZDJPY",0,"BBP",BBPeriod,TypeMA,0,i)/100;
_cadjpy=iCustom("CADJPY",0,"BBP",BBPeriod,TypeMA,0,i)/100;
_audcad=iCustom("AUDCAD",0,"BBP",BBPeriod,TypeMA,0,i);
_cadchf=iCustom("CADCHF",0,"BBP",BBPeriod,TypeMA,0,i);
_nzdcad=iCustom("NZDCAD",0,"BBP",BBPeriod,TypeMA,0,i);
_audchf=iCustom("AUDCHF",0,"BBP",BBPeriod,TypeMA,0,i);
_nzdchf=iCustom("NZDCHF",0,"BBP",BBPeriod,TypeMA,0,i);
if (swUSD)BBP_USD[i]=(-_eurusd-_gbpusd-_audusd-_nzdusd+_usdchf+_usdcad+_usdjpy)/7;
if (swEUR)BBP_EUR[i]=(_eurusd+_euraud+_eurgbp+_eurchf+_eurnzd+_eurcad+_eurjpy)/7;
if (swGBP)BBP_GBP[i]=(_gbpusd+_gbpaud-_eurgbp+_gbpchf+_gbpcad+_gbpjpy)/6;
if (swJPY)BBP_JPY[i]=(-_eurjpy-_audjpy-_gbpjpy-_chfjpy-_nzdjpy-_cadjpy-_usdjpy)/7;
if (swCAD)BBP_CAD[i]=(-_eurcad-_audcad-_gbpcad+_cadchf-_nzdcad-_usdcad+_cadjpy)/7;
if (swAUD)BBP_AUD[i]=(_audusd-_euraud-_gbpaud+_audchf+_audcad+_audjpy)/6;
if (swNZD)BBP_NZD[i]=(_nzdusd+_nzdchf-_eurnzd+_nzdcad+_nzdjpy)/5;
if (swCHF)BBP_CHF[i]=(-_usdchf-_audchf-_gbpchf-_eurchf-_nzdchf-_cadchf+_chfjpy)/7;
}
//----
double SumBBP;
double sMarket=0;
SumBBP=MathAbs(BBP_USD[0])+MathAbs(BBP_EUR[0])+MathAbs(BBP_GBP[0])+MathAbs(BBP_JPY[0])+
MathAbs(BBP_CAD[0])+MathAbs(BBP_AUD[0])+MathAbs(BBP_NZD[0])+MathAbs(BBP_CHF[0]);
sMarket=SumBBP*100;
double mUSD=0,mEUR=0,mGBP=0,mJPY=0,mCAD=0,mAUD=0,mNZD=0,mCHF=0;
for(i=0; i<limit; i++)
{
mUSD+=BBP_USD[i];
mEUR+=BBP_EUR[i];
mGBP+=BBP_GBP[i];
mJPY+=BBP_JPY[i];
mCAD+=BBP_CAD[i];
mAUD+=BBP_AUD[i];
mNZD+=BBP_NZD[i];
mCHF+=BBP_CHF[i];
}
mUSD=mUSD/limit;
mEUR=mEUR/limit;
mGBP=mGBP/limit;
mJPY=mJPY/limit;
mCAD=mCAD/limit;
mAUD=mAUD/limit;
mNZD=mNZD/limit;
mCHF=mCHF/limit;
string _buystr="BUY ",_sellstr="SELL ";
string _buyp="BUY ",_sellp="SELL ";
double P[8];
double M[8];
string S[8]={"USD","EUR","GBP","JPY","CAD","AUD","NZD","CHF"};
double SY[26];
string PA[26]={"EURUSD","GBPUSD","AUDUSD","NZDUSD","USDCHF",//0-4
"USDCAD","USDJPY","EURAUD","EURGBP","EURCHF",//5-9
"EURNZD","EURCAD","EURJPY","GBPAUD","GBPCHF",//10-14
"GBPCAD","GBPJPY","AUDJPY","CHFJPY","NZDJPY",//15-19
"CADJPY","AUDCAD","CADCHF","NZDCAD","AUDCHF",//20-24
"NZDCHF"};//25
if (BBP_USD[0]>0) {P[0]=BBP_USD[0]/SumBBP*200;SY[0]-=P[0];SY[1]-=P[0];SY[2]-=P[0];SY[3]-=P[0];SY[4]+=P[0];SY[5]+=P[0];SY[6]+=P[0];}
if (BBP_USD[0]<0) {M[0]=BBP_USD[0]/SumBBP*200;SY[0]-=M[0];SY[1]-=M[0];SY[2]-=M[0];SY[3]-=M[0];SY[4]+=M[0];SY[5]+=M[0];SY[6]+=M[0];}
if (BBP_EUR[0]>0) {P[1]=BBP_EUR[0]/SumBBP*200;SY[0]+=P[1];SY[7]+=P[1];SY[8]+=P[1];SY[9]+=P[1];SY[10]+=P[1];SY[11]+=P[1];SY[12]+=P[1];}
if (BBP_EUR[0]<0) {M[1]=BBP_EUR[0]/SumBBP*200;SY[0]+=M[1];SY[7]+=M[1];SY[8]+=M[1];SY[9]+=M[1];SY[10]+=M[1];SY[11]+=M[1];SY[12]+=M[1];}
if (BBP_GBP[0]>0) {P[2]=BBP_GBP[0]/SumBBP*200;SY[1]+=P[2];SY[8]-=P[2];SY[13]+=P[2];SY[14]+=P[2];SY[15]+=P[2];SY[16]+=P[2];}
if (BBP_GBP[0]<0) {M[2]=BBP_GBP[0]/SumBBP*200;SY[1]+=M[2];SY[8]-=M[2];SY[13]+=M[2];SY[14]+=M[2];SY[15]+=M[2];SY[16]+=M[2];}
if (BBP_JPY[0]>0) {P[3]=BBP_JPY[0]/SumBBP*200;SY[6]-=P[3];SY[12]-=P[3];SY[16]-=P[3];SY[17]-=P[3];SY[18]-=P[3];SY[19]-=P[3];SY[20]-=P[3];}
if (BBP_JPY[0]<0) {M[3]=BBP_JPY[0]/SumBBP*200;SY[6]-=M[3];SY[12]-=M[3];SY[16]-=M[3];SY[17]-=M[3];SY[18]-=M[3];SY[19]-=M[3];SY[20]-=M[3];}
if (BBP_CAD[0]>0) {P[4]=BBP_CAD[0]/SumBBP*200;SY[5]-=P[4];SY[11]-=P[4];SY[15]-=P[4];SY[20]+=P[4];SY[21]-=P[4];SY[22]+=P[4];SY[23]-=P[4];}
if (BBP_CAD[0]<0) {M[4]=BBP_CAD[0]/SumBBP*200;SY[5]-=M[4];SY[11]-=M[4];SY[15]-=M[4];SY[20]+=M[4];SY[21]-=M[4];SY[22]+=M[4];SY[23]-=M[4];}
if (BBP_AUD[0]>0) {P[5]=BBP_AUD[0]/SumBBP*200;SY[2]+=P[5];SY[7]-=P[5];SY[13]-=P[5];SY[17]+=P[5];SY[21]+=P[5];SY[24]+=P[5];}
if (BBP_AUD[0]<0) {M[5]=BBP_AUD[0]/SumBBP*200;SY[2]+=M[5];SY[7]-=M[5];SY[13]-=M[5];SY[17]+=M[5];SY[21]+=M[5];SY[24]+=M[5];}
if (BBP_NZD[0]>0) {P[6]=BBP_NZD[0]/SumBBP*200;SY[3]+=P[6];SY[10]-=P[6];SY[19]+=P[6];SY[23]+=P[6];SY[25]+=P[6];}
if (BBP_NZD[0]<0) {M[6]=BBP_NZD[0]/SumBBP*200;SY[3]+=M[6];SY[10]-=M[6];SY[19]+=M[6];SY[23]+=M[6];SY[25]+=M[6];}
if (BBP_CHF[0]>0) {P[7]=BBP_CHF[0]/SumBBP*200;SY[4]-=P[7];SY[9]-=P[7];SY[14]-=P[7];SY[18]+=P[7];SY[22]-=P[7];SY[24]-=P[7];SY[25]-=P[7];}
if (BBP_CHF[0]<0) {M[7]=BBP_CHF[0]/SumBBP*200;SY[4]-=M[7];SY[9]-=M[7];SY[14]-=M[7];SY[18]+=M[7];SY[22]-=M[7];SY[24]-=M[7];SY[25]-=M[7];}
int maxP,maxM,maxSY;int w;
w=999;
while (w>0)
{
maxP=ArrayMaximum(P);
if (P[maxP]>0){_buystr=_buystr+S[maxP]+" "+DoubleToStr(P[maxP],1)+" % ";P[maxP]=0;}
else w=0;
}
w=999;
while (w>0)
{
maxM=ArrayMinimum(M);
if (M[maxM]<0){_sellstr=_sellstr+S[maxM]+" "+DoubleToStr(M[maxM],1)+" % ";M[maxM]=0;}
else w=0;
}
w=999;
while (w>0)
{
maxSY=ArrayMaximum(SY);
if (SY[maxSY]>0){_buyp=_buyp+" "+PA[maxSY]+" "+DoubleToStr(SY[maxSY],1);SY[maxSY]=0;}
else w=0;
}
w=999;
while (w>0)
{
maxSY=ArrayMinimum(SY);
if (SY[maxSY]<0){_sellp=_sellp+" "+PA[maxSY]+" "+DoubleToStr(SY[maxSY],1);SY[maxSY]=0;}
else w=0;
}
Label("Calc1",Window,10,18,_buystr,12,Blue);
Label("Calc2",Window,10,36,_sellstr,12,Red);
Label("Calc3",Window,10,54,"Market="+DoubleToStr(sMarket,1),12,Green);
Label("SP1",Window,10,72,_buyp,8,Blue);
Label("SP2",Window,10,90,_sellp,8,Red);
Print (_sellp);
Print (_buyp);
} return(0);
}
//-------------------------------------------------------------------------------------
void Label(string _name,int _window,int _x,int _y,string _text,int _font,color _color)
{
ObjectCreate(_name,OBJ_LABEL,_window,0,0);
ObjectSet(_name,OBJPROP_CORNER,4);
ObjectSet(_name,OBJPROP_XDISTANCE,_x);
ObjectSet(_name,OBJPROP_YDISTANCE,_y);
ObjectSetText(_name,_text,_font,"Arial",_color);
return;
}
//------------------------------------------------------------------------------
Comments