Custom Indicator Errors Coming From Translated MQL5 Code
2 replies
l fe
1 year ago #289644
Hello everyone
I’m trying to translate the UTBot MQL5 indicator into StrategyQuant however I’m having a bit of trouble compiling my indicator.
I have no idea why I’m getting these errors coming from indicators.java.
If anyone has some guidance or any pointers as to why the error is happening I would really appreciate it.
Attached are the UTBot.java file which is my indicator
An image snippet of indicators.java which is where the errors are coming from, and the errors shown.
Many thanks 🙂
1
l fe
1 year ago #289645
Apologizes the .java file failed to attach, here is the custom indicator code
`
package com.strategyquant.indicators;
import com.strategyquant.tradinglib.*;
import com.strategyquant.lib.*;
import com.strategyquant.datalib.*;
import static java.lang.Math.*;
/**
* UT Bot – port of Geraked’s MT5 indicator.
*
* • C1 – trailing channel line
* • Sig – +1 = Bull, –1 = Bear, 0 = Flat
*/
@BuildingBlock(
name = “UT Bot”,
display = “UT Bot (#Length# | #Coef#)”,
returnType = ReturnTypes.Number
)
public class UTBot extends IndicatorBlock {
@Parameter(name = “Length”, defaultValue = “10”, minValue = 1, isPeriod = true)
public int Length = 10;
@Parameter(name = “Coef”, defaultValue = “3.0”, minValue = 0.5, maxValue = 10, step = 0.1)
public double Coef = 3.0;
@Output(name = “C1”) public DataSeries C1;
@Output(name = “Sig”) public DataSeries Sig;
private ATR atr;
@Override
public void onInitialize() throws TradingException {
atr = Indicators.ATR(Length);
}
@Override
public void onBarUpdate() throws TradingException {
int i = series.index();
if (i == 0) {
C1.set(series.close(0));
Sig.set(0);
return;
}
double close = series.close(0);
double close1 = series.close(1);
double prevC1 = C1.get(i – 1);
double loss = atr.getValue(0) * Coef;
double t1 = close > prevC1 ? close – loss : close + loss;
double t2 = (close < prevC1 && close1 < prevC1) ? min(prevC1, close + loss) : t1; double newC1 = (close > prevC1 && close1 > prevC1)
? max(prevC1, close – loss) : t2;
int sig = 0;
if (close > newC1 && close1 <= prevC1) sig = 1;
if (close < newC1 && close1 >= prevC1) sig = -1;
C1.set(newC1);
Sig.set(sig);
}
}
`
0
Tomas Matejka
1 year ago #289764
If you seek programming help you can contact our developers directly. Check for more details: https://strategyquant.com/codebase/request-coding/
0
Viewing 2 replies - 1 through 2 (of 2 total)