Example #1
0
        /// <summary>
        /// Converts value containing time in seconds that has passed since January 1, 1970, into a string of "yyyy.mm.dd hh:mi" format. 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        protected string TimeToStr(datetime value, int mode = TIME_DATE | TIME_MINUTES)
        {
            var result = new StringBuilder();

            var dateTime = value.DateTime;

            if ((mode & TIME_DATE) != 0)
                result.AppendFormat(dateTime.ToString("yyyy.MM.dd "));

            if ((mode & TIME_SECONDS) != 0)
                result.AppendFormat(dateTime.ToString("hh:mm:ss"));
            else if ((mode & TIME_MINUTES) != 0)
                result.AppendFormat(dateTime.ToString("hh:mm"));

            return result.ToString();
        }
Example #2
0
 public static double Time(Bar bar)
 {
     var time = new datetime(bar.From);
     return time.Value;
 }
Example #3
0
        /// <summary>
        /// Search for bar by open time. The function returns bar shift with the open time specified.
        /// If the bar having the specified open time is missing, the function will return -1 or the nearest bar shift depending on the exact.
        /// </summary>
        /// <param name="symbol">symbol the data of which should be used to calculate indicator; NULL means the current symbol</param>
        /// <param name="timeframe">tt can be any of Timeframe enumeration values; 0 means the current chart timeframe</param>
        /// <param name="time">value to find (bar's open time)</param>
        /// <param name="exact">return mode when bar not found; false - iBarShift returns nearest; true - iBarShift returns -1. </param>
        /// <returns></returns>
        protected int iBarShift(string symbol, int timeframe, datetime time, bool exact = false)
        {
            var shift = -1;
            var result = -1;
            var minimumDelta = int.MaxValue;
            var bars = this.GetBars(symbol, timeframe);
            foreach (var element in bars)
            {
                ++shift;
                var current = (datetime)element.From;
                int delta = Math.Abs(current.Value - time.Value);
                if (delta < minimumDelta)
                {
                    delta = minimumDelta;
                    result = shift;
                }
            }

            if (result == -1)
                return result;

            if (minimumDelta == 0)
                return result;

            if (exact)
                result = -1;

            return result;
        }
Example #4
0
 /// <summary>
 /// The function moves an object coordinate in the chart. Objects can have from one to three coordinates depending on their types. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE. To get the detailed error information, one has to call the GetLastError() function. The object coordinates are numbered starting from 0. 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="point"></param>
 /// <param name="time1"></param>
 /// <param name="price1"></param>
 /// <returns></returns>
 protected bool ObjectMove(string name, int point, datetime time1, double price1)
 {
     throw new NotImplementedException();
 }
Example #5
0
 /// <summary>
 /// Creation of an object with the specified name, type and initial coordinates in the specified window. Count of coordinates related to the object can be from 1 to 3 depending on the object type. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE. To get the detailed error information, one has to call the GetLastError() function. Objects of the OBJ_LABEL type ignore the coordinates. Use the function of ObjectSet() to set up the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.
 /// Notes: The chart sub-windows (if there are sub-windows with indicators in the chart) are numbered starting from 1. The chart main window always exists and has the 0 index.
 /// Coordinates must be passed in pairs: time and price. For example, the OBJ_VLINE object needs only time, but price (any value) must be passed, as well. 
 /// </summary>
 /// <param name="name">Object unique name.</param>
 /// <param name="type">Object type. It can be any of the Object type enumeration values.</param>
 /// <param name="window">Index of the window where the object will be added. Window index must exceed or equal to 0 and be less than WindowsTotal().</param>
 /// <param name="time1">Time part of the first point.</param>
 /// <param name="price1">Price part of the first point.</param>
 /// <param name="time2">Time part of the second point.</param>
 /// <param name="price2">Price part of the second point.</param>
 /// <param name="time3">Time part of the third point.</param>
 /// <param name="price3">Price part of the third point.</param>
 /// <returns></returns>
 protected bool ObjectCreate(string name, int type, int window, datetime time1, double price1,
                             datetime time2 = new datetime(),
                             double price2 = 0, datetime time3 = new datetime(), double price3 = 0)
 {
     throw new NotImplementedException();
 }
Example #6
0
 /// <summary>
 /// Returns the amount of seconds elapsed from the beginning of the minute for the specified time.
 /// </summary>
 /// <param name="time">datetime as number of seconds elapsed since midnight (00:00:00), January 1, 1970</param>
 /// <returns></returns>
 protected int TimeSeconds(datetime time)
 {
     return time.DateTime.Second;
 }
Example #7
0
 /// <summary>
 /// Returns year for the specified date.
 /// </summary>
 /// <param name="time">datetime as number of seconds elapsed since midnight (00:00:00), January 1, 1970</param>
 /// <returns></returns>
 protected int TimeYear(datetime time)
 {
     return time.DateTime.Year;
 }
Example #8
0
 /// <summary>
 /// Returns the minute for the specified time. 
 /// </summary>
 /// <param name="time">datetime as number of seconds elapsed since midnight (00:00:00), January 1, 1970</param>
 /// <returns></returns>
 protected int TimeMinute(datetime time)
 {
     return time.DateTime.Minute;
 }
Example #9
0
 /// <summary>
 /// Returns the month number for the specified time.
 /// </summary>
 /// <param name="time"></param>
 /// <returns></returns>
 protected int TimeMonth(datetime time)
 {
     return time.DateTime.Month;
 }
Example #10
0
 /// <summary>
 /// Returns the hour for the specified time.
 /// </summary>
 /// <param name="time">datetime as number of seconds elapsed since midnight (00:00:00), January 1, 1970</param>
 /// <returns></returns>
 protected int TimeHour(datetime time)
 {
     return time.DateTime.Hour;
 }
Example #11
0
 /// <summary>
 /// Returns day (1 means 1 January,..,365(6) does 31 December) of year for the specified date.
 /// </summary>
 /// <param name="date">datetime as number of seconds elapsed since midnight (00:00:00), January 1, 1970</param>
 /// <returns></returns>
 protected int TimeDayOfYear(datetime date)
 {
     return date.DateTime.DayOfYear;
 }
Example #12
0
 /// <summary>
 /// Returns the zero-based day of week (0 means Sunday,1,2,3,4,5,6) for the specified date.
 /// </summary>
 /// <param name="date">datetime as number of seconds elapsed since midnight (00:00:00), January 1, 1970.</param>
 /// <returns></returns>
 protected int TimeDayOfWeek(datetime date)
 {
     return (int)date.DateTime.DayOfWeek;
 }
Example #13
0
 /// <summary>
 /// Returns day of month (1 - 31) for the specified date.
 /// </summary>
 /// <param name="date">datetime as number of seconds elapsed since midnight (00:00:00), January 1, 1970</param>
 /// <returns></returns>
 protected int TimeDay(datetime date)
 {
     return date.DateTime.Day;
 }
Example #14
0
        /// <summary>
        /// Modification of characteristics for the previously opened position or pending orders.
        /// </summary>
        /// <param name="ticket">unique number of the order ticket</param>
        /// <param name="price">new open price of the pending order</param>
        /// <param name="stoploss">new StopLoss level</param>
        /// <param name="takeprofit">new TakeProfit level</param>
        /// <param name="expiration"></param>
        /// <param name="arrow_color"></param>
        /// <returns></returns>
        protected bool OrderModify(int ticket, double price, double stoploss, double takeprofit, datetime expiration, int arrow_color = CLR_NONE)
        {
            try
            {
                var record = this.TradeRecordFromTicket(ticket);

                var newActivationPrice = price > 0 ? (double?)price : null;
                var newStopLoss = stoploss > 0 ? (double?)stoploss : null;
                var newTakeProfit = takeprofit > 0 ? (double?)takeprofit : null;
                var newExpiration = expiration.Value > 0 ? (DateTime?)expiration.DateTime : null;
                record.Modify(newActivationPrice, newStopLoss, newTakeProfit, newExpiration);

                this.SafeRefreshSnapshot();

                return true;
            }
            catch
            {
                return false;
            }
        }