Class Util
java.lang.Object
com.motivewave.platform.sdk.common.Util
This class provides a set of utility methods
-
Field Summary
Modifier and TypeFieldDescriptionstatic 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
-
Method Summary
Modifier and TypeMethodDescriptionstatic Color
adjustColor
(Color c, double factor) Brightens or darkens the give color by the given percent factorstatic 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
calculateAngle
(Point2D start, Point2D end) 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
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
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 placesstatic final String
formatFloat
(float val, int places) Formats a float number to the given number of placesstatic String
formatMK
(double val) Formats the double value as a stringstatic String
formatMK
(float val) Formats the given value to shorten the display be using T - trillions, B - billions, M - millions, K - thousandsstatic String
formatMK
(long val) Formats the float value as a stringstatic 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
formatMMDDYYYYHHMMSS
(long date) Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm:ss a format.static String
formatYYYYMMMDDHHSSMMM
(long date) Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm:ss.ZZZ a format.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.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.static FontMetrics
getFontMetrics
(Font font) 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 datestatic long
getMidnight
(long time, TimeZone tz) Gets the time in millis as of midnight on the morning of the specified datestatic long
getMidnight
(Calendar cal, long time) Gets the time in millis as of midnight on the morning of the specified datestatic long
getMidnightEST
(long time) Gets the time in millis as of midnight on the morning of the specified datestatic long
getMidnightGMT
(long time) Gets the time in millis as of midnight on the morning of the specified datestatic 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 monthstatic long
getStartOfNextWeek
(long time, Instrument instr, boolean rth) Gets the start of the next trading weekstatic long
getStartOfNextYear
(long time, Instrument instr, boolean rth) Gets the start of the next trading yearstatic 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 monthstatic long
getStartOfPrevWeek
(long time, Instrument instr, boolean rth) Gets the start of the previous trading weekstatic long
getStartOfPrevYear
(long time, Instrument instr, boolean rth) Gets the start of the previous yearstatic final Stroke
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 liststatic final boolean
Returns true if the Object o is in the search liststatic final boolean
Returns true if the String s is present in the liststatic 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
Gets the last element from the list (null if the list is null or empty).static double[]
leastSquares
(List<Point2D> points) 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
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
Calculates and returns the midpoint of the line defined by the given points.static double
min
(double... args) static Double
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
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>
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
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
Calculates the slope for the given line.static double
Calculates the slope for the line defined by the given points.static int
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
static final double
static final int
Converts the given object to an int.Splits the given string into tokens using the given separator character
-
Field Details
-
SECONDS_IN_MINUTE
public static final int SECONDS_IN_MINUTE- See Also:
-
SECONDS_IN_HOUR
public static final int SECONDS_IN_HOUR- See Also:
-
SECONDS_IN_DAY
public static final int SECONDS_IN_DAY- See Also:
-
SECONDS_IN_WEEK
public static final int SECONDS_IN_WEEK- See Also:
-
MILLIS_IN_MINUTE
public static final long MILLIS_IN_MINUTE- See Also:
-
MILLIS_IN_HOUR
public static final long MILLIS_IN_HOUR- See Also:
-
MILLIS_IN_DAY
public static final long MILLIS_IN_DAY- See Also:
-
MILLIS_IN_MONTH
public static final long MILLIS_IN_MONTH- See Also:
-
MILLIS_IN_WEEK
public static final long MILLIS_IN_WEEK- See Also:
-
MILLIS_IN_YEAR
public static final long MILLIS_IN_YEAR- See Also:
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
list
Creates a list from the variable argument list. -
first
Gets the first element from the list (null if the list is null or empty). -
last
Gets the last element from the list (null if the list is null or empty). -
findNearest
Finds the index of the bar that is nearest to the given start time.- Parameters:
data
- list of barsstart_time
- start time in milliseconds since 1970- Returns:
- index of the bar in the last (-1 if not found)
-
tokenize
Splits the given string into tokens using the given separator character- Parameters:
str
- string to tokenizesep
- character that separates the tokens- Returns:
- tokenized list (excluding separator characters)
-
schedule
Executes the given task on a background thread.- Parameters:
task
- runnable task to be executed on a background thread
-
awtColor
-
awtColor
-
adjustColor
Brightens or darkens the give color by the given percent factor- Parameters:
c
- color to adjustfactor
- percentage factor to adjust. Negative value darkens the color
-
getFontMetrics
Gets the font metrics for the given font. -
getStartOfBar
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 barend
- end time for the barinstr
- instrumentbs
- bar sizerth
- regular trading hours vs extended trading hours- Returns:
- start time of the bar in milliseconds since 1970
-
getStartOfNextDay
Gets the start of the next trading day (accounting for the weekend)- Parameters:
time
- time in milliseconds since 1970instr
- instrumentrth
- regular trading hours vs extended trading hours
-
getStartOfNextWeek
Gets the start of the next trading week- Parameters:
time
- time in milliseconds since 1970instr
- instrumentrth
- regular trading hours vs extended trading hours
-
getStartOfNextMonth
Gets the start of the next trading month- Parameters:
time
- time in milliseconds since 1970instr
- instrumentrth
- regular trading hours vs extended trading hours
-
getStartOfNextYear
Gets the start of the next trading year- Parameters:
time
- time in milliseconds since 1970instr
- instrumentrth
- regular trading hours vs extended trading hours
-
getStartOfPrevDay
Gets the start of the previous trading day (accounting for the weekend)- Parameters:
time
- time in milliseconds since 1970instr
- instrumentrth
- regular trading hours vs extended trading hours
-
getStartOfPrevMonth
Gets the start of the previous trading month- Parameters:
time
- time in milliseconds since 1970instr
- instrumentrth
- regular trading hours vs extended trading hours
-
getStartOfPrevYear
Gets the start of the previous year- Parameters:
time
- time in milliseconds since 1970instr
- instrumentrth
- regular trading hours vs extended trading hours
-
getStartOfPrevWeek
Gets the start of the previous trading week- Parameters:
time
- time in milliseconds since 1970instr
- instrumentrth
- regular trading hours vs extended trading hours
-
getEndOfBar
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 barend
- end time for the barinstr
- instrumentbs
- bar sizerth
- regular trading hours vs extended trading hours- Returns:
- end time of the bar in milliseconds since 1970
-
strWidth
Calculates and returns the width of a the given string (in pixels) using the given font. -
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 roundstep
- 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 roundstep
- minimum value to round- Returns:
- rounded value (using the minimum step)
-
createDownTriangle
Creates a triangle path pointing down.- Parameters:
x
- x coordinatey
- y coordinated
- size of the triangle
-
createUpTriangle
Creates a triangle path pointing up.- Parameters:
x
- x coordinatey
- y coordinated
- size of the triangle
-
intersection
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 lineend2
- 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 1y1
- Starting point of Segment 1x2
- Ending point of Segment 1y2
- Ending point of Segment 1x3
- Starting point of Segment 2y3
- Starting point of Segment 2x4
- Ending point of Segment 2y4
- Ending point of Segment 2- Returns:
- Point where the segments intersect, or null if they don't
-
intersection
computes the intersection point between the two given lines. -
clipLine
Clips the line defined by the two given points to the bounds. Uses the Cohen Sutherland Line algorithm. -
clipLine
-
clipLine
-
rotate
public static double[] rotate(double[] points, double radians) Rotates the given array of points and returns the result in a new array. -
midpoint
Calculates and returns the midpoint of the given line. -
midpoint
Calculates and returns the midpoint of the line defined by the given points. -
rotate
Rotates the given point p about the given origin. -
rotate
Rotates the given point p about the given origin. -
slope
Calculates the slope for the given line. -
slope
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
Calculates the angle (in radians) between the two given points. -
calculateAngle
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
Calculates distance from the given line. -
distance
public static double distance(double ux, double uy, double vx, double vy) -
distance
Calculates and returns the distance between the two points. -
distance
-
norm
public static double norm(double vx, double vy) -
dot
public static double dot(double ux, double uy, double vx, double vy) -
compare
Compares the two objects.- Parameters:
x
- The first objecty
- The second object- Returns:
- true if the two objects are equal according to .equals()
-
in
Returns true if the String s is present in the list- Parameters:
s
- The string to search forlist
- The list of parameters to search- Returns:
- true if s is in the list
-
in
Returns true if the Object o is in the search list- Parameters:
o
- The object to search forlist
- 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 forlist
- 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
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
-
getAlphaFill
-
getStroke
-
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
-
minDouble
-
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
Converts the given object to an int.- Parameters:
value
- The value to convert
-
toDouble
Converts the given object to an double.- Parameters:
value
- The value to convert- Returns:
- 0 if null is given
-
toDouble
-
toDouble
-
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
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
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
-
formatMMDDYYYY
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
Formats the given date (in milliseconds since 1970) in MM/dd/yyyy format.- Parameters:
date
- milliseconds since 1970tz
- time zone- Returns:
- formatted date as MM/dd/yyyy
-
formatMMDDYYYYHHMM
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
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
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
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
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
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
Formats the float value as a string- Parameters:
val
- value to format- Returns:
- value formatted as a string using MK format
-
formatMK
Formats the double value as a string- Parameters:
val
- value to format- Returns:
- value formatted as a string using MK format
-
formatDouble
Formats a double number to the given number of places- Parameters:
val
- value to formatplaces
- number of decimal places
-
formatFloat
Formats a float number to the given number of places- Parameters:
val
- value to formatplaces
- 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 contextmethod
- - Moving Average Methodinput
- - input type (high, low close etc)period
- - Period of the moving averageshift
- - number of bars to shift (left or right, negative value for left)valKey
- - id of the series of cached datafillForward
- - 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 contextmethod
- - Moving Average Methodinput
- - input type (high, low close etc)period
- - Period of the moving averageshift
- - number of bars to shift (left or right, negative value for left)valKey
- - id of the series of cached datafillForward
- - if true and shift is negative, add forward valuesincludeUnfinishedBars
- - 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 contextmethod
- - Moving Average Methodinput
- - input type (high, low close etc)period
- - Period of the moving averageshift
- - number of bars to shift (left or right, negative value for left)valKey
- - id of the series of cached datafillForward
- - 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 seriesctx
- - Study contextmethod
- - Moving Average Methodinput
- - input type (high, low close etc)period
- - Period of the moving averageshift
- - number of bars to shift (left or right, negative value for left)valKey
- - id of the series of cached data
-
formatMK
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
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
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
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 streamsource
- 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
Replaces occurences of the given pattern in the source string with the replacement value. The resulting string is returned.- Parameters:
source
- source stringpatterns
- patterns to search forreplacements
- replacement strings- Returns:
- string with pattern replaced.
-