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.

Drawing text attached to bars
 Post subject: Drawing text attached to bars Post rating: 0   New post Posted: Fri 16 Mar, 2018, 02:05 

User rating: 0
Joined: Fri 02 Mar, 2018, 04:23
Posts: 12
Location: Cambodia,
I'd like to draw text objects either attached to a bar's high or low, or anchored an arbitrary distance in pixels from a (time, price) coordinate. Is there any way to do that?

Thanks.


 
 Post subject: Re: Drawing text attached to bars Post rating: 0   New post Posted: Fri 16 Mar, 2018, 12:06 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You can do it by using ITextChartObject interface. https://www.dukascopy.com/wiki/en/development/strategy-api/chart-objects/chart-object-catalog#text


 
 Post subject: Re: Drawing text attached to bars Post rating: 0   New post Posted: Fri 16 Mar, 2018, 15:34 

User rating: 0
Joined: Fri 02 Mar, 2018, 04:23
Posts: 12
Location: Cambodia,
API Support wrote:


Thanks for your reply. I see on that page and in the javadocs where it discusses drawing in the time/price coordinate system, but it's unclear to me how I could either use those APIs to attach text to a bar (so that it would always show right above or right below the bar, move with the bar as it grows upwards and downwards, and be a fixed pixel distance from the bar regardless of zoom settings) or how I could draw a label at a fixed pixel offset from a time/price coordinate (for example, draw 5 pixels above and 2 pixels left of price = 1.1, time = Wednesday at midnight).

If either those things can be done, could you point me closer toward the documentation for doing things like that?

Thanks again.


 
 Post subject: Re: Drawing text attached to bars Post rating: 0   New post Posted: Fri 16 Mar, 2018, 16:58 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
More about ITextChartObject and other Chart objects you can read in javadoc - https://www.dukascopy.com/client/javadoc3/com/dukascopy/api/drawings/ITextChartObject.html

Example:
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IChart;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
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;
import com.dukascopy.api.drawings.IChartObjectFactory;
import com.dukascopy.api.drawings.ITextChartObject;
import java.awt.Color;

public class ITextChartObjectExampleStrategy implements IStrategy {
  private IEngine engine;
  private IConsole console;
  private IHistory history;
  private IContext context;
  private IIndicators indicators;
  private IUserInterface userInterface;
  private IChart chart;

  Instrument instrument = Instrument.EURUSD;
  Period period = Period.ONE_MIN;

  ITextChartObject textChartObject;
  double highestBarValue;

  public void onStart(IContext context) throws JFException {
    this.engine = context.getEngine();
    this.console = context.getConsole();
    this.history = context.getHistory();
    this.context = context;
    this.indicators = context.getIndicators();
    this.userInterface = context.getUserInterface();
    this.chart = context.getChart(instrument);
  }

  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 {
  }

  public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    if (this.period != period || this.instrument != instrument) {
      return;
    }
    if (askBar.getHigh() > highestBarValue) {
      drawNewHighestBarValue(askBar);
      highestBarValue = askBar.getHigh();
    }

  }

  private void drawNewHighestBarValue(IBar bar) {
    if (textChartObject == null) {
      IChartObjectFactory chartObjectFactory = chart.getChartObjectFactory();
      textChartObject = chartObjectFactory.createText();
      textChartObject.setText("Highest Bar");
      textChartObject.setColor(Color.RED);
      textChartObject.setPrice(0, bar.getHigh());
      textChartObject.setTime(0, bar.getTime());
      chart.add(textChartObject);
    } else {
      textChartObject.move(bar.getTime(), bar.getHigh());
    }
  }
}


 

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