Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Why doesn't it print?
 Post subject: Why doesn't it print? Post rating: 0   New post Posted: Mon 30 Mar, 2015, 12:26 
User avatar

User rating: 0
Joined: Tue 25 Feb, 2014, 16:16
Posts: 6
So the code used to print something all the time and than it stopped.
It does not print "init" nor "calculate" no matter if it's attached to the chart or not.

I press compile. It informs that it compiled ok. Then i go to Workspace >custome indicators > (right click) Risk control > attach to active chart.
Still nothing happens.

package jforex;

import com.dukascopy.api.indicators.*;
import com.dukascopy.api.drawings.*;
import com.dukascopy.api.feed.*;
import com.dukascopy.api.*;
import java.awt.Color;
import java.io.*;

public class RiskControl implements IIndicator {
    private IndicatorInfo indicatorInfo;
    private InputParameterInfo[] inputParameterInfos;
    private OptInputParameterInfo[] optInputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos;
    private double[][] inputs = new double[1][];
    private int timePeriod = 2;
    private double[][] outputs = new double[1][];
    private IIndicatorContext context;
    private IPriceMarkerChartObject slMarker;
    private IPriceMarkerChartObject tpMarker;
    private IPriceMarkerChartObject opMarker;
    private IFeedDescriptor feedDescriptor;
   
    public void onStart(IIndicatorContext context) {
        indicatorInfo = new IndicatorInfo("Risk Control", "", "",
            true, false, false, 1, 1, 1);
       
        inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Input data", InputParameterInfo.Type.DOUBLE)};
       
        optInputParameterInfos = new OptInputParameterInfo[] {new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER,
            new IntegerRangeDescription(2, 2, 100, 1))};
       
        outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("out", OutputParameterInfo.Type.DOUBLE,
            OutputParameterInfo.DrawingStyle.LINE)};
       
        this.context = context;     
        PrintStream stream = context.getConsole().getOut();
        stream.print("init");
    }

    public IndicatorResult calculate(int startIndex, int endIndex) {
        context.getConsole().getOut().print("calculate");

        Draw();

        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }
        int i, j;
        for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
            double value = 0;
            for (int k = timePeriod; k > 0; k--) {
                value += inputs[0][i - k];
            }
            outputs[0][j] = value;
        }
        return new IndicatorResult(startIndex, j);
       
        //return new IndicatorResult(startIndex, 0);
    }
   
    private void Draw(){
        IHistory history = context.getHistory();
       
        IIndicatorChartPanel panel = context.getIndicatorChartPanel();
        if(panel == null){
            context.getConsole().getWarn().print("Panel is null");       
            return;   
        }
       
        IChartObjectFactory factory = panel.getChartObjectFactory();
     
        double balance = context.getAccount().getBalance();
     
        feedDescriptor = context.getFeedDescriptor();
        if(feedDescriptor == null){
            context.getConsole().getWarn().print("Feed descriptor is null");       
            return;   
        }
        Period period = feedDescriptor.getPeriod();       
        Instrument instrument = feedDescriptor.getInstrument();
        if(instrument == null){
            context.getConsole().getWarn().print("Instrument is null");       
            return;
        }
 
        double priceMid;
        try{
            double priceAsk = history.getBar(instrument, period, OfferSide.ASK, 0).getClose();
            double priceBid = history.getBar(instrument, period, OfferSide.BID, 0).getClose();
            priceMid = (priceAsk + priceBid)/2.0;
             context.getConsole().getOut().print("03");
       
        } catch(Exception ex){
            context.getConsole().getWarn().print("Get bar error");       
       
            context.getConsole().getErr().print(ex.toString());
            return;
        }
           
        slMarker = factory.createPriceMarker("SL", priceMid - 20.0 * instrument.getPipValue());
        opMarker = factory.createPriceMarker("OP", priceMid);
        slMarker.setColor(Color.RED);
        opMarker.setColor(Color.ORANGE);
        slMarker.setLineWidth(2.0f);
        opMarker.setLineWidth(2.0f);
           
        context.getConsole().getOut().print("01");
       
        context.getConsole().getOut().print(slMarker.getPrice(0));
        context.getConsole().getOut().print(opMarker.getPrice(0));
     
    }

    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

    public InputParameterInfo getInputParameterInfo(int index) {
        if (index <= inputParameterInfos.length) {
            return inputParameterInfos[index];
        }
        return null;
    }

    public int getLookback() {
        return timePeriod;
    }

    public int getLookforward() {
        return 0;
    }

    public OptInputParameterInfo getOptInputParameterInfo(int index) {
        if (index < optInputParameterInfos.length) {
            return optInputParameterInfos[index];
        }
        return null;
    }

    public OutputParameterInfo getOutputParameterInfo(int index) {
        if (index < outputParameterInfos.length) {
            return outputParameterInfos[index];
        }
        return null;
    }

    public void setInputParameter(int index, Object array) {
        inputs[index] = (double[]) array;
    }

    public void setOptInputParameter(int index, Object value) {
        timePeriod = (Integer) value;
    }

    public void setOutputParameter(int index, Object array) {
        outputs[index] = (double[]) array;
    }
}


 
 Post subject: Re: Why doesn't it print? Post rating: 0   New post Posted: Wed 08 Apr, 2015, 10:09 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Messages will be printed only when newline character is received.
Therefore please replace print with println.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com