Vertical line extended on either side

Hari

Member
Joined
Jan 15, 2025
Posts
5
Likes
2
I'm starting out with Motivewave. I'm trying to draw a vertical line that is extended on both ends. I see setExtendLeft and setExtendRight in the Line class but not top and bottom. Can someone please help?
 
package study_examples;

import java.awt.BasicStroke;
import java.awt.Color;
import java.time.*;
import java.time.ZoneId;

import com.motivewave.platform.sdk.common.*;
import com.motivewave.platform.sdk.common.Enums.MarkerType;
import com.motivewave.platform.sdk.common.desc.*;
import com.motivewave.platform.sdk.draw.*;
import com.motivewave.platform.sdk.study.*;

@StudyHeader(namespace = "com.motivewave",
name = "DWOL",
id = "DWOL",
desc = "Daily Weekly Open Lines",
overlay = true,
menu = "MyMotivewaveIndicators" ,
supportsBarUpdates = true,
requiresBarUpdates = true
)
public class DailyWeeklyOpenLines extends Study {

// Inputs if you want user to customize colors, etc.
final static String DAILY_COLOR = "dailyColor";
final static String WEEKLY_COLOR = "weeklyColor";

@Override
public void initialize(Defaults defaults) {

var sd = createSD();
var tab = sd.addTab("General");
var group = tab.addGroup("Colors");

ColorDescriptor dailyColorDesc = new ColorDescriptor(DAILY_COLOR, "Daily Separator", defaults.getBlue());
group.addRow(dailyColorDesc);

ColorDescriptor weeklyColorDesc = new ColorDescriptor(WEEKLY_COLOR, "Weekly Separator", defaults.getRed());
group.addRow(weeklyColorDesc);

sd.addQuickSettings(DAILY_COLOR);
sd.addQuickSettings(WEEKLY_COLOR);

// We will plot lines on the chart, so we need at least 1 bar
setMinBars(1);
}

@Override
public void calculate(int index, DataContext ctx) {
var series = ctx.getDataSeries();
int lastIndex = series.size() - 1;
if (lastIndex < 0)
return;

// Get the bar's start time
var barTimeMillis = series.getStartTime(index);
info("index , bartime " + index + ", " + barTimeMillis);
var instrumentTimeZone = ctx.getInstrument().getTimeZone();
var easternTimeZone = ZoneId.of("America/New_York");
var barTime = Instant.ofEpochMilli(barTimeMillis).atZone(easternTimeZone);

int hour = barTime.getHour();
int minute = barTime.getMinute();
info("hour, minute "+ hour + ", " + minute);
if( hour == 18 && minute == 0) {
Color lineColor;
DayOfWeek dayOfWeek = barTime.getDayOfWeek();
if (dayOfWeek == DayOfWeek.SUNDAY) {
lineColor = getSettings().getColor(WEEKLY_COLOR);
info("selected color weekly");
}else {
lineColor = getSettings().getColor(DAILY_COLOR);
info("selected color daily");
}


//draw vertical line
drawVerticalLine(ctx, index, lineColor);
}
}

private void drawVerticalLine(DataContext ctx, int lastIndex, Color lineColor) {
var series = ctx.getDataSeries();
BasicStroke SOLID_LINE = new BasicStroke(3.0f);

// Get the highest and lowest price to cover full chart height
double highestPrice = series.getHigh(series.size() - 1);
double lowestPrice = series.getLow(series.size() - 1);

Line line = new Line(lastIndex, highestPrice, lastIndex, lowestPrice);
line.setColor(lineColor);
//line.setStroke(SOLID_LINE); // Solid vertical line
addFigure(line);
}

}

This is a simple study that just draws a vertical line start of day. I'm not able to get it to work. It wouldn't draw the line. Can someone please help?
 
....
Line line = new Line(lastIndex, highestPrice, lastIndex, lowestPrice); <-
...
Review how you create the line. Your lasIndex is not a correct parameter for the expected startTime/endTime.

From the SDK
public Line(long startTime, double startValue, long endTime, double endValue)
 
Top