0 Views
0 Downloads
0 Favorites
OD

//OD

#property indicator_chart_window

        //---- input parameters

        extern int Hour_Open = 8;
        extern int AR_Period = 4;
        extern int Bars_In_Window = 28;
        extern color cvet = Black;
        extern int Width_Line = 2;
        int c;

//----------------------------------------------------------

        int init( )
        {

         return( 0 );
        }

//----------------------------------------------------------

        int deinit( )
        {

           for( int d = 0; d <= c; d++ )
           {
            string del1 = "b" + d;
            string del2 = "c" + d;
            ObjectDelete( del1 );
            ObjectDelete( del2 );
           }
         
         Comment( " " );
         
           return( 0 );
        }

//-----------------------------------------------------------

        int start( )
        {

         double open0;
         double h0;
         double l0;
         int e;
         int j;
         int dd;
         int sh;
         double atr;
         double ar1;
         double Sum;
         double max;
         double min;
         double open4;
         int pe = Period( );
         int p; 
         int s = 100 * ( 0.6 * Hour_Open + 0.000166667 ) / pe;
         int i;

         //-------------------------------------------------------------

         for( i = 0; i <= Bars_In_Window - 1; i++ )
         {
          e++;
          c = i;
          string df1 = "b" + i;
          string df2 = "c" + i;
          datetime BarTime = iTime( NULL, PERIOD_D1, i );
          int Bar = iBarShift ( NULL, 0, BarTime, false );

          if( e <= Bars_In_Window )
          {
           open4 = Open[Bar - s];
           
            if( e <= 1 )
            {
             datetime BarTime1 = iTime( NULL, PERIOD_D1, 0 );
             int Bar1 = iBarShift( NULL, 0, BarTime1, false );

             //----------------------------

             if( Bar1 - s < 0 )
             {
              sh = 1;
             }
             else
             {
             if( Bar1 - s >= 0 )
             {
              sh = 0;
             }
             }

             //------------------------------

            } // ãðàíèöà óñëîâèÿ if( e <= 1 )

            //--------------------------------------------------

            datetime day = iTime( NULL, PERIOD_D1, 0 );
            if( BarTime < day )
            {
             dd = Bar - s - PERIOD_D1 / pe;
             j = PERIOD_D1 / pe;
            }
            else
            {
            if( BarTime >= day )
            {
             dd = 0;
             j = Bar - s;
            }
            }

            //-----------------------------------------------------

            if( e > 1 )
            {
             max = High[ iHighest( NULL, 0, MODE_HIGH, j, dd + 1 ) ];
             min = Low[ iLowest( NULL, 0, MODE_LOW, j, dd + 1 ) ];
            }
            else
            {
            if( ( e == 1 ) && ( Bar1 - s > 0 ) )
            {
             max = High[ iHighest( NULL, 0, MODE_HIGH, ( j + 1 ), 0 ) ];
             min = Low[ iLowest( NULL, 0, MODE_LOW, ( j + 1 ), 0 ) ];
            }
            }

            //---------------------------------------------------------

            if( ( Bar1 - s <= 0 ) && ( e == 1 ) )
            {
             max = High[0];
             min = Low[0];
            }

            //---------------------------------------------------------

            if( ( e > sh ) && ( e <= AR_Period + sh ) && ( Bars_In_Window >= AR_Period ) )
            {
             atr = max - min;
             Sum = Sum + atr;
             ar1 = Sum / AR_Period;
            }

            //-----------------------------------------------------------

            if( e == 1 + sh )
            {
             open0 = open4;
             h0 = max;
             l0 = min;
            }

            //----------------------------------------------------------

            //open
            p = 1440 / pe; 
            ObjectCreate( df1, OBJ_TREND, 0, Time[Bar - s], open4, Time[Bar - s + p], open4 );
            ObjectSet( df1, OBJPROP_TIME1, Time[Bar - s] );
            ObjectSet( df1, OBJPROP_TIME2, Time[Bar - s + p] );
            ObjectSet( df1, OBJPROP_PRICE1, open4 );
            ObjectSet( df1, OBJPROP_PRICE2, open4 );
            ObjectSet( df1, OBJPROP_COLOR, cvet ); 
            ObjectSet( df1, OBJPROP_RAY,0 );
            ObjectSet( df1, OBJPROP_WIDTH, Width_Line );
            ObjectSet( df1, OBJPROP_STYLE, 0 );
            ObjectSet( df1, OBJPROP_BACK, 0 );

            //-----------------------------------------------------------

            //max_min
            ObjectCreate( df2, OBJ_TREND, 0, Time[Bar - s], max, Time[Bar - s], min );
            ObjectSet( df2, OBJPROP_TIME1, Time[Bar - s] );
            ObjectSet( df2, OBJPROP_TIME2, Time[Bar - s] );
            ObjectSet( df2, OBJPROP_PRICE1, max );
            ObjectSet( df2, OBJPROP_PRICE2, min );
            ObjectSet( df2, OBJPROP_COLOR, cvet );
            ObjectSet( df2, OBJPROP_RAY, 0 );
            ObjectSet( df2, OBJPROP_WIDTH, Width_Line );
            ObjectSet( df2, OBJPROP_STYLE, 0 );
            ObjectSet( df2, OBJPROP_BACK, 0 );

           //-----------------------------------------------------------

           }  // ãðàíèöà óñëîâèÿ if( e <= Bars_In_Window )

         }  // ãðàíèöà öèêëà for( i = 0; i <= Bars_In_Window - 1; i++ )

         //------------------------------------------------------------

         Comment( "Open:  ",open0,
         "\n","High:  ", h0,
         "\n","Low:  ", l0,
         "\n","Average Range ("+AR_Period+"):  ", NormalizeDouble( ar1, Digits ) / MarketInfo( Symbol( ), MODE_TICKSIZE ) );

         //------------------------------------------------------------




         return( 0 );
         }


Comments