//+------------------------------------------------------------------+ //| PricePosition.mq4 | //| Copyright 2016, Roberto Jacobs (3rjfx) | //| https://www.mql5.com/en/users/3rjfx | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, Roberto Jacobs (3rjfx) ~ Created: 2016/09/12" #property link "https://www.mql5.com/en/users/3rjfx" #property version "2.00" #property strict #property description "PricePosition indicator provide the position of price in the point of angle" #property description "when the price was rise or down, where the chance to buy or sell." //-- /* Update 1 version "2.00" 18/10/2016 ~ Add display options for corner position, at the LeftHand or at the RightHand ~ Add options to Turn On or Turn Off Alerts */ //-- #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 clrAqua #property indicator_width1 2 //--- enum YN { Yes = 1, No = 0 }; //-- enum corner { RightHand=1, LeftHand=0 }; //--- input corner cor = RightHand; // Corner Position input YN UseAlert = Yes; // Turn On Alert (Yes) or (No) input color BuyColor = clrAqua; // BUY Color input color SellColor = clrOrangeRed; // SELL Color input color clrNT = clrYellow; // No Trend Color //-- //--- buffers double angle[], signal[], media1[], media2[]; //-- string day[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; //-- //-- int xdis=0, ydis=135; //-- color clrfont; //-- int cal, pal, prc, pdn; //-----// //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping IndicatorBuffers(4); //-- SetIndexBuffer(0,angle); SetIndexBuffer(1,signal); SetIndexBuffer(2,media1); SetIndexBuffer(3,media2); //-- SetIndexStyle(0,DRAW_SECTION,STYLE_SOLID); SetIndexStyle(1,DRAW_NONE); SetIndexStyle(2,DRAW_NONE); SetIndexStyle(3,DRAW_NONE); //-- SetIndexLabel(0,"Turn"); SetIndexLabel(1,NULL); SetIndexLabel(2,NULL); SetIndexLabel(3,NULL); //-- IndicatorShortName("PricePosition"); IndicatorDigits(_Digits); //-- xdis=cor==1 ? 133 : 30; //--- //--- return(INIT_SUCCEEDED); } //-----// //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //---- ObjectsDeleteAll(); GlobalVariablesDeleteAll(); //---- return; } //--- //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { //--- int i,limit; limit=rates_total-prev_calculated; if(prev_calculated>0) {limit++;} //-- ArraySetAsSeries(angle,true); ArraySetAsSeries(signal,true); ArraySetAsSeries(media1,true); ArraySetAsSeries(media2,true); ArraySetAsSeries(open,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); //-- for(i=limit-1; i>=0; i--) { media1[i]=iMA(_Symbol,0,26,0,2,4,i); media2[i]=iMA(_Symbol,0,20,0,0,4,i); signal[i]=(media1[i]+media2[i])/2; } //-- for(i=limit-1; i>=0; i--) { if((open[i]<=signal[i])&&(close[i]>=signal[i])) angle[i]=low[i]; else if((open[i]>=signal[i])&&(close[i]<=signal[i])) angle[i]=high[i]; else angle[i]=EMPTY_VALUE; } //-- double priceturn=0.0; int seek=0; int s=0; //-- while(seek<1) { if(angle[s]!=EMPTY_VALUE) { priceturn=angle[s]; seek++; } s++; } //-- //--- //--- Create indicator section angles if(close[0]>priceturn) { CreateLabel(0,"AngleDirection","BUY","Verdana",28,BuyColor,cor,xdis,ydis); CreateLabel(0,"AngleLevel","above "+DoubleToString(priceturn,_Digits),"Verdana",10,BuyColor,cor,xdis,ydis+45); //-- clrfont=BuyColor; cal=1; if((cal!=pal)&&(UseAlert==1)) {Alert("*"+WindowExpertName()+": "+_Symbol+", TF: ",strTF(_Period)+", @ "+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES)+ " --- BUY above --- ",DoubleToString(priceturn,_Digits)); pal=cal;} } else if(close[0]open[0]) {bararw=CharToStr(241); barclr=BuyColor;} else if(close[0]open[0]) { prc=1; if((prc!=pdn)&&(UseAlert==1)) {Alert("*"+WindowExpertName()+": "+_Symbol+", TF: ",strTF(_Period)+", @ "+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES)+ " --- Rising --- "); pdn=prc;} } else if(close[0]