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.

Horizontal Line at a specific Price
 Post subject: Horizontal Line at a specific Price Post rating: 0   Post Posted: Mon 18 Jul, 2011, 21:11 

User rating: 0
Joined: Wed 13 Jul, 2011, 17:59
Posts: 17
Location: United States,
Hello Every one:

I`m very new to Jforex platform and I need to draw Multiple line at a specific price ...

Can you help me PLEASE !!


 
 Post subject: Re: Horizontal Line at a specific Price Post rating: 0   Post Posted: Tue 19 Jul, 2011, 08:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
see links and example stategy in:
viewtopic.php?f=61&t=39377


 
 Post subject: Re: Horizontal Line at a specific Price Post rating: 0   Post Posted: Tue 19 Jul, 2011, 14:29 

User rating: 0
Joined: Wed 13 Jul, 2011, 17:59
Posts: 17
Location: United States,
Ok, Thanks alot ...

I tried to convert the Strategy ( From your Example ) to an Indicators which draw multiple Lines .... But Unfortunately it didn`t work ...

package charts.test;

import java.awt.Color;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.util.UUID;

import javax.swing.SwingConstants;


import com.dukascopy.api.*;
import com.dukascopy.api.IChartObject.ATTR_INT;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.IIndicators.MaType;
import com.dukascopy.api.drawings.IChartObjectFactory;
import com.dukascopy.api.drawings.IHorizontalLineChartObject;
import com.dukascopy.api.drawings.ILongLineChartObject;
import com.dukascopy.api.drawings.IShortLineChartObject;

public class Samer implements IIndicator {
   
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IChart chart;
   
   
    @Configurable("Instrument")
    public Instrument instrument = Instrument.EURUSD;
    @Configurable("PriceA")
    public double PriceA = 1.44;
    @Configurable("PriceB")
    public double PriceB = 1.45;   
   
    private SimpleDateFormat sdf;
    private ITick lastTick;
   
   
   public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.chart = context.getChart(instrument);

        sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
       
       
       
        lastTick = history.getLastTick(instrument);
        drawLines(lastTick.getAsk());
    }

    //draws two horizontal lines - one 5 pips above the price, the other - 5 pips below the price
    private void drawLines(double price){
       
        IChartObjectFactory factory = chart.getChartObjectFactory();
       
        IHorizontalLineChartObject lineA = factory.createHorizontalLine("lineA", PriceA);
        lineA.setColor(Color.GREEN);
        lineA.setAttrInt(ATTR_INT.WIDTH, 2);
        lineA.setText(" A line ", SwingConstants.CENTER);
        //unlocked means that you can select the line and move it while strategy is running
        chart.addToMainChartUnlocked(lineA);
       
        IHorizontalLineChartObject lineB = factory.createHorizontalLine("lineB", PriceB);
        lineB.setColor(Color.RED);
        lineB.setAttrInt(ATTR_INT.WIDTH, 2);
        lineB.setText(" B line ", SwingConstants.CENTER);
        chart.addToMainChartUnlocked(lineB);
       
    }
   
   
    private void print(Object message) {
        console.getOut().println(message);
    }
   
}


 
 Post subject: Re: Horizontal Line at a specific Price Post rating: 0   Post Posted: Tue 19 Jul, 2011, 15:59 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
For creating your first indicator in JForex please refer to:
https://www.dukascopy.com/wiki/index.php ... _indicator
and:
https://www.dukascopy.com/wiki/index.php ... _Indicator


 

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