pinbar detector for motivewave

shyton

New member
Joined
May 1, 2023
Posts
2
Likes
1
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

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:
I do not know anything about programming Java either but I would love to see what someone like @Spin has to say about the AI generated code?! :)
 
from bard.google.com

The mistake in the code is that the line is importing the class from the package, but the class is already imported from the package. Therefore, the line can be removed without affecting the functionality of the code.import com.motivewave.platform.sdk.common.desc.color.*;Colorcom.motivewave.platform.sdk.common.desc.colorColorjava.awtimport com.motivewave.platform.sdk.common.desc.color.*;

Here is the corrected code:

Code:
import com.motivewave.platform.sdk.common.*;
import com.motivewave.platform.sdk.common.desc.*;
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
    }
}


Sources​

  1. github.com/lndshk/MotiveWave
 
Thanks for your guidance
It is possible to put the final Java file for download ?
 
It's fascinating how the AI entering all the fields to replace actual humans. The generated code looks pretty good.

cheers.
 
Hello everyone,

Please excuse the question: I'm not a programmer and would like to use PinBars - is there a way to simply import them into MW? Cheers
 
I do not know anything about programming Java either but I would love to see what someone like @Spin has to say about the AI generated code?! :)
(I seem to have missed this thread back in May, apparently)

If that is what bard spat out, then I am impressed. Not necessarily the way I would code it, but still: impressive.
Copy / pasting it into an IDE reveals quite a few 'issues' though:
1730663202556.png

So I'm not fearing for my job yet.
:)
 
Top