#property copyright "Ajchi" #property link "No Link" #property indicator_chart_window #property indicator_buffers 6 #property indicator_color1 Green #property indicator_color2 Red #property indicator_color3 MediumVioletRed #property indicator_color4 DodgerBlue #property indicator_color5 Bisque #property indicator_color6 DeepPink //extern int takenBars,difference,matching; //----vyrovnávací paměti double buyPB[]; double sellPB[]; double insideBar[]; double arrayGaps[]; double outsideBars[]; double smallSR[]; int startDay=2000; static int prevTime; double dayRange = 0.0; int outsideBarsCount=0; string period=""; //stats variables //+------------------------------------------------------------------+ //| Custom indicator – inicializační funkce | //+------------------------------------------------------------------+ int init() { //----indikátory SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,233); //242 for down arrow SetIndexBuffer(0,buyPB); SetIndexLabel(0,"PB UP"); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,234); //244 for up&down arrow SetIndexBuffer(1,sellPB); SetIndexLabel(1,"PB DOWN"); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,235); //242 for down arrow SetIndexBuffer(2,insideBar); SetIndexLabel(2,"Inside Bar"); /* SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,242); //244 for up&down arrow SetIndexBuffer(3,arrayGaps); SetIndexLabel(3,"PB DOWN"); */ SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,120); //242 for down arrow SetIndexBuffer(3,arrayGaps); SetIndexLabel(3,"GAP"); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,163); //242 for down arrow SetIndexBuffer(4,outsideBars); SetIndexLabel(4,"Outside Bar"); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,163); //242 for down arrow SetIndexBuffer(5,smallSR); SetIndexLabel(5,"Sup-Res"); switch (Period()) { case 60: period="H1"; break; case 240: period="H4"; break; case 1440: period="D1"; break; case 30: period="30m"; break; case 15: period="15m"; break; case 5: period="5m"; break; } ObjectsDeleteAll(0); return(0); } //+------------------------------------------------------------------+ //| Custom indicator – deinicializační funkce | //+------------------------------------------------------------------+ int deinit() { //----- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator – funkce opakování | //+------------------------------------------------------------------+ int start() { string info=""; string time=""; bool addInfo=false; int outsideBarDirection; int hours, min, sec; double gapSize; bool alertOn; int smallSRcount=0; /* min = Time[0] + Period()*60 - TimeCurrent(); sec = min%60; min =(min - min%60) / 60; if(min<60) { time=min + "m " + sec + "s"; } else { hours = MathFloor(min/60); min = min-hours*60; time=hours + "h " + min + "m"; } time = time + ", Spread: "+DoubleToStr(MarketInfo(Symbol(),MODE_SPREAD),0); time = time + ", PV(0.1): "+DoubleToStr(PipValue("USD",Symbol(),10000),2); ObjectCreate("timer_object", OBJ_LABEL, 0, Time[0], 1.1); ObjectSetText( "timer_object", time, 10, "Verdana", Red); ObjectSet("timer_object",OBJPROP_CORNER,1); ObjectSet("timer_object",OBJPROP_XDISTANCE,3); ObjectSet("timer_object",OBJPROP_YDISTANCE,3); AvailableMarkets(); AvoidTradingCorrelatedMarket(); */ if(prevTime==Time[0]) return(0); // Always start at the new bar prevTime=Time[0]; int counted_bars=IndicatorCounted(); if (counted_bars<0) return(-1); if (counted_bars>0) counted_bars--; int pos=Bars-counted_bars; if(pos>20000) pos=20000; alertOn=true; //Comment("counted_bars="+counted_bars+", pos="+pos); //pos=0; int counter=0; //double poslGap=0.0; while(pos>=0 )//&& TimeYear(Time[pos])>startDay { //addInfo=false; if (IsBuyPinbar(dayRange,pos)) { buyPB[pos+1]=Low[pos+1]-dayRange/4.0; if(alertOn&&pos<1) { Alert ("Symbol: ",Symbol()," TimeFrame: ",period," Operace: PinBar BUY Rozsah: ",(High[1]-Low[1])/Point," Cas:",TimeToStr(Time[pos],TIME_DATE|TIME_MINUTES)); PlaySound("alert2.wav"); addInfo=true; } } if (IsSellPinbar(dayRange,pos)) { sellPB[pos+1]=High[pos+1]+dayRange/4.0; if(alertOn&&pos<1) { Alert ("Symbol: ",Symbol()," TimeFrame: ",period," Operace: PinBar SELL Rozsah: ",(High[1]-Low[1])/Point," Cas:",TimeToStr(Time[pos],TIME_DATE|TIME_MINUTES)); PlaySound("alert2.wav"); addInfo=true; } } /* if (IsInsideBar(pos)) { dayRange=AveRange4(pos); insideBar[pos+1]=Low[pos+1]-dayRange/4.0; if(alertOn&&pos<1) { Alert ("Symbol: ",Symbol()," TimeFrame: ",period," Operace: InsideBar Cas:",TimeToStr(Time[pos],TIME_DATE|TIME_MINUTES)); PlaySound("alert2.wav"); } } gapSize=Gap(pos); if (MathAbs(gapSize)>0.0) { if(gapSize>0) arrayGaps[pos]=High[pos]+dayRange/4.0; else arrayGaps[pos+1]=High[pos+1]+dayRange/4.0; //counter++; if(alertOn&&pos<1) { Alert ("Symbol: ",Symbol()," TimeFrame: ",period," Operace: GAP Cas:",TimeToStr(Time[pos],TIME_DATE|TIME_MINUTES)); PlaySound("alert2.wav"); } } outsideBarDirection=IsOutsideBar(pos); if (outsideBarDirection!=0) { if(outsideBarDirection==1) outsideBars[pos+1]=Low[pos+1]-dayRange/3.5; else outsideBars[pos+1]=High[pos+1]+dayRange/3.5; if(alertOn&&pos<1) { Alert ("Symbol: ",Symbol()," TimeFrame: ",period," Operace: OutSide Bar Rozsah:",(High[1]-Low[1])/Point," Cas:",TimeToStr(Time[pos],TIME_DATE|TIME_MINUTES)); PlaySound("alert2.wav"); } } if(IsSmallBuySR(pos))//IsSmallSR(int pos, int takenBars,int difference,int matching) { // if(iMA(NULL,0,50,0,0,0,pos)-iMA(NULL,0,50,0,0,0,pos+20)>40*Point &&iRSI(NULL,0,7,6,pos)<40) //{ smallSR[pos]=High[pos]+dayRange/5; smallSRcount++; // } } if(IsSmallSellSR(pos))//IsSmallSR(int pos, int takenBars,int difference,int matching) { // if(iMA(NULL,0,50,0,0,0,pos)-iMA(NULL,0,50,0,0,0,pos+20)<-40*Point &&iRSI(NULL,0,7,6,pos)>60) // { smallSRcount++; smallSR[pos]=Low[pos]-dayRange/5; // } } if (addInfo) { info=info+" Max. Lot size: "+DoubleToStr(LotSize(High[1]-Low[1]),1); } */ pos--; } //double cor=2.3; //DrawLines(11); //AvoidTradingCorrelatedMarket(); //AvailableMarkets(); //double cor = Correl("NZDUSD", Symbol(), 1440, 6); //Comment("Pocet smallSRcount: ",pos);//, " Kor: ",cor return(0); } //+------------------------------------------------------------------+ //| User function AveRange4 | //+------------------------------------------------------------------+ double AveRange4(int pos) { double sum; double rangeSerie[4]; int i=0; int ind=1; int startYear=1995; int den; if(pos<=0)den=1; else den = pos; if (TimeYear(Time[den-1])>=startYear) { while (i<4) { //datetime pok=Time[pos+ind]; if(TimeDayOfWeek(Time[pos+ind])!=0) { sum+=High[pos+ind]-Low[pos+ind];//make summation i++; } ind++; //i++; } //Comment(sum/4.0); return (sum/4.0);//make average, don't count min and max, this is why I divide by 4 and not by 6 } return (50*Point); }//------------END FUNCTION------------- //+------------------------------------------------------------------+ //| User function IsPinbar | //+------------------------------------------------------------------+ bool IsBuyPinbar(double& dayRange, int pos) { //start of declarations double actOp,actCl,actHi,actLo,preHi,preLo,preCl,preOp,actRange,preRange,actHigherPart,actHigherPart1; actOp=Open[pos+1]; actCl=Close[pos+1]; actHi=High[pos+1]; actLo=Low[pos+1]; preOp=Open[pos+2]; preCl=Close[pos+2]; preHi=High[pos+2]; preLo=Low[pos+2]; //SetProxy(preHi,preLo,preOp,preCl);//Check proxy actRange=actHi-actLo; preRange=preHi-preLo; actHigherPart=actHi-actRange*0.4;//helping variable to not have too much counting in IF part actHigherPart1=actHi-actRange*0.4;//helping variable to not have too much counting in IF part //end of declaratins //start function body dayRange=AveRange4(pos); if((actCl>actHigherPart1&&actOp>actHigherPart)&& //Close&Open of PB is in higher 1/3 of PB (actRange>dayRange*0.5)&& //PB is not too small //(actHi<(preHi-preRange*0.3))&& //High of PB is NOT higher than 1/2 of previous Bar (actLo+actRange*0.25Low[pos+1]) return (true); } return(false); }//------------END FUNCTION------------- bool IsSellPinbar(double& dayRange, int pos) { //start of declarations double actOp,actCl,actHi,actLo,preHi,preLo,preCl,preOp,actRange,preRange,actLowerPart, actLowerPart1; actOp=Open[pos+1]; actCl=Close[pos+1]; actHi=High[pos+1]; actLo=Low[pos+1]; preOp=Open[pos+2]; preCl=Close[pos+2]; preHi=High[pos+2]; preLo=Low[pos+2]; //SetProxy(preHi,preLo,preOp,preCl);//Check proxy actRange=actHi-actLo; preRange=preHi-preLo; actLowerPart=actLo+actRange*0.4;//helping variable to not have too much counting in IF part actLowerPart1=actLo+actRange*0.4;//helping variable to not have too much counting in IF part //end of declaratins //start function body dayRange=AveRange4(pos); if((actCldayRange*0.5)&& //PB is not too small //(actLo>(preLo+preRange/3.0))&& //Low of PB is NOT lower than 1/2 of previous Bar (actHi-actRange*0.25>preHi)) //Nose of the PB is at least 1/3 lower than previous bar { if(High[ArrayMaximum(High,3,pos+3)]=Low[takenDays[1]]&&Low[takenDays[1]]>=Low[takenDays[2]]) if (High[takenDays[0]]<=High[takenDays[1]]&&High[takenDays[1]]<=High[takenDays[2]]) return (true); } else { if(Low[pos+1]>=Low[pos+2]&&Low[pos+2]>=Low[pos+3]) if (High[pos+1]<=High[pos+2]&&High[pos+2]<=High[pos+3]) return (true); } return (false); } //+------------------------------------------------------------------+ //| User function IsOutsideBar - average gap size | //+------------------------------------------------------------------+ int IsOutsideBar(int pos) { int i = 0; // int x = 0; // int diff = 1; if(TimeDayOfWeek(Time[pos+2])!=0) // return (0); if(Low[pos+2]>=Low[pos+1]&&High[pos+2]<=High[pos+1]) { if(Open[pos+1]High[pos+2]) return (1); else if(Open[pos+1]>Close[pos+1]&&Close[pos+1]difference+1) return (false); } return(false); } //------------END FUNCTION------------- //+------------------------------------------------------------------+ //| User function IsSmallSellSR - SR levels | //+------------------------------------------------------------------+ bool IsSmallSellSR(int pos) { int countMatching,ind,takenBars,difference,matching; if (TimeDayOfWeek(Time[pos])==0) return(false); if(takenBars==0) { switch(Period()) { case 1440: takenBars=6;difference=6;matching=3; break; case 240: takenBars=4;difference=4;matching=3; break; case 60: takenBars=4;difference=2;matching=3; break; } } double refLow=Low[pos]; for(int i=0;idifference+1) return (false); } return(false); } //------------END FUNCTION------------- //+------------------------------------------------------------------+ //| User function Gaps - average gap size | //+------------------------------------------------------------------+ double Gap (int pos) { int startYear=2000; double gap; if (TimeYear(Time[pos])>=startYear) { if (Close[pos+1]!=Open[pos]) { gap=(Close[pos+1]-Open[pos])/Point; if(MathAbs(gap) > 40.0) { return (gap); } else return (0.0); } } else return (0.0); } void DrawLines(int numberOfLines) { double prices[10]; //nejde nadefinovat jako numberOfLines double closestPrice, startPrice,roundedPrice; int base4digits=100; int base2digits=100; if (MathMod(numberOfLines,2)==0) numberOfLines++; if (Symbol()=="GBPUSD"||Period()==1440) base4digits=1000; if(Digits==4) //pro 4 ciferne trhy { closestPrice=MathRound(Ask*base4digits)/base4digits; if (Symbol()=="GBPUSD"||Period()==1440) closestPrice=MathRound(Ask*10)/10; roundedPrice=numberOfLines/2*base4digits*Point+closestPrice; for (int i=0;i=0.75 || MathAbs(monthly)>=0.75)&&weekly*monthly>0.0)// { avoidMarkets=avoidMarkets+orderSymbol+":W"+DoubleToStr(weekly,2)+"M"+DoubleToStr(monthly,2)+" "; output=true; } /* else { FileDelete(orderSymbol+"AvoidCorrel"); } */ } } //output=true; if(output) { //avoidMarkets="Korelace:"+avoidMarkets; ObjectCreate("avoid_object", OBJ_LABEL, 1, Time[0], 1.1); ObjectSetText( "avoid_object", avoidMarkets, 9, "Verdana", DeepPink); /* if(Period()==1440) { handle=FileOpen(Symbol()+"AvoidCorrel", FILE_WRITE); if(handle>0) { FileWrite(handle, avoidMarkets); FileClose(handle); } ObjectSetText( "avoid_object", avoidMarkets, 9, "Verdana", DeepPink); } else { handle=FileOpen(Symbol()+"AvoidCorrel", FILE_READ); if(handle>0) { avoidMarkets=FileReadString(handle); FileClose(handle); ObjectSetText( "avoid_object", avoidMarkets, 9, "Verdana", DeepPink); } else ObjectSetText( "avoid_object", "Null", 9, "Verdana", DeepPink); }*/ ObjectSet("avoid_object",OBJPROP_CORNER,2); ObjectSet("avoid_object",OBJPROP_XDISTANCE,3); ObjectSet("avoid_object",OBJPROP_YDISTANCE,3); //ObjectSetText( "avoid_object", "EURCAD: W-0.22 M0.70>> NZDUSD: W0.96 M0.96>> USDCHF: W-0.72 M-0.63>> ", 9, "Verdana", DeepPink); }// else ObjectDelete("avoid_object"); }//------------END FUNCTION------------- void AvailableMarkets() { int total=OrdersTotal(); int handle; //for file string actMarkets, prevMarkets; double weekly,monthly; string orderSymbol; string tradedMarkets[]={"EURCHF","AUDUSD","USDCZK","USDCAD","EURUSD","GBPUSD","EURJPY","USDJPY","USDCHF","EURCAD","EURCZK","AUDJPY","NZDUSD","EURGBP"}; int marketCount=ArraySize(tradedMarkets); int index=0; if(total==0) actMarkets="ALL "; else { for(int pos=0;pos0) { FileWrite(fileHandle,); FileWrite(fileHandle,0,1,2,3,4,5); FileWrite(fileHandle,0,1,2,3,4,5); FileWrite(fileHandle,0,1,2,3,4,5); FileClose(fileHandle); } }//------------END FUNCTION------------- */