java.lang.Object
com.motivewave.platform.sdk.common.Util

public class Util extends Object
This class provides a set of utility methods
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final long
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Color
    adjustColor(Color c, double factor)
    Brightens or darkens the give color by the given percent factor
    static Color
    awtColor(int r, int g, int b)
     
    static Color
    awtColor(int r, int g, int b, int alpha)
     
    static void
    calcLatestMA(DataContext ctx, Enums.MAMethod method, Object input, int period, int shift, Object valKey, boolean fillForward)
    This convenience method updates the calculates a moving average of the current (latest) bar in the data series and stores it in the internal data cache with key specified (@see valKey)
    static void
    calcMAAt(int index, DataContext ctx, Enums.MAMethod method, Object input, int period, int shift, Object valKey)
    This convenience method calculates the moving average at the given index in the data series and stores it in the internal data cache with key specified (@see valKey)
    static void
    calcSeriesMA(DataContext ctx, Enums.MAMethod method, Object input, int period, int shift, Object valKey, boolean fillForward)
    This convenience method calculates a moving average for the visible bars in the data series and stores it in the internal data cache with key specified (@see valKey)
    static void
    calcSeriesMA(DataContext ctx, Enums.MAMethod method, Object input, int period, int shift, Object valKey, boolean fillForward, boolean includeUnfinishedBars)
    This convenience method calculates a moving average for the visible bars in the data series and stores it in the internal data cache with key specified (@see valKey)
    static double
    calculateAngle(double x1, double y1, double x2, double y2)
    Calculates the angle (in radians) between the two given points.
    static double
    Calculates the angle (in radians) between the two given points.
    static double
    calculateAngle(Point2D origin, Point2D end1, Point2D end2)
    Calculates the angle (in radians) between the two given points.
    static Line2D
    clipLine(double x1, double y1, double x2, double y2, Rectangle2D bounds)
     
    static Line2D
    clipLine(Line2D line, Rectangle2D bounds)
     
    static Line2D
    clipLine(Point2D p1, Point2D p2, Rectangle2D bounds)
    Clips the line defined by the two given points to the bounds.
    static final boolean
    Compares the two objects.
    static Path2D
    createDownTriangle(int x, int y, int d)
    Creates a triangle path pointing down.
    static Path2D
    createUpTriangle(int x, int y, int d)
    Creates a triangle path pointing up.
    static double
    degreesToRadians(double degree)
    Converts the given value in degrees to radians.
    static double
    distance(double ux, double uy, double vx, double vy)
     
    static double
    distance(Point2D p1, int x, int y)
     
    static double
    Calculates and returns the distance between the two points.
    static double
    distanceFromLine(double x, double y, double lx1, double ly1, double lx2, double ly2)
    Calculates distance from the given line.
    static double
    distanceFromLine(double x, double y, Line2D line)
    Calculates distance from the given line.
    static double
    dot(double ux, double uy, double vx, double vy)
     
    static int
    findNearest(List<Bar> data, long start_time)
    Finds the index of the bar that is nearest to the given start time.
    static <T> T
    first(List<T> list)
    Gets the first element from the list (null if the list is null or empty).
    static final String
    formatDouble(double val, int places)
    Formats a double number to the given number of places
    static final String
    formatFloat(float val, int places)
    Formats a float number to the given number of places
    static String
    formatMK(double val)
    Formats the double value as a string
    static String
    formatMK(float val)
    Formats the given value to shorten the display be using T - trillions, B - billions, M - millions, K - thousands
    static String
    formatMK(long val)
    Formats the float value as a string
    static String
    formatMMDDYYYY(long date)
    Formats the given date (in milliseconds since 1970) in MM/dd/yyyy format.
    static String
    formatMMDDYYYY(long date, TimeZone tz)
    Formats the given date (in milliseconds since 1970) in MM/dd/yyyy format.
    static String
    formatMMDDYYYYHHMM(long date)
    Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm a format.
    static String
    formatMMDDYYYYHHMM(long date, TimeZone tz)
    Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm a format.
    static String
    Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm:ss a format.
    static String
    Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm:ss.ZZZ a format.
    static String
    Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm:ss.ZZZ a format.
    static final Color
     
    static final Color
    getAlphaFill(Color c, int alpha)
     
    static long
    getEndOfBar(long start, long end, Instrument instr, BarSize bs, boolean rth)
    Calculates the end of the bar taking into account regular vs extended trading hours.
    static File
    Gets the extensions directory.
    Gets the font metrics for the given font.
    static long
    getMidnight(long time)
    Gets the time in millis as of midnight on the morning of the specified date
    static long
    getMidnight(long time, TimeZone tz)
    Gets the time in millis as of midnight on the morning of the specified date
    static long
    getMidnight(Calendar cal, long time)
    Gets the time in millis as of midnight on the morning of the specified date
    static long
    getMidnightEST(long time)
    Gets the time in millis as of midnight on the morning of the specified date
    static long
    getMidnightGMT(long time)
    Gets the time in millis as of midnight on the morning of the specified date
    static long
    getNextDayMidnight(long time)
    Gets the time in millis as of midnight on the morning of the specified date + 1 day (accounting for DST)
    static long
    getNextDayMidnight(long time, TimeZone tz)
     
    static long
    getStartOfBar(long start, long end, Instrument instr, BarSize bs, boolean rth)
    Calculates the start of the bar taking into account regular vs extended trading hours.
    static long
    getStartOfNextDay(long time, Instrument instr, boolean rth)
    Gets the start of the next trading day (accounting for the weekend)
    static long
    getStartOfNextMonth(long time, Instrument instr, boolean rth)
    Gets the start of the next trading month
    static long
    getStartOfNextWeek(long time, Instrument instr, boolean rth)
    Gets the start of the next trading week
    static long
    getStartOfNextYear(long time, Instrument instr, boolean rth)
    Gets the start of the next trading year
    static long
    getStartOfPrevDay(long time, Instrument instr, boolean rth)
    Gets the start of the previous trading day (accounting for the weekend)
    static long
    getStartOfPrevMonth(long time, Instrument instr, boolean rth)
    Gets the start of the previous trading month
    static long
    getStartOfPrevWeek(long time, Instrument instr, boolean rth)
    Gets the start of the previous trading week
    static long
    getStartOfPrevYear(long time, Instrument instr, boolean rth)
    Gets the start of the previous year
    static final Stroke
    getStroke(PathInfo path, boolean selected)
     
    static final boolean
    in(double i, double[] list)
    Determines if the given double value i is in the list of double values.
    static final boolean
    in(int i, int[] list)
    Returns true if the number i is in the search list
    static final boolean
    in(Object o, Object... list)
    Returns true if the Object o is in the search list
    static final boolean
    in(String s, String... list)
    Returns true if the String s is present in the list
    static Point2D
    intersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
    Computes the intersection between two segments.
    static Point2D
    intersection(Line2D line1, Line2D line2)
    computes the intersection point between the two given lines.
    static Point2D
    intersection(Point2D start1, Point2D end1, Point2D start2, Point2D end2)
    Computes the intersection point between the two lines defined by the pairs of start and end points.
    static final boolean
    Tests if an object is empty or null.
    static <T> T
    last(List<T> list)
    Gets the last element from the list (null if the list is null or empty).
    static double[]
    Determines the coefficients m and b for the least squares method of linear regression (y = mx + b).
    static <T> List<T>
    list(T... items)
    Creates a list from the variable argument list.
    static double
    max(double... args)
     
    static double
    max(double someNumber, double someOtherNumber)
    Returns the greater number between someNumber and someOtherNumber.
    static int
    max(int someNumber, int someOtherNumber)
    Returns the greater number between someNumber and someOtherNumber.
    static Double
    maxDouble(Double... args)
     
    static float
    maxFloat(float... args)
     
    static int
    maxInt(int... args)
     
    static long
    maxLong(long... args)
     
    static Point2D
    Calculates and returns the midpoint of the given line.
    static Point2D
    midpoint(Point2D start, Point2D end)
    Calculates and returns the midpoint of the line defined by the given points.
    static double
    min(double... args)
     
    static Double
    minDouble(Double... args)
     
    static float
    minFloat(float... args)
     
    static int
    minInt(int... args)
     
    static long
    minLong(long... args)
     
    static double
    norm(double vx, double vy)
     
    static double
    radiansToDegrees(double rad)
    Converts the given value in radians to degrees.
    static final String
    replace(String source, String[] patterns, String[] replacements)
    Replaces occurences of the given pattern in the source string with the replacement value.
    static final void
    replaceAll(Writer out, String source, String[] patterns, Object[] replacements)
    Takes a collection of patterns (no support for regex), replacements and a target string.
    static final String
    replaceAll(String source, String[] patterns, Object[] replacements)
    Takes a collection of patterns (no support for regex), replacements and a target string.
    static final String
    replaceAll(String source, String[] patterns, String[] replacements)
    Takes a collection of patterns (no support for regex), replacements and a target string.
    static <T> Iterable<T>
    reverse(List<T> list)
    Returns an Iterable object for iterating through a list in reverse order.
    static double[]
    rotate(double[] points, double radians)
    Rotates the given array of points and returns the result in a new array.
    static Point2D
    rotate(double x, double y, double cx, double cy, double radians)
    Rotates the given point p about the given origin.
    static Point2D
    rotate(Point2D p, Point2D origin, double radians)
    Rotates the given point p about the given origin.
    static double
    round(double val, double step)
    Rounds a double value using the given step (minimum value).
    static double
    round(double val, int places)
    Round a double value to a specified number of decimal places.
    static float
    round(float val, float step)
    Rounds a double value using the given step (minimum value).
    static float
    round(float val, int places)
    Round a double value to a specified number of decimal places.
    static double
    roundDouble(double val, int places)
    Round a double value to a specified number of decimal places.
    static long
    roundHour(long time)
    Gets the current date/time rounded down to the current hour.
    static long
    roundMinutes(long time, int minutes)
    Gets the current date/time rounded down to the current minute.
    static void
    Executes the given task on a background thread.
    static double
    slope(double xl, double yl, double xr, double yr)
    Calculates the slope for the line defined by the given points.
    static double
    slope(Line2D line)
    Calculates the slope for the given line.
    static double
    slope(Point2D start, Point2D end)
    Calculates the slope for the line defined by the given points.
    static int
    strWidth(String str, Font font)
    Calculates and returns the width of a the given string (in pixels) using the given font.
    static final double
    Converts the given object to an double.
    static final double
    toDouble(Object value, double def)
     
    static final double
     
    static final int
    toInt(Object value)
    Converts the given object to an int.
    static List<String>
    tokenize(String str, char sep)
    Splits the given string into tokens using the given separator character

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Util

      public Util()
  • Method Details

    • list

      @SafeVarargs public static <T> List<T> list(T... items)
      Creates a list from the variable argument list.
    • first

      public static <T> T first(List<T> list)
      Gets the first element from the list (null if the list is null or empty).
    • last

      public static <T> T last(List<T> list)
      Gets the last element from the list (null if the list is null or empty).
    • findNearest

      public static int findNearest(List<Bar> data, long start_time)
      Finds the index of the bar that is nearest to the given start time.
      Parameters:
      data - list of bars
      start_time - start time in milliseconds since 1970
      Returns:
      index of the bar in the last (-1 if not found)
    • tokenize

      public static List<String> tokenize(String str, char sep)
      Splits the given string into tokens using the given separator character
      Parameters:
      str - string to tokenize
      sep - character that separates the tokens
      Returns:
      tokenized list (excluding separator characters)
    • schedule

      public static void schedule(Runnable task)
      Executes the given task on a background thread.
      Parameters:
      task - runnable task to be executed on a background thread
    • awtColor

      public static Color awtColor(int r, int g, int b)
    • awtColor

      public static Color awtColor(int r, int g, int b, int alpha)
    • adjustColor

      public static Color adjustColor(Color c, double factor)
      Brightens or darkens the give color by the given percent factor
      Parameters:
      c - color to adjust
      factor - percentage factor to adjust. Negative value darkens the color
    • getFontMetrics

      public static FontMetrics getFontMetrics(Font font)
      Gets the font metrics for the given font.
    • getStartOfBar

      public static long getStartOfBar(long start, long end, Instrument instr, BarSize bs, boolean rth)
      Calculates the start of the bar taking into account regular vs extended trading hours. For intraday bars, this will simply return the start of the bar. For daily+ bars this will calculate the start of the day/week/month
      Parameters:
      start - start time for the bar
      end - end time for the bar
      instr - instrument
      bs - bar size
      rth - regular trading hours vs extended trading hours
      Returns:
      start time of the bar in milliseconds since 1970
    • getStartOfNextDay

      public static long getStartOfNextDay(long time, Instrument instr, boolean rth)
      Gets the start of the next trading day (accounting for the weekend)
      Parameters:
      time - time in milliseconds since 1970
      instr - instrument
      rth - regular trading hours vs extended trading hours
    • getStartOfNextWeek

      public static long getStartOfNextWeek(long time, Instrument instr, boolean rth)
      Gets the start of the next trading week
      Parameters:
      time - time in milliseconds since 1970
      instr - instrument
      rth - regular trading hours vs extended trading hours
    • getStartOfNextMonth

      public static long getStartOfNextMonth(long time, Instrument instr, boolean rth)
      Gets the start of the next trading month
      Parameters:
      time - time in milliseconds since 1970
      instr - instrument
      rth - regular trading hours vs extended trading hours
    • getStartOfNextYear

      public static long getStartOfNextYear(long time, Instrument instr, boolean rth)
      Gets the start of the next trading year
      Parameters:
      time - time in milliseconds since 1970
      instr - instrument
      rth - regular trading hours vs extended trading hours
    • getStartOfPrevDay

      public static long getStartOfPrevDay(long time, Instrument instr, boolean rth)
      Gets the start of the previous trading day (accounting for the weekend)
      Parameters:
      time - time in milliseconds since 1970
      instr - instrument
      rth - regular trading hours vs extended trading hours
    • getStartOfPrevMonth

      public static long getStartOfPrevMonth(long time, Instrument instr, boolean rth)
      Gets the start of the previous trading month
      Parameters:
      time - time in milliseconds since 1970
      instr - instrument
      rth - regular trading hours vs extended trading hours
    • getStartOfPrevYear

      public static long getStartOfPrevYear(long time, Instrument instr, boolean rth)
      Gets the start of the previous year
      Parameters:
      time - time in milliseconds since 1970
      instr - instrument
      rth - regular trading hours vs extended trading hours
    • getStartOfPrevWeek

      public static long getStartOfPrevWeek(long time, Instrument instr, boolean rth)
      Gets the start of the previous trading week
      Parameters:
      time - time in milliseconds since 1970
      instr - instrument
      rth - regular trading hours vs extended trading hours
    • getEndOfBar

      public static long getEndOfBar(long start, long end, Instrument instr, BarSize bs, boolean rth)
      Calculates the end of the bar taking into account regular vs extended trading hours. For intraday bars, this will simply return the end of the bar. For daily+ bars this will calculate the end of the day/week/month
      Parameters:
      start - start time for the bar
      end - end time for the bar
      instr - instrument
      bs - bar size
      rth - regular trading hours vs extended trading hours
      Returns:
      end time of the bar in milliseconds since 1970
    • strWidth

      public static int strWidth(String str, Font font)
      Calculates and returns the width of a the given string (in pixels) using the given font.
    • getExtensionsDirectory

      public static File getExtensionsDirectory()
      Gets the extensions directory.
    • round

      public static double round(double val, int places)
      Round a double value to a specified number of decimal places.
      Parameters:
      val - the value to be rounded.
      places - the number of decimal places to round to.
      Returns:
      val rounded to places decimal places.
    • round

      public static double round(double val, double step)
      Rounds a double value using the given step (minimum value).
      Parameters:
      val - value to round
      step - minimum value to round
      Returns:
      rounded value (using the minimum step)
    • round

      public static float round(float val, int places)
      Round a double value to a specified number of decimal places.
      Parameters:
      val - the value to be rounded.
      places - the number of decimal places to round to.
      Returns:
      val rounded to places decimal places.
    • round

      public static float round(float val, float step)
      Rounds a double value using the given step (minimum value).
      Parameters:
      val - value to round
      step - minimum value to round
      Returns:
      rounded value (using the minimum step)
    • createDownTriangle

      public static Path2D createDownTriangle(int x, int y, int d)
      Creates a triangle path pointing down.
      Parameters:
      x - x coordinate
      y - y coordinate
      d - size of the triangle
    • createUpTriangle

      public static Path2D createUpTriangle(int x, int y, int d)
      Creates a triangle path pointing up.
      Parameters:
      x - x coordinate
      y - y coordinate
      d - size of the triangle
    • intersection

      public static Point2D intersection(Point2D start1, Point2D end1, Point2D start2, Point2D end2)
      Computes the intersection point between the two lines defined by the pairs of start and end points.
      Parameters:
      start1 - start point of the first line.
      end1 - end point of the first line.
      start2 - start point of the second line
      end2 - end point of the second line
      Returns:
      intersection point between the lines
    • intersection

      public static Point2D intersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
      Computes the intersection between two segments.
      Parameters:
      x1 - Starting point of Segment 1
      y1 - Starting point of Segment 1
      x2 - Ending point of Segment 1
      y2 - Ending point of Segment 1
      x3 - Starting point of Segment 2
      y3 - Starting point of Segment 2
      x4 - Ending point of Segment 2
      y4 - Ending point of Segment 2
      Returns:
      Point where the segments intersect, or null if they don't
    • intersection

      public static Point2D intersection(Line2D line1, Line2D line2)
      computes the intersection point between the two given lines.
    • clipLine

      public static Line2D clipLine(Point2D p1, Point2D p2, Rectangle2D bounds)
      Clips the line defined by the two given points to the bounds. Uses the Cohen Sutherland Line algorithm.
    • clipLine

      public static Line2D clipLine(double x1, double y1, double x2, double y2, Rectangle2D bounds)
    • clipLine

      public static Line2D clipLine(Line2D line, Rectangle2D bounds)
    • rotate

      public static double[] rotate(double[] points, double radians)
      Rotates the given array of points and returns the result in a new array.
    • midpoint

      public static Point2D midpoint(Line2D line)
      Calculates and returns the midpoint of the given line.
    • midpoint

      public static Point2D midpoint(Point2D start, Point2D end)
      Calculates and returns the midpoint of the line defined by the given points.
    • rotate

      public static Point2D rotate(Point2D p, Point2D origin, double radians)
      Rotates the given point p about the given origin.
    • rotate

      public static Point2D rotate(double x, double y, double cx, double cy, double radians)
      Rotates the given point p about the given origin.
    • slope

      public static double slope(Line2D line)
      Calculates the slope for the given line.
    • slope

      public static double slope(Point2D start, Point2D end)
      Calculates the slope for the line defined by the given points.
    • slope

      public static double slope(double xl, double yl, double xr, double yr)
      Calculates the slope for the line defined by the given points.
    • radiansToDegrees

      public static double radiansToDegrees(double rad)
      Converts the given value in radians to degrees.
    • degreesToRadians

      public static double degreesToRadians(double degree)
      Converts the given value in degrees to radians.
    • calculateAngle

      public static double calculateAngle(double x1, double y1, double x2, double y2)
      Calculates the angle (in radians) between the two given points.
    • calculateAngle

      public static double calculateAngle(Point2D start, Point2D end)
      Calculates the angle (in radians) between the two given points.
    • calculateAngle

      public static double calculateAngle(Point2D origin, Point2D end1, Point2D end2)
      Calculates the angle (in radians) between the two given points.
    • distanceFromLine

      public static double distanceFromLine(double x, double y, double lx1, double ly1, double lx2, double ly2)
      Calculates distance from the given line.
    • distanceFromLine

      public static double distanceFromLine(double x, double y, Line2D line)
      Calculates distance from the given line.
    • distance

      public static double distance(double ux, double uy, double vx, double vy)
    • distance

      public static double distance(Point2D p1, Point2D p2)
      Calculates and returns the distance between the two points.
    • distance

      public static double distance(Point2D p1, int x, int y)
    • norm

      public static double norm(double vx, double vy)
    • dot

      public static double dot(double ux, double uy, double vx, double vy)
    • compare

      public static final boolean compare(Object x, Object y)
      Compares the two objects.
      Parameters:
      x - The first object
      y - The second object
      Returns:
      true if the two objects are equal according to .equals()
    • in

      public static final boolean in(String s, String... list)
      Returns true if the String s is present in the list
      Parameters:
      s - The string to search for
      list - The list of parameters to search
      Returns:
      true if s is in the list
    • in

      public static final boolean in(Object o, Object... list)
      Returns true if the Object o is in the search list
      Parameters:
      o - The object to search for
      list - The list of parameters to search
      Returns:
      true if o is in the list
    • in

      public static final boolean in(int i, int[] list)
      Returns true if the number i is in the search list
      Parameters:
      i - the number to search for
      list - The list of parameters to search
      Returns:
      true if i is in the list
    • in

      public static final boolean in(double i, double[] list)
      Determines if the given double value i is in the list of double values.
    • isEmpty

      public static final boolean isEmpty(Object o)
      Tests if an object is empty or null.
      Parameters:
      o - The object to test
      Returns:
      true if the object is null, or is an empty collection or map, or is an empty array, or is an empty string, or is a string containing only whitespace.
    • getAlphaFill

      public static final Color getAlphaFill(Color c)
    • getAlphaFill

      public static final Color getAlphaFill(Color c, int alpha)
    • getStroke

      public static final Stroke getStroke(PathInfo path, boolean selected)
    • min

      public static double min(double... args)
    • minFloat

      public static float minFloat(float... args)
    • minInt

      public static int minInt(int... args)
    • minLong

      public static long minLong(long... args)
    • max

      public static double max(double... args)
    • maxFloat

      public static float maxFloat(float... args)
    • maxInt

      public static int maxInt(int... args)
    • maxDouble

      public static Double maxDouble(Double... args)
    • minDouble

      public static Double minDouble(Double... args)
    • maxLong

      public static long maxLong(long... args)
    • max

      public static int max(int someNumber, int someOtherNumber)
      Returns the greater number between someNumber and someOtherNumber.
      Parameters:
      someNumber - Some number.
      someOtherNumber - Some other number (or the same number if you want).
      Returns:
      The greater number between someNumber and someOtherNumber.
    • max

      public static double max(double someNumber, double someOtherNumber)
      Returns the greater number between someNumber and someOtherNumber.
      Parameters:
      someNumber - Some number.
      someOtherNumber - Some other number (or the same number if you want).
      Returns:
      The greater number between someNumber and someOtherNumber.
    • toInt

      public static final int toInt(Object value)
      Converts the given object to an int.
      Parameters:
      value - The value to convert
    • toDouble

      public static final double toDouble(Object value)
      Converts the given object to an double.
      Parameters:
      value - The value to convert
      Returns:
      0 if null is given
    • toDouble

      public static final double toDouble(Object value, double def)
    • toDouble

      public static final double toDouble(String value)
    • getMidnight

      public static long getMidnight(long time)
      Gets the time in millis as of midnight on the morning of the specified date
      Parameters:
      time - the day in milliseconds
      Returns:
      midnight at the start of the specified day
    • getMidnight

      public static long getMidnight(long time, TimeZone tz)
      Gets the time in millis as of midnight on the morning of the specified date
      Parameters:
      time - the day in milliseconds
      Returns:
      midnight at the start of the specified day
    • getMidnightEST

      public static long getMidnightEST(long time)
      Gets the time in millis as of midnight on the morning of the specified date
      Parameters:
      time - the day in milliseconds
      Returns:
      midnight at the start of the specified day
    • getMidnightGMT

      public static long getMidnightGMT(long time)
      Gets the time in millis as of midnight on the morning of the specified date
      Parameters:
      time - the day in milliseconds
      Returns:
      midnight at the start of the specified day
    • getMidnight

      public static long getMidnight(Calendar cal, long time)
      Gets the time in millis as of midnight on the morning of the specified date
      Parameters:
      time - the day in milliseconds
      Returns:
      midnight at the start of the specified day
    • getNextDayMidnight

      public static long getNextDayMidnight(long time)
      Gets the time in millis as of midnight on the morning of the specified date + 1 day (accounting for DST)
      Parameters:
      time - the day in milliseconds
      Returns:
      midnight at the start of the specified day
    • getNextDayMidnight

      public static long getNextDayMidnight(long time, TimeZone tz)
    • formatMMDDYYYY

      public static String formatMMDDYYYY(long date)
      Formats the given date (in milliseconds since 1970) in MM/dd/yyyy format.
      Parameters:
      date - milliseconds since 1970
      Returns:
      formatted date as MM/dd/yyyy
    • formatMMDDYYYY

      public static String formatMMDDYYYY(long date, TimeZone tz)
      Formats the given date (in milliseconds since 1970) in MM/dd/yyyy format.
      Parameters:
      date - milliseconds since 1970
      tz - time zone
      Returns:
      formatted date as MM/dd/yyyy
    • formatMMDDYYYYHHMM

      public static String formatMMDDYYYYHHMM(long date)
      Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm a format.
      Parameters:
      date - milliseconds since 1970
      Returns:
      formatted date as MM/dd/yyyy h:mm a
    • formatMMDDYYYYHHMM

      public static String formatMMDDYYYYHHMM(long date, TimeZone tz)
      Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm a format.
      Parameters:
      date - milliseconds since 1970
      Returns:
      formatted date as MM/dd/yyyy h:mm a
    • formatMMDDYYYYHHMMSS

      public static String formatMMDDYYYYHHMMSS(long date)
      Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm:ss a format.
      Parameters:
      date - milliseconds since 1970
      Returns:
      formatted date as MM/dd/yyyy h:mm:ss a
    • formatYYYYMMMDDHHSSMMM

      public static String formatYYYYMMMDDHHSSMMM(long date)
      Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm:ss.ZZZ a format.
      Parameters:
      date - milliseconds since 1970
      Returns:
      formatted date as MM/dd/yyyy h:mm:ss.ZZZ a
    • formatYYYYMMMDDHHSSMMM

      public static String formatYYYYMMMDDHHSSMMM(long date, TimeZone tz)
      Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm:ss.ZZZ a format.
      Parameters:
      date - milliseconds since 1970
      Returns:
      formatted date as MM/dd/yyyy h:mm:ss.ZZZ a
    • roundHour

      public static long roundHour(long time)
      Gets the current date/time rounded down to the current hour.
      Parameters:
      time - hour
      Returns:
      the start of the given hour in milliseconds.
    • roundMinutes

      public static long roundMinutes(long time, int minutes)
      Gets the current date/time rounded down to the current minute.
      Parameters:
      time - how to round
      Returns:
      the current hour in milliseconds.
    • reverse

      public static <T> Iterable<T> reverse(List<T> list)
      Returns an Iterable object for iterating through a list in reverse order.
      Parameters:
      list - list to iterate
      Returns:
      Iterable object for traversing in reverse order
    • formatMK

      public static String formatMK(long val)
      Formats the float value as a string
      Parameters:
      val - value to format
      Returns:
      value formatted as a string using MK format
    • formatMK

      public static String formatMK(double val)
      Formats the double value as a string
      Parameters:
      val - value to format
      Returns:
      value formatted as a string using MK format
    • formatDouble

      public static final String formatDouble(double val, int places)
      Formats a double number to the given number of places
      Parameters:
      val - value to format
      places - number of decimal places
    • formatFloat

      public static final String formatFloat(float val, int places)
      Formats a float number to the given number of places
      Parameters:
      val - value to format
      places - number of decimal places
    • calcLatestMA

      public static void calcLatestMA(DataContext ctx, Enums.MAMethod method, Object input, int period, int shift, Object valKey, boolean fillForward)
      This convenience method updates the calculates a moving average of the current (latest) bar in the data series and stores it in the internal data cache with key specified (@see valKey)
      Parameters:
      ctx - - Study context
      method - - Moving Average Method
      input - - input type (high, low close etc)
      period - - Period of the moving average
      shift - - number of bars to shift (left or right, negative value for left)
      valKey - - id of the series of cached data
      fillForward - - if true and shift is negative, add forward values
    • calcSeriesMA

      public static void calcSeriesMA(DataContext ctx, Enums.MAMethod method, Object input, int period, int shift, Object valKey, boolean fillForward, boolean includeUnfinishedBars)
      This convenience method calculates a moving average for the visible bars in the data series and stores it in the internal data cache with key specified (@see valKey)
      Parameters:
      ctx - - Study context
      method - - Moving Average Method
      input - - input type (high, low close etc)
      period - - Period of the moving average
      shift - - number of bars to shift (left or right, negative value for left)
      valKey - - id of the series of cached data
      fillForward - - if true and shift is negative, add forward values
      includeUnfinishedBars - - if true, the latest incomplete bar is included
    • calcSeriesMA

      public static void calcSeriesMA(DataContext ctx, Enums.MAMethod method, Object input, int period, int shift, Object valKey, boolean fillForward)
      This convenience method calculates a moving average for the visible bars in the data series and stores it in the internal data cache with key specified (@see valKey)
      Parameters:
      ctx - - Study context
      method - - Moving Average Method
      input - - input type (high, low close etc)
      period - - Period of the moving average
      shift - - number of bars to shift (left or right, negative value for left)
      valKey - - id of the series of cached data
      fillForward - - if true and shift is negative, add forward values
    • calcMAAt

      public static void calcMAAt(int index, DataContext ctx, Enums.MAMethod method, Object input, int period, int shift, Object valKey)
      This convenience method calculates the moving average at the given index in the data series and stores it in the internal data cache with key specified (@see valKey)
      Parameters:
      index - index in the data series
      ctx - - Study context
      method - - Moving Average Method
      input - - input type (high, low close etc)
      period - - Period of the moving average
      shift - - number of bars to shift (left or right, negative value for left)
      valKey - - id of the series of cached data
    • formatMK

      public static String formatMK(float val)
      Formats the given value to shorten the display be using T - trillions, B - billions, M - millions, K - thousands
      Parameters:
      val - value to format
      Returns:
      formatted string
    • roundDouble

      public static double roundDouble(double val, int places)
      Round a double value to a specified number of decimal places.
      Parameters:
      val - the value to be rounded.
      places - the number of decimal places to round to.
      Returns:
      val rounded to places decimal places.
    • leastSquares

      public static double[] leastSquares(List<Point2D> points)
      Determines the coefficients m and b for the least squares method of linear regression (y = mx + b). Result is returned as a double array of size 2 where m = result[0] and b = result[1]
    • replaceAll

      public static final String replaceAll(String source, String[] patterns, String[] replacements)
      Takes a collection of patterns (no support for regex), replacements and a target string. All occurances of the patterns are replaced with the replacements in the target string. Carefull attention has been put on performing this operation with minimal object creation. It creates less objects than the native replaceAll() in situations where the target string doesn't contain any of the patterns.
      Parameters:
      source - A string that may contain patterns that need to be replaced.
      patterns - A collection of strings that need to be replaced (regex will not be parsed)
      replacements - A collection of replacements. NOTE: The order of the replacements must correspond to the patterns they replace in the pattern collection. EXAMPLE:
      String[] patterns = {"&", """, "<", ">"}; String[] replacements = {"&", """, "<", ">"};
      Returns:
      The source with all patterns replaced.
    • replaceAll

      public static final String replaceAll(String source, String[] patterns, Object[] replacements)
      Takes a collection of patterns (no support for regex), replacements and a target string. All occurances of the patterns are replaced with the replacements in the target string. Carefull attention has been put on performing this operation with minimal object creation. It creates less objects than the native replaceAll() in situations where the target string doesn't contain any of the patterns.
      Parameters:
      source - A string that may contain patterns that need to be replaced.
      patterns - A collection of strings that need to be replaced (regex will not be parsed)
      replacements - A collection of replacements. NOTE: The order of the replacements must corrispond to the patterns they replace in the pattern collection. EXAMPLE:
      String[] patterns = {"&", """, "<", ">"}; String[] replacements = {"&", """, "<", ">"};
      Returns:
      The source with all patterns replaced.
    • replaceAll

      public static final void replaceAll(Writer out, String source, String[] patterns, Object[] replacements) throws IOException
      Takes a collection of patterns (no support for regex), replacements and a target string. All occurances of the patterns are replaced with the replacements in the target string. Carefull attention has been put on performing this operation with minimal object creation. It creates less objects than the native replaceAll() in situations where the target string doesn't contain any of the patterns.
      Parameters:
      out - output stream
      source - A string that may contain patterns that need to be replaced.
      patterns - A collection of strings that need to be replaced (regex will not be parsed)
      replacements - A collection of replacements. NOTE: The order of the replacements must corrispond to the patterns they replace in the pattern collection. EXAMPLE:
      String[] patterns = {"&", """, "<", ">"}; String[] replacements = {"&", """, "<", ">"};
      Throws:
      IOException
    • replace

      public static final String replace(String source, String[] patterns, String[] replacements)
      Replaces occurences of the given pattern in the source string with the replacement value. The resulting string is returned.
      Parameters:
      source - source string
      patterns - patterns to search for
      replacements - replacement strings
      Returns:
      string with pattern replaced.