hi,
I need an indicator with the ability to send alerts on motivewave, to alert when a pinbar candle is formed
I am not good at Java coding, so I got help from chatgpt and he wrote this code for me. Can anyone help me to fix this code and get the jar file for everyone to download and use it
I need an indicator with the ability to send alerts on motivewave, to alert when a pinbar candle is formed
I am not good at Java coding, so I got help from chatgpt and he wrote this code for me. Can anyone help me to fix this code and get the jar file for everyone to download and use it
Code:
import com.motivewave.platform.sdk.common.*;
import com.motivewave.platform.sdk.common.desc.*;
import com.motivewave.platform.sdk.common.desc.color.*;
import com.motivewave.platform.sdk.study.*;
import java.awt.*;
import java.util.*;
@StudyHeader(
namespace="com.example",
id="PinbarDetector",
name="Pinbar Detector",
version="1.0"
)
public class PinbarDetector extends Study
{
private static final Color DEFAULT_COLOR = new Color(255, 0, 0);
private int bodyToTailRatio = 1; // Customize this value to adjust the sensitivity
// Input Parameters
@StudyInputField(title="Body to Tail Ratio", type=StudyInputField.Type.INT, defval="1")
public void setBodyToTailRatio(int ratio)
{
bodyToTailRatio = ratio;
}
// Output Parameters
@StudyOutputField(title="Pinbar Alert", type=StudyOutputField.Type.OBJECT)
private StudyOutputField pinbarAlert;
@Override
public void initialize(Defaults defaults)
{
pinbarAlert = createOutputObject();
}
@Override
public void recalculate(int startIndex, int endIndex)
{
TimeSeries series = getSeries();
if (series == null) return;
for (int i = startIndex; i <= endIndex; i++)
{
double open = series.getOpen(i);
double high = series.getHigh(i);
double low = series.getLow(i);
double close = series.getClose(i);
double bodyHeight = Math.abs(open - close);
double tailHeight = Math.min(Math.abs(high - open), Math.abs(high - close));
double bodyToTailHeightRatio = bodyHeight / tailHeight;
if (bodyHeight > 0 && tailHeight > 0 && bodyToTailHeightRatio >= bodyToTailRatio)
{
pinbarAlert.setValue(new Object());
return;
}
}
}
@Override
public void paint(Graphics g, BarPainter painter)
{
// No visual representation required for this indicator
}
}
Last edited: