OBz library of general functions for EA

29 September 2016, 08:50
Sergiy Podolyak
0
45

This is an extract from production version of EAs "Ocean Breeze" and "Graalino-Pro".

This is a library of general functions for any EA.

It is PUBLIC DOMAIN (and free).

Example:

//_____________________________________________________________________________________
//                                                 |                                                                                     |
//                      Get_One_Price   ()         |        
//_________________________________________________|
double Get_One_Price (string    Bond_Name,
                      int       Time_Period,
                      int       Price_Type_Param,
                      int       First_Bar)
{
        double One_Price;
        double Tempo_Array [4];
        double old_open ;
        double old_low ;
        double old_high ;
        double old_close ;
        if ( (Symbol () == Bond_Name) && (Period () == Time_Period) )
        {
                old_open = Open [First_Bar];
                old_low = Low [First_Bar];
                old_high = High [First_Bar];
                old_close = Close [First_Bar];
        }
        else
        {
                old_open = iOpen (Bond_Name, Time_Period, First_Bar);
                old_low = iLow (Bond_Name, Time_Period, First_Bar);
                old_high = iHigh (Bond_Name, Time_Period, First_Bar);
                old_close = iClose (Bond_Name, Time_Period, First_Bar);
        }
        switch (Price_Type_Param)
        {
                case 0:
                        One_Price =  old_close;
                        break;
                case 1:
                        One_Price = old_open ;
                        break;
                case 2:
                        One_Price = old_high;
                        break;
                case 3:
                        One_Price = old_low;
                        break;
                case 4:
                        One_Price = 0.5 * (old_high + old_low) ;                                // median
                        break;
                case 5:
                        One_Price = (old_high + old_low + old_close) / 3.0;   // typical
                        break;
                case 6:
                        One_Price = 0.25 * (old_high + old_low + 2.0 * old_close);   // wighted close
                        break;
                case 7:
                        One_Price = 0.25 * (old_open + old_high + old_low + old_close) ; // Heiken Ashi Close
                        break;
                case 8:
                        Tempo_Array[0] = old_open;
                        Tempo_Array[1] = old_high;
                        Tempo_Array[2] = old_low;
                        Tempo_Array[3] = old_close;
                        ArraySort (Tempo_Array) ;
                        One_Price = 0.5 * (Tempo_Array[1] + Tempo_Array[2]) ;   // Layered median
                        break;
                case 9:                                                         // custom
                        One_Price = 0.20 * (2.5 * old_close + 1.5 * old_open + 0.5 * (old_low + old_high) ) ;
                        break;
                case 10:
                        One_Price = 4.0 / (1.0 / old_open + 1.0 / old_high + 1.0 / old_low + 1.0 / old_close);  // Harm
                        break;
                case 11:
                        One_Price = MathSqrt (MathSqrt (old_open * old_high * old_low * old_close));    // Geom
                        break;
                default:
                        One_Price = 0.5 * (old_open + old_close);               // custom
        }
        return (One_Price);
}
Files:
Share it with friends: