public String getTemplatePath() {
return "org/encog/data/mt4.mql4";
}
private void processCalc() {
AnalystField firstOutputField = null;
final int barsNeeded = Math.abs(getAnalyst().determineMinTimeSlice());
final int inputCount = getAnalyst().determineInputCount();
final int outputCount = getAnalyst().determineOutputCount();
setIndentLevel(2);
addLine("if( _inputCount>0 && Bars>=" + barsNeeded + " )");
addLine("{");
indentIn();
addLine("double input[" + inputCount + "];");
addLine("double output[" + outputCount + "];");
int idx = 0;
for (final AnalystField field : getAnalyst().getScript().getNormalize()
.getNormalizedFields()) {
if (field.isInput()) {
final DataField df = getAnalyst().getScript().findDataField(
field.getName());
String str;
switch (field.getAction()) {
case PassThrough:
str = EngineArray.replace(df.getSource(), "##", "pos+"
+ (-field.getTimeSlice()));
addLine("input[" + idx + "]=" + str + ";");
idx++;
break;
case Normalize:
str = EngineArray.replace(df.getSource(), "##", "pos+"
+ (-field.getTimeSlice()));
addLine("input[" + idx + "]=Norm(" + str + ","
+ field.getNormalizedHigh() + ","
+ field.getNormalizedLow() + ","
+ field.getActualHigh() + ","
+ field.getActualLow() + ");");
idx++;
break;
case Ignore:
break;
default:
throw new AnalystCodeGenerationError(
"Can't generate Ninjascript code, unsupported normalizatoin action: "
+ field.getAction().toString());
}
}
if (field.isOutput()) {
if (firstOutputField == null) {
firstOutputField = field;
}
}
}
if (firstOutputField == null) {
throw new AnalystCodeGenerationError(
"Could not find an output field.");
}
addLine("Compute(input,output);");
addLine("ExtMapBuffer1[pos] = DeNorm(output[0]" + ","
+ firstOutputField.getNormalizedHigh() + ","
+ firstOutputField.getNormalizedLow() + ","
+ firstOutputField.getActualHigh() + ","
+ firstOutputField.getActualLow() + ");");
indentOut();
addLine("}");
setIndentLevel(2);
}