//+------------------------------------------------------------------+ //| OverLayChart.mq4 Ver.1.11 | //| PREV: OverLay Chart.mq4 Ver.1.10 | //| Copyright© 2006-2007 S.B.T. | //| http://sufx.core.t3-ism.net/ | //+------------------- DO NOT REMOVE THIS HEADER --------------------+ //| This script is free to use/distribute/modify and re-distribute. | //| (Limited to noncommercial use.) | //+------------------------------------------------------------------+ #property version "1.11" /* FUTURE POSSIBLE ENHANCEMENTS: NEXT(2022-FEB): Rather than place the Overlay Price-Y-axis centered in the chart, draw a vertical trendline (Ray=off) and allow it to be moved around to choose exactly at what Vertical range (high and low) should the overlay Y-axis be drawn. This is very tricky, however, since merely scrolling back in time, or new bars appearing, will change the axis range and ideal location. It's not worth my time to work on this, as I don't intend to use this overlay tool much! NEXT(2022-FEB): The Overlay price/grid objects will overlap unless further changes made to the code. 2022-FEB-07 Ver.1.11 by pips4life (NO further support; I don't use it much, and I've no interest in further improving this tool!) Derived from: https://www.forexfactory.com/thread/post/3160939#post3160939 Minor changes that improve functionality and code maintainability (IMO). Extern var 'CreatedObjectsSelectable' (false) To prevent accidental selection of most created objects. Exceptions: The UpperLeft OHLC Text, and the LowerRight "Copyright" labels can be selected and moved. The new position(s) will remain until the indy is removed or recompiled. (See OnDeinit). Most created objects are now "Hidden". To see them, in the Ctrl+B Objects list, use "List all" 2006+ Original + various mods. */ //Indicator Properties #property copyright "Orig. Copyright© 2006 S.B.T." #property link "http://sufx.core.t3-ism.net/" #property indicator_chart_window #property indicator_buffers 4 //Indicator Parameters extern string SubSymbol = "USDJPY"; extern color BullBarColor = clrMediumSeaGreen; extern color BearBarColor = clrOrange; extern color GridColor = clrGray; extern bool Mirroring = true; extern bool Price_Level=true; // Your choice of defaults. extern int style_price_level=2; extern int width_price_level=1; extern color color_price_level=clrSilver; extern bool CreatedObjectsSelectable=false; //Global Variables string Prefix; //Indicator Prefix int Grid = 10; //Grid Lines int SnapPips = 10; //Snap Pips For Grid Lines //Indicator Buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //Initialize Indexes Prefix = "OverLayChart" + (int) Mirroring + SubSymbol; IndicatorShortName( "OverLay Chart( " + SubSymbol + " )" ); SetIndexBuffer( 0, ExtMapBuffer1 ); SetIndexBuffer( 1, ExtMapBuffer2 ); SetIndexBuffer( 2, ExtMapBuffer3 ); SetIndexBuffer( 3, ExtMapBuffer4 ); SetIndexStyle( 0, DRAW_HISTOGRAM, DRAW_LINE, 1, BullBarColor ); SetIndexStyle( 1, DRAW_HISTOGRAM, DRAW_LINE, 1, BearBarColor ); SetIndexStyle ( 2, DRAW_HISTOGRAM, DRAW_LINE, 3, BullBarColor ); SetIndexStyle( 3, DRAW_HISTOGRAM, DRAW_LINE, 3, BearBarColor ); SetIndexEmptyValue( 0, 0.0 ); SetIndexEmptyValue( 1, 0.0 ); SetIndexEmptyValue( 2, 0.0 ); SetIndexEmptyValue( 3, 0.0 ); return(INIT_SUCCEEDED); }//end of OnInit() //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //Delete Objects if(reason==REASON_REMOVE || reason==REASON_RECOMPILE) { // The user can move these Texts and they'll stay moved until indicator is removed. ObjectDelete( Prefix + "Copyright" ); ObjectDelete( Prefix + "Status" ); } for ( int _i = 1; _i <= Grid ; _i ++ ) { ObjectDelete( Prefix +"Grid" + _i ); ObjectDelete( Prefix +"Price" + _i ); } ObjectDelete( Prefix +"_price_line"); return; }//end of OnDeinit() //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { string objName; int _BarsCount; double _CurRangeHigh, _CurRangeLow, _CurRangeCenter; double _SubRangeHigh, _SubRangeLow, _SubRangeCenter; double _SubPoint, _SubDigit; double _SubOpen, _SubHigh, _SubLow, _SubClose; double _PipsRatio; double _GridPips, _GridPrice; int _i; //Initialize Buffers RefreshRates(); ArrayInitialize( ExtMapBuffer1, 0.0 ); ArrayInitialize( ExtMapBuffer2, 0.0 ); ArrayInitialize( ExtMapBuffer3, 0.0 ); ArrayInitialize( ExtMapBuffer4, 0.0 ); //Calculate Visible Bars _BarsCount = BarsPerWindow() + 1; int _FirstBar = FirstVisibleBar(); int _LastBar = _FirstBar - _BarsCount + 1; if ( _LastBar < 0 ) { _LastBar = 0; _BarsCount = _FirstBar + 1; } //Calculate Chart Ratio _CurRangeHigh = High[Highest(NULL, 0, MODE_HIGH, _BarsCount, _LastBar)]; _CurRangeLow = Low[Lowest(NULL, 0, MODE_LOW, _BarsCount, _LastBar)]; _CurRangeCenter = ( _CurRangeHigh + _CurRangeLow ) / 2; if ( Mirroring ) { _SubRangeHigh = iLow( SubSymbol, 0, Lowest( SubSymbol, 0, MODE_LOW, _BarsCount, _LastBar ) ); _SubRangeLow = iHigh( SubSymbol, 0, Highest( SubSymbol, 0, MODE_HIGH, _BarsCount, _LastBar ) ); } else { _SubRangeHigh = iHigh( SubSymbol, 0, Highest( SubSymbol, 0, MODE_HIGH, _BarsCount, _LastBar ) ); _SubRangeLow = iLow( SubSymbol, 0, Lowest( SubSymbol, 0, MODE_LOW, _BarsCount, _LastBar ) ); } _SubRangeCenter = ( _SubRangeHigh + _SubRangeLow ) / 2; _SubPoint = MarketInfo( SubSymbol, MODE_POINT ); _SubDigit = MarketInfo( SubSymbol, MODE_DIGITS ); _PipsRatio = ( _CurRangeHigh - _CurRangeLow ) / ( _SubRangeHigh - _SubRangeLow ); _GridPips = ( _SubRangeHigh - _SubRangeLow ) / Grid; _GridPips = MathRound( ( _SubRangeHigh - _SubRangeLow ) / Grid / ( _SubPoint * SnapPips ) ) * ( _SubPoint * SnapPips ); //Draw Candlesticks for ( _i = _LastBar; _i < _LastBar + _BarsCount; _i ++ ) { _SubOpen = iOpen( SubSymbol, 0, _i ) - _SubRangeCenter; _SubHigh = iHigh( SubSymbol, 0, _i ) - _SubRangeCenter; _SubLow = iLow( SubSymbol, 0, _i ) - _SubRangeCenter; _SubClose = iClose( SubSymbol, 0, _i ) - _SubRangeCenter; if ( Mirroring ) { if ( _SubOpen < _SubClose ) { ExtMapBuffer2[_i] = _CurRangeCenter + _SubHigh * _PipsRatio; ExtMapBuffer1[_i] = _CurRangeCenter + _SubLow * _PipsRatio; } else { ExtMapBuffer2[_i] = _CurRangeCenter + _SubLow * _PipsRatio; ExtMapBuffer1[_i] = _CurRangeCenter + _SubHigh * _PipsRatio; } ExtMapBuffer4[_i] = _CurRangeCenter + _SubClose * _PipsRatio; ExtMapBuffer3[_i] = _CurRangeCenter + _SubOpen * _PipsRatio; } else { if ( _SubOpen < _SubClose ) { ExtMapBuffer1[_i] = _CurRangeCenter + _SubHigh * _PipsRatio; ExtMapBuffer2[_i] = _CurRangeCenter + _SubLow * _PipsRatio; } else { ExtMapBuffer1[_i] = _CurRangeCenter + _SubLow * _PipsRatio; ExtMapBuffer2[_i] = _CurRangeCenter + _SubHigh * _PipsRatio; } ExtMapBuffer3[_i] = _CurRangeCenter + _SubClose * _PipsRatio; ExtMapBuffer4[_i] = _CurRangeCenter + _SubOpen * _PipsRatio; } } //Draw Objects objName = Prefix + "Copyright"; if(ObjectCreate( objName, OBJ_LABEL, 0, 0, 0 )) { ObjectSet( objName, OBJPROP_XDISTANCE, 4 ); ObjectSet( objName, OBJPROP_YDISTANCE, 4 ); } //ObjectSetInteger(0,objName,OBJPROP_SELECTABLE,CreatedObjectsSelectable); //NO, allow to be selected and moved! //ObjectSetInteger(0,objName,OBJPROP_HIDDEN,true); ObjectSet( objName, OBJPROP_COLOR, GridColor ); ObjectSet( objName, OBJPROP_CORNER, 3 ); ObjectSetText( objName, "OverLay Chart by S.B.T.", 8 ); objName = Prefix + "Status"; if(ObjectCreate( objName, OBJ_LABEL, 0, 0, 0 )) { ObjectSet( objName, OBJPROP_XDISTANCE, 4 ); ObjectSet( objName, OBJPROP_YDISTANCE, 16 ); } //ObjectSetInteger(0,objName,OBJPROP_HIDDEN,true); ObjectSet( objName, OBJPROP_COLOR, GridColor ); ObjectSet( objName, OBJPROP_CORNER, 0 ); ObjectSetText( objName, SubSymbol + " O = " + DoubleToStr( iOpen( SubSymbol, 0, _LastBar ), _SubDigit ) + ", H = " + DoubleToStr( iHigh( SubSymbol, 0, _LastBar ), _SubDigit ) + ", L = " + DoubleToStr( iLow( SubSymbol, 0, _LastBar ), _SubDigit ) + ", C = " + DoubleToStr( iClose( SubSymbol, 0, _LastBar ), _SubDigit ), 8 ); for ( _i = 1; _i <= Grid ; _i ++ ) { _GridPrice = MathRound( _SubRangeCenter / ( _SubPoint * SnapPips ) ) * ( _SubPoint * SnapPips ); _GridPrice = ( ( _GridPrice + _GridPips / 2 ) + _GridPips * ( Grid / 2 - 1 ) ) - ( _GridPips * ( _i - 1 ) ); objName = Prefix +"Grid"; ObjectCreate( objName + _i, OBJ_TREND, 0, 0, 0 ); ObjectSetInteger(0,objName + _i,OBJPROP_SELECTABLE,CreatedObjectsSelectable); ObjectSetInteger(0,objName + _i,OBJPROP_HIDDEN,true); ObjectSet( objName + _i, OBJPROP_TIME1, Time[_FirstBar] ); ObjectSet( objName + _i, OBJPROP_PRICE1, _CurRangeCenter + ( _GridPrice - _SubRangeCenter ) * _PipsRatio ); ObjectSet( objName + _i, OBJPROP_TIME2, Time[_LastBar] ); ObjectSet( objName + _i, OBJPROP_PRICE2, _CurRangeCenter + ( _GridPrice - _SubRangeCenter ) * _PipsRatio ); ObjectSet( objName + _i, OBJPROP_COLOR, GridColor ); ObjectSet( objName + _i, OBJPROP_STYLE, STYLE_DOT ); ObjectSet( objName + _i, OBJPROP_WIDTH, 1 ); ObjectSet( objName + _i, OBJPROP_RAY, true ); objName = Prefix +"Price"; ObjectCreate( objName + _i, OBJ_TEXT, 0, 0, 0 ); ObjectSetInteger(0,objName + _i,OBJPROP_SELECTABLE,CreatedObjectsSelectable); ObjectSetInteger(0,objName + _i,OBJPROP_HIDDEN,true); ObjectSet( objName + _i, OBJPROP_TIME1, Time[_FirstBar - _BarsCount / 10] ); ObjectSet( objName + _i, OBJPROP_PRICE1, _CurRangeCenter + ( _GridPrice - _SubRangeCenter ) * _PipsRatio ); ObjectSet( objName + _i, OBJPROP_COLOR, GridColor ); ObjectSetText( objName + _i, DoubleToStr( _GridPrice, _SubDigit ), 8 ); ObjectSetInteger(0,objName + _i,OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER); } //------------------ if(Price_Level) { objName = Prefix + "_price_line"; ObjectDelete(objName); ObjectCreate(objName, OBJ_HLINE,0, CurTime(),ExtMapBuffer4[0]); ObjectSetInteger(0,objName,OBJPROP_SELECTABLE,CreatedObjectsSelectable); ObjectSetInteger(0,objName,OBJPROP_HIDDEN,true); ObjectSet(objName,OBJPROP_COLOR,color_price_level); ObjectSet(objName,OBJPROP_STYLE,style_price_level); ObjectSet(objName,OBJPROP_WIDTH,width_price_level); } //------------------ return( 0 ); }//end of start() //+------------------------------------------------------------------+