chart overlay mtf

楼主  收藏   举报   帖子创建时间:  2019-05-05 05:00 回复:0 关注量:705
XAUUSDM30.png

  1. //+------------------------------------------------------------------+
  2. //|                                       MTF_OverLay Chart(yyr).mq4 Ver.1.10 |
  3. //|                                      Copyright?2006-2007 S.B.T. |
  4. //|                                     http://sufx.core.t3-ism.net/ |
  5. //+------------------- DO NOT REMOVE THIS HEADER --------------------+
  6. //|  This script is free to use/distribute/modify and re-distribute. |
  7. //|                                  (Limited to noncommercial use.)
  8. //|  Thank you for S.B.T.,yangelong redited from your OverLay Chart.mq4        
  9. //+------------------------------------------------------------------+

  10. //Indicator Properties
  11. #property copyright "Copyright?2006 S.B.T."
  12. #property link      "http://sufx.core.t3-ism.net/"
  13. #property indicator_chart_window
  14. #property indicator_buffers 4


  15. //Indicator Parameters
  16. extern string SubSymbol = "EURUSD";
  17. extern int    Timeframe=60;
  18. extern color BullBarColor = MediumSeaGreen;
  19. extern color BearBarColor = Orange;
  20. //extern color GridColor = Black;
  21. extern bool Mirroring = false;

  22. //Global Variables
  23. string Prefix; //Indicator Prefix
  24. int Grid = 10; //Grid Lines
  25. int SnapPips = 10;  //Snap Pips For Grid Lines


  26. //Indicator Buffers
  27. double ExtMapBuffer1[];
  28. double ExtMapBuffer2[];
  29. double ExtMapBuffer3[];
  30. double ExtMapBuffer4[];



  31. //+------------------------------------------------------------------+
  32. //| Custom indicator initialization function                         |
  33. //+------------------------------------------------------------------+
  34. int init() {

  35.    //Initialize Indexes
  36.    Prefix = "OverLayChart" + SubSymbol;

  37.    IndicatorShortName( "OverLay Chart( " + SubSymbol + " )" );

  38.    SetIndexBuffer( 0, ExtMapBuffer1 );
  39.    SetIndexBuffer( 1, ExtMapBuffer2 );
  40.    SetIndexBuffer( 2, ExtMapBuffer3 );
  41.    SetIndexBuffer( 3, ExtMapBuffer4 );

  42.    SetIndexStyle( 0, DRAW_HISTOGRAM, DRAW_LINE, 1, BullBarColor );
  43.    SetIndexStyle( 1, DRAW_HISTOGRAM, DRAW_LINE, 1, BearBarColor );
  44.    SetIndexStyle ( 2, DRAW_HISTOGRAM, DRAW_LINE, 2, BullBarColor );
  45.    SetIndexStyle( 3, DRAW_HISTOGRAM, DRAW_LINE, 2, BearBarColor );

  46.    SetIndexEmptyValue( 0, 0.0 );
  47.    SetIndexEmptyValue( 1, 0.0 );
  48.    SetIndexEmptyValue( 2, 0.0 );
  49.    SetIndexEmptyValue( 3, 0.0 );


  50.    return( 0 );
  51. }



  52. //+------------------------------------------------------------------+
  53. //| Custom indicator deinitialization function                       |
  54. //+------------------------------------------------------------------+
  55. int deinit() {
  56.    int _i;
  57.    
  58.    

  59.    //Delete Objects
  60.         ObjectDelete( Prefix + "Status" );
  61.         ObjectDelete( Prefix + "Copyright" );

  62.         for ( _i = 1; _i <= Grid ; _i ++ ) {
  63.            ObjectDelete( Prefix + "Grid" + _i );
  64.            ObjectDelete( Prefix + "Price" + _i );
  65.    }


  66.    return( 0 );
  67. }



  68. //+------------------------------------------------------------------+
  69. //| Custom indicator iteration function                              |
  70. //+------------------------------------------------------------------+
  71. int start() {
  72.    int _BarsCount;
  73.    double _CurRangeHigh, _CurRangeLow, _CurRangeCenter;
  74.    double _SubRangeHigh, _SubRangeLow, _SubRangeCenter;
  75.    double _SubPoint, _SubDigit;
  76.    double _SubOpen, _SubHigh, _SubLow, _SubClose;
  77.    double _PipsRatio;
  78.    double _GridPips, _GridPrice;
  79.    int _i;



  80.    //Initialize Buffers
  81.         RefreshRates();

  82.    ArrayInitialize( ExtMapBuffer1, 0.0 );
  83.    ArrayInitialize( ExtMapBuffer2, 0.0 );
  84.    ArrayInitialize( ExtMapBuffer3, 0.0 );
  85.    ArrayInitialize( ExtMapBuffer4, 0.0 );


  86.    //Calculate Visible Bars
  87.    _BarsCount = BarsPerWindow() + 1;
  88.    int _FirstBar = FirstVisibleBar();
  89.    int _LastBar = _FirstBar - _BarsCount + 1;
  90.    if ( _LastBar < 0 ) {
  91.       _LastBar = 0;
  92.       _BarsCount = _FirstBar + 1;
  93.    }


  94.    //Calculate Chart Ratio
  95.    _CurRangeHigh = High[Highest(NULL, 0, MODE_HIGH, _BarsCount, _LastBar)];
  96.    _CurRangeLow = Low[Lowest(NULL, 0, MODE_LOW, _BarsCount, _LastBar)];
  97.    _CurRangeCenter = ( _CurRangeHigh + _CurRangeLow ) / 2;

  98.    if ( Mirroring ) {
  99.       _SubRangeHigh = iLow( SubSymbol, Timeframe, Lowest( SubSymbol, Timeframe, MODE_LOW, _BarsCount, _LastBar ) );
  100.       _SubRangeLow = iHigh( SubSymbol, Timeframe, Highest( SubSymbol, Timeframe, MODE_HIGH, _BarsCount, _LastBar ) );
  101.    } else {
  102.       _SubRangeHigh = iHigh( SubSymbol, Timeframe, Highest( SubSymbol, Timeframe, MODE_HIGH, _BarsCount, _LastBar ) );
  103.       _SubRangeLow = iLow( SubSymbol, Timeframe, Lowest( SubSymbol, Timeframe, MODE_LOW, _BarsCount, _LastBar ) );
  104.    }

  105.    _SubRangeCenter = ( _SubRangeHigh + _SubRangeLow ) / 2;
  106.    _SubPoint = MarketInfo( SubSymbol, MODE_POINT );
  107.    _SubDigit = MarketInfo( SubSymbol, MODE_DIGITS );

  108.    _PipsRatio = ( _CurRangeHigh - _CurRangeLow )  / ( _SubRangeHigh - _SubRangeLow );

  109.    _GridPips = ( _SubRangeHigh - _SubRangeLow ) / Grid;
  110.    _GridPips = MathRound( ( _SubRangeHigh - _SubRangeLow ) / Grid / ( _SubPoint * SnapPips ) ) * ( _SubPoint * SnapPips );


  111.    //Draw Candlesticks
  112.         for ( _i = _LastBar; _i < _LastBar + _BarsCount; _i ++ ) {
  113.       _SubOpen = iOpen( SubSymbol, Timeframe, _i ) - _SubRangeCenter;
  114.       _SubHigh = iHigh( SubSymbol, Timeframe, _i ) - _SubRangeCenter;
  115.       _SubLow = iLow( SubSymbol, Timeframe, _i ) - _SubRangeCenter;
  116.       _SubClose = iClose( SubSymbol, Timeframe, _i ) - _SubRangeCenter;

  117.       if ( Mirroring ) {
  118.          if ( _SubOpen < _SubClose ) {
  119.             ExtMapBuffer2[_i] = _CurRangeCenter + _SubHigh * _PipsRatio;
  120.             ExtMapBuffer1[_i] = _CurRangeCenter + _SubLow * _PipsRatio;
  121.          } else {
  122.             ExtMapBuffer2[_i] = _CurRangeCenter + _SubLow * _PipsRatio;
  123.             ExtMapBuffer1[_i] = _CurRangeCenter + _SubHigh * _PipsRatio;
  124.          }

  125.          ExtMapBuffer4[_i] = _CurRangeCenter + _SubClose * _PipsRatio;
  126.          ExtMapBuffer3[_i] = _CurRangeCenter + _SubOpen * _PipsRatio;
  127.       } else {
  128.          if ( _SubOpen < _SubClose ) {
  129.             ExtMapBuffer1[_i] = _CurRangeCenter + _SubHigh * _PipsRatio;
  130.             ExtMapBuffer2[_i] = _CurRangeCenter + _SubLow * _PipsRatio;
  131.          } else {
  132.             ExtMapBuffer1[_i] = _CurRangeCenter + _SubLow * _PipsRatio;
  133.             ExtMapBuffer2[_i] = _CurRangeCenter + _SubHigh * _PipsRatio;
  134.          }
  135.          ExtMapBuffer3[_i] = _CurRangeCenter + _SubClose * _PipsRatio;
  136.          ExtMapBuffer4[_i] = _CurRangeCenter + _SubOpen * _PipsRatio;
  137.       }
  138.    }


  139.    return( 0 );
  140. }
  141. //+------------------------------------------------------------------+

打赏