Dukascopy
 
 
Wiki JStore Search Login

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

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

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

indicator AskBidVolumes
 Post subject: indicator AskBidVolumes Post rating: 0   New post Posted: Sun 08 Jul, 2018, 18:52 

User rating: 6
Joined: Tue 30 Oct, 2012, 19:39
Posts: 14
Hello everyone!
Someone give an example of how to call the value of the AskBidVolumes indicator on the previous bar


 
 Post subject: Re: indicator AskBidVolumes Post rating: 0   New post Posted: Tue 10 Jul, 2018, 14:25 
User avatar

User rating: 0
Joined: Fri 19 Apr, 2013, 10:17
Posts: 31
Location: Ukraine, Kiev
https://www.dukascopy.com/client/javado ... cator.html


 
 Post subject: Re: indicator AskBidVolumes Post rating: 1   New post Posted: Tue 10 Jul, 2018, 16:16 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

        IFeedDescriptor myFeedDescriptor = new TimePeriodAggregationFeedDescriptor(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.ASK, Filter.WEEKENDS);
        Object[] values = indicators.calculateIndicator(myFeedDescriptor,
                new OfferSide[]{OfferSide.ASK},
                "AskBidVolumes",
                new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
                new Object[]{},
                1);

        console.getOut().println("Total volume: " + values[0] + " Bullish volume: " + values[1] + " Bearish volume: " + values[2]);


 
 Post subject: Re: indicator AskBidVolumes Post rating: 1   New post Posted: Tue 24 Jul, 2018, 21:40 

User rating: 6
Joined: Tue 30 Oct, 2012, 19:39
Posts: 14
Thanks for your help!!!


 
 Post subject: Re: indicator AskBidVolumes Post rating: 0   New post Posted: Sun 09 Sep, 2018, 09:49 
User avatar

User rating: 13
Joined: Mon 27 Jul, 2015, 16:30
Posts: 110
Location: Canada, Mission
Here are few practical examples in strategies context!


import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;

import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.IUserInterface;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;

public class FullMarketDepth implements IStrategy {
   private static final String TAB_NAME = "Full Market Depth";
    private IContext context;
    private IUserInterface userInterface;

    private MarketDepthTableModel tableModel;
    private JTable table;

    public void onStart(IContext context) throws JFException {
        this.context = context;
        userInterface = context.getUserInterface();
       placeControlsOnTab(context);
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
       userInterface.removeBottomTab(TAB_NAME);
    }

    public void onTick(Instrument instrument, final ITick tick) throws JFException {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    setVolumes(tick.getAsks(), tick.getAskVolumes(), tick.getBids(), tick.getBidVolumes());
                }
            });
        } catch (Exception e) {
            context.getConsole().getOut().println(e);
        }
    }

   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
   }

    private void placeControlsOnTab(IContext context) {
      JPanel mainPanel = userInterface.getBottomTab(TAB_NAME);
      //mainPanel.setLayout(new BorderLayout());
        tableModel = new MarketDepthTableModel();
        table = new JTable(tableModel);
        mainPanel.add(new JScrollPane(table), BorderLayout.CENTER);
    }

    public void setVolumes(double[] asks, double[] askVols, double[] bids, double[] bidVols) {

        double[][] data = new double[asks.length > bids.length ? asks.length : bids.length][4];
        for (int i = 0; i < asks.length; i++) {
            data[i][3] = askVols[i] / 1000000;
            data[i][2] = asks[i];
        }
        for (int i = 0; i < bids.length; i++) {
            data[i][0] = bidVols[i] / 1000000;
            data[i][1] = bids[i];
        }
        tableModel.setData(data);
    }
}

class MarketDepthTableModel extends AbstractTableModel {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private double[][] data = new double[0][0];

    public void setData(double[][] data) {
        this.data = data;
        fireTableDataChanged();
    }

    public int getRowCount() {
        return data.length;
    }

    public int getColumnCount() {
        return 4;
    }

    public Object getValueAt(int row, int column) {
        if (data[row][column] == 0.0) {
            return "";
        } else {
            return Double.toString(data[row][column]);
        }
    }

    public String getColumnName(int column) {

        switch (column) {
            case 0:
                return "Vol";
            case 1:
                return "Bid";
            case 2:
                return "Ask";
            case 3:
                return "Vol";
            default:
                return "";
        }
    }
}


//////////////////////////////////////////////////////////

import java.util.*;

import com.dukascopy.api.*;

public class MarketDepth_V1 implements IStrategy {
    private IConsole console;
    private IContext context;
    public void onStart(IContext context) throws JFException {
        context.getEngine();
        this.console = context.getConsole();
        context.getHistory();
        this.context = context;
        context.getIndicators();
        context.getUserInterface();
       
        Set<Instrument> instruments = new HashSet<Instrument>();
        instruments.add(Instrument.EURUSD);
        this.context.setSubscribedInstruments(instruments);
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {       
        if(!Instrument.EURUSD.equals(instrument)) {
            return;
        }
               
        console.getOut().print("ask ");
        for(double volume : tick.getAskVolumes()) {
            console.getOut().print(volume+ ", ");
        }
        console.getOut().println();
       
        console.getOut().print("bid ");
        for(double volume : tick.getBidVolumes()) {
            console.getOut().print(volume+ ", ");
        }
        console.getOut().println();
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


////////////////////////////

package jforex.indicators;

import com.dukascopy.api.indicators.*;
import java.awt.*;
import com.dukascopy.api.*;

/**
 * Created by: chriz aka Indiana Pips
 * Review: Mar 12, 2011
 * email: puntasabbioni/AT/gmail.com
 */

public class AskBidVolumeIndiPrice2 implements IIndicator {
    private IndicatorInfo indicatorInfo;
    private InputParameterInfo[] inputParameterInfos;
    private OptInputParameterInfo[] optInputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos;

    private double[][] iBidVolumes, iAskVolumes;

    private double[][] outputs = new double[3][];
    private IIndicatorContext context;

    public void onStart(IIndicatorContext context) {
        this.context = context;
        indicatorInfo = new IndicatorInfo("AskBidVolumeIndiPrice", "Ask+Bid Volume Indi Price", "AskBid", false, false, true, 2, 0, 3);

        inputParameterInfos = new InputParameterInfo[] { new InputParameterInfo("Input data Ask", InputParameterInfo.Type.PRICE) {
            {
                setOfferSide(OfferSide.ASK);
            }
        }, new InputParameterInfo("Input data Bid", InputParameterInfo.Type.PRICE) {
            {
                setOfferSide(OfferSide.BID);
            }
        } };

        optInputParameterInfos = new OptInputParameterInfo[] { new OptInputParameterInfo("MA Period", OptInputParameterInfo.Type.OTHER,
                new IntegerRangeDescription(100, 2, 1000, 1)) };
        outputParameterInfos = new OutputParameterInfo[] {
                new OutputParameterInfo("Ask+Bid", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.HISTOGRAM) {
                    {
                        setColor(Color.BLUE);
                    }
                },
                new OutputParameterInfo("Ask Vol > Bid Vol ", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.HISTOGRAM) {
                    {
                        setColor(Color.GREEN);
                    }
                },
                new OutputParameterInfo("Bid Vol > Ask Vol ", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.HISTOGRAM) {
                    {
                        setColor(Color.RED);
                    }
                } };
    }

    public IndicatorResult calculate(int startIndex, int endIndex) {

        double currentAskVolume = 0, currentBidVolume = 0;

        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }

        if (startIndex > endIndex) {
            return new IndicatorResult(0, 0);
        }

        int i, j;

        for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
           
            if(i >= iAskVolumes[4].length || i >= iBidVolumes[4].length){ //not enough data for calculation on the given candle
                continue;
            }

            //InputParameterInfo.Type.PRICE consists of 5 arrays open, close, high, low, volume -> volume is with index 4
            currentAskVolume = iAskVolumes[4][i];
            currentBidVolume = iBidVolumes[4][i];


            outputs[0][j] = (currentAskVolume + currentBidVolume);

            if (currentAskVolume >= currentBidVolume) {
                outputs[1][j] = -(currentAskVolume - currentBidVolume);
                outputs[2][j] = Double.NaN;
            } else if (currentAskVolume < currentBidVolume) {
                outputs[2][j] = -(currentBidVolume - currentAskVolume);
                outputs[1][j] = Double.NaN;
            }
        }

        return new IndicatorResult(startIndex, j);
    }

    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

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

    public int getLookback() {
        return 5;
    }

    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) {
        switch (index) {
        case 0:
            iAskVolumes = (double[][]) array;
            break;
        case 1:
            iBidVolumes = (double[][]) array;
            break;
        default:
            throw new ArrayIndexOutOfBoundsException(" setInputParameter(). Invalid index: " + index);
        }
    }

    public void setOptInputParameter(int index, Object value) {

    }

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

    private void print(String sss) {
        context.getConsole().getOut().println(sss);
    }

}
////////////////////////////////////////////////////////////////


Attachments:
AskBidVolumeIndiPrice2.java [5.34 KiB]
Downloaded 322 times
MarketDepth_V1.java [1.47 KiB]
Downloaded 302 times
FullMarketDepth.java [3.52 KiB]
Downloaded 337 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: indicator AskBidVolumes Post rating: 1   New post Posted: Sun 20 Jan, 2019, 12:59 

User rating: 6
Joined: Tue 30 Oct, 2012, 19:39
Posts: 14
Thanks so much


 
 Post subject: Re: indicator AskBidVolumes Post rating: 1   New post Posted: Thu 14 Mar, 2019, 20:22 

User rating: 6
Joined: Tue 30 Oct, 2012, 19:39
Posts: 14
a little complicated... It is easier to compare the values of the volume indicator by ASK and BID separately... However, thank you very much


 

Jump to:  

  © 1998-2024 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