Adding Signal to Fractal study

RonnieDubs

Member
Joined
Aug 13, 2020
Posts
15
Likes
2
Can anyone assist me... I'm trying to add a Signal to the Fractal study. The study itself already creates an up marker and a down marker. I'm trying to add a signal when these markers show up. The code for the signal is:

package com.motivewave.platform.study.williams;

import java.util.List;

import com.motivewave.platform.sdk.common.DataContext;
import com.motivewave.platform.sdk.common.DataSeries;
import com.motivewave.platform.sdk.common.Defaults;
import com.motivewave.platform.sdk.common.Enums;
import com.motivewave.platform.sdk.common.Enums.Position;
import com.motivewave.platform.sdk.common.Inputs;
import com.motivewave.platform.sdk.common.MarkerInfo;
import com.motivewave.platform.sdk.common.SwingPoint;
import com.motivewave.platform.sdk.common.desc.IntegerDescriptor;
import com.motivewave.platform.sdk.common.desc.MarkerDescriptor;
import com.motivewave.platform.sdk.common.desc.SettingGroup;
import com.motivewave.platform.sdk.common.desc.SettingTab;
import com.motivewave.platform.sdk.common.desc.SettingsDescriptor;
import com.motivewave.platform.sdk.draw.Marker;
import com.motivewave.platform.sdk.study.RuntimeDescriptor;
import com.motivewave.platform.sdk.study.Study;
import com.motivewave.platform.sdk.study.StudyHeader;

/** Fractal (Bill Williams) */
@StudyHeader(
namespace="com.motivewave",
id="FRACTAL",
rb="com.motivewave.platform.study.nls.strings",
name="TITLE_FRACTAL",
desc="DESC_FRACTAL",
menu="MENU_OVERLAY",
menu2="MENU_BILL_WILLIAMS",
overlay=true,
helpLink="http://www.motivewave.com/studies/fractal.htm")
public class Fractal extends Study
{
@Override
public void initialize(Defaults defaults)
{
SettingsDescriptor sd = new SettingsDescriptor();
SettingTab tab = new SettingTab(get("TAB_GENERAL"));
sd.addTab(tab);
setSettingsDescriptor(sd);

SettingGroup inputs = new SettingGroup(get("LBL_INPUTS"));
inputs.addRow(new IntegerDescriptor(Inputs.STRENGTH, get("LBL_STRENGTH"), 2, 1, 999, 1));
tab.addGroup(inputs);
SettingGroup markers = new SettingGroup(get("LBL_MARKERS"));
markers.addRow(new MarkerDescriptor(Inputs.UP_MARKER, get("LBL_UP_MARKER"),
Enums.MarkerType.TRIANGLE, Enums.Size.SMALL, defaults.getGreen(), defaults.getLineColor(), true, true));
markers.addRow(new MarkerDescriptor(Inputs.DOWN_MARKER, get("LBL_DOWN_MARKER"),
Enums.MarkerType.TRIANGLE, Enums.Size.SMALL, defaults.getRed(), defaults.getLineColor(), true, true));
tab.addGroup(markers);

RuntimeDescriptor desc = new RuntimeDescriptor();
desc.setLabelSettings(Inputs.STRENGTH);
setRuntimeDescriptor(desc);
}

@Override
public void onBarClose(DataContext ctx)
{
calculateValues(ctx);
}

@Override
protected void calculateValues(DataContext ctx)
{
DataSeries series = ctx.getDataSeries();
clearFigures();

List<SwingPoint> swingPoints = series.calcSwingPoints(getSettings().getInteger(Inputs.STRENGTH, 2));

// Add the markers
MarkerInfo upMarker = getSettings().getMarker(Inputs.UP_MARKER);
MarkerInfo downMarker = getSettings().getMarker(Inputs.DOWN_MARKER);
swingPoints.forEach(sp -> {
if (sp.isTop() && downMarker.isEnabled()) {
addFigure(new Marker(sp.getCoordinate(), Position.BOTTOM, upMarker));
}
else if (!sp.isTop() && upMarker.isEnabled()) {
addFigure(new Marker(sp.getCoordinate(), Position.TOP, downMarker));
}
});
}
}
 

Spin

Well-known member
Joined
May 22, 2019
Posts
478
Likes
191
Hi @RonnieDubs 😀

I would advise you to look at one of the built-in MW Studies and see how 'signals' are implemented there. VPCI for example.

It's all quite simple actually:
Make sure you define the signal
Java:
 enum Signals { BULLISH_CROSS, BEARISH_CROSS }
declare them
Java:
// Signals
    desc.declareSignal(Signals.BULLISH_CROSS, get("LBL_BULLISH_CROSS"));
    desc.declareSignal(Signals.BEARISH_CROSS, get("LBL_BEARISH_CROSS"));
and add them to the code that gets executed when a marker needs to be drawn
Code:
ctx.signal(index, Signals.BULLISH_CROSS, get("LBL_BULLISH_CROSS"), theInstrument.round(series.getClose(index)));
 

RonnieDubs

Member
Joined
Aug 13, 2020
Posts
15
Likes
2
Spin thanks a lot for the help. So I added those in and added
LBL_BUY=BUY
LBL_SELL=SELL
into the string properties
however I'm still getting errors as if it doesn't know what my symbol is:
error: cannot find symbol
[javac] desc.declareSignal(Signals.BUY, get("LBL_BUY"));
[javac] ^
[javac] symbol: variable desc
[javac] location: class Fractal
 

RonnieDubs

Member
Joined
Aug 13, 2020
Posts
15
Likes
2
Do you see the error in this?

package study_examples;

import java.util.List;

import com.motivewave.platform.sdk.common.DataContext;
import com.motivewave.platform.sdk.common.DataSeries;
import com.motivewave.platform.sdk.common.Defaults;
import com.motivewave.platform.sdk.common.Enums;
import com.motivewave.platform.sdk.common.Enums.Position;
import com.motivewave.platform.sdk.common.Inputs;
import com.motivewave.platform.sdk.common.MarkerInfo;
import com.motivewave.platform.sdk.common.SwingPoint;
import com.motivewave.platform.sdk.common.desc.IntegerDescriptor;
import com.motivewave.platform.sdk.common.desc.MarkerDescriptor;
import com.motivewave.platform.sdk.common.desc.SettingGroup;
import com.motivewave.platform.sdk.common.desc.SettingTab;
import com.motivewave.platform.sdk.common.desc.SettingsDescriptor;
import com.motivewave.platform.sdk.draw.Marker;
import com.motivewave.platform.sdk.study.RuntimeDescriptor;
import com.motivewave.platform.sdk.study.Study;
import com.motivewave.platform.sdk.study.StudyHeader;

/** Fractal (Bill Williams) */
@StudyHeader(
namespace="com.motivewave",
id="FRACTAL22",
rb="com.motivewave.platform.study.nls.strings",
name="TITLE_FRACTAL22",
desc="DESC_FRACTAL22",
menu="MENU_OVERLAY",
menu2="MENU_FRACTAL22",
signals=true,
overlay=true,
helpLink="http://www.motivewave.com/studies/fractal.htm")
public class Fractal22 extends Study
{
enum Signals { SELL, BUY }


@Override
public void initialize(Defaults defaults)
{
SettingsDescriptor sd = new SettingsDescriptor();
SettingTab tab = new SettingTab(get("TAB_GENERAL"));
sd.addTab(tab);
setSettingsDescriptor(sd);

SettingGroup inputs = new SettingGroup(get("LBL_INPUTS"));
inputs.addRow(new IntegerDescriptor(Inputs.STRENGTH, get("LBL_STRENGTH"), 2, 1, 999, 1));
tab.addGroup(inputs);
SettingGroup markers = new SettingGroup(get("LBL_MARKERS"));
markers.addRow(new MarkerDescriptor(Inputs.UP_MARKER, get("LBL_UP_MARKER"),
Enums.MarkerType.TRIANGLE, Enums.Size.SMALL, defaults.getGreen(), defaults.getLineColor(), true, true));
markers.addRow(new MarkerDescriptor(Inputs.DOWN_MARKER, get("LBL_DOWN_MARKER"),
Enums.MarkerType.TRIANGLE, Enums.Size.SMALL, defaults.getRed(), defaults.getLineColor(), true, true));
tab.addGroup(markers);

RuntimeDescriptor desc = new RuntimeDescriptor();
desc.setLabelSettings(Inputs.STRENGTH);
setRuntimeDescriptor(desc);
}

@Override
public void onBarClose(DataContext ctx)
{
calculateValues(ctx);
}

@Override
protected void calculateValues(DataContext ctx)
{
DataSeries series = ctx.getDataSeries();
clearFigures();

List<SwingPoint> swingPoints = series.calcSwingPoints(getSettings().getInteger(Inputs.STRENGTH, 2));

// signals
desc.declareSignal(Signals.BUY, get("LBL_BUY"));
desc.declareSignal(Signals.SELL, get("LBL_SELL"));


// Add the markers
MarkerInfo upMarker = getSettings().getMarker(Inputs.UP_MARKER);
MarkerInfo downMarker = getSettings().getMarker(Inputs.DOWN_MARKER);
swingPoints.forEach(sp -> {
if (sp.isTop() && downMarker.isEnabled()) {
addFigure(new Marker(sp.getCoordinate(), Position.BOTTOM, upMarker));
ctx.signal(index, Signals.BUY, get("LBL_BUY"), theInstrument.round(series.getClose(index)));
}
else if (!sp.isTop() && upMarker.isEnabled()) {
addFigure(new Marker(sp.getCoordinate(), Position.TOP, downMarker));
ctx.signal(index, Signals.SELL, get("LBL_SELL"), theInstrument.round(series.getClose(index)));
}
});
}
}
 

Spin

Well-known member
Joined
May 22, 2019
Posts
478
Likes
191
Hi @RonnieDubs, you were definitely on the right track.

I took a look and added a few lines. I advise you to compare your version and mine to see what was missing / misplaced :)

I have not tested anything, but it does compile now.
 

Attachments

  • testForum.txt
    3.5 KB · Views: 19
Last edited:
Top