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:

Donovan2580

Well-known member
Joined
Sep 13, 2020
Posts
431
Likes
236
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?! :)
 

cocos2010

New member
Joined
Aug 11, 2021
Posts
4
Likes
1
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
 

shyton

New member
Joined
May 1, 2023
Posts
2
Likes
1
Thanks for your guidance
It is possible to put the final Java file for download ?
 

igor.s

Well-known member
Joined
May 22, 2019
Posts
286
Likes
152
It's fascinating how the AI entering all the fields to replace actual humans. The generated code looks pretty good.

cheers.
 
Top