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.

MQL4 ObjectFind analog
 Post subject: MQL4 ObjectFind analog Post rating: 0   New post Posted: Tue 08 Nov, 2011, 22:41 

User rating: 0
Joined: Sat 06 Aug, 2011, 23:17
Posts: 27
Location: Russian Federation,
Hellow everyone. I need mql4 ObjectFind https://docs.mql4.com/objects/objectfind analog.

Thanks for help.


 
 Post subject: Re: MQL4 ObjectFind analog Post rating: 0   New post Posted: Tue 08 Nov, 2011, 23:24 

User rating: 0
Joined: Sat 06 Aug, 2011, 23:17
Posts: 27
Location: Russian Federation,
2) And i create horisontal line:

double price1 = (tick.getAsk() + tick.getBid()) / 2;
IHorizontalLineChartObject hLine = chart.getChartObjectFactory().createHorizontalLine("hLine",
    tick.getTime(), price1
);
chart.addToMainChart(hLine);


How to get price from this line (hLine) ?


 
 Post subject: Re: MQL4 ObjectFind analog Post rating: 0   New post Posted: Wed 09 Nov, 2011, 08:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You can find objects by key. See if the following example helps:
package charts.test;

import com.dukascopy.api.*;
import com.dukascopy.api.drawings.IHorizontalLineChartObject;

public class HLineKey implements IStrategy {

   private IChart chart;
   private IHistory history;
   
   @Override
   public void onStart(IContext context) throws JFException {
      this.chart = context.getChart(Instrument.EURUSD);
      this.history = context.getHistory();
      ITick tick = history.getLastTick(Instrument.EURUSD);   

      double price1 = (tick.getAsk() + tick.getBid()) / 2;
      
      IHorizontalLineChartObject hLine = chart.getChartObjectFactory().createHorizontalLine();
      hLine.setPrice(0, price1);
      hLine.setTime(0, tick.getTime());
      chart.addToMainChartUnlocked(hLine);
      
      String hLineKey = hLine.getKey();
      IChartObject obj = chart.get(hLineKey);
      //note that if object does not have 0th price attribute, an exception will get thrown
      context.getConsole().getOut().println("hLineKey="+hLineKey+" object price="+obj.getPrice(0));
      
   }
   public void onTick(Instrument instrument, ITick tick) throws JFException {   }
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
   public void onMessage(IMessage message) throws JFException {}
   public void onAccount(IAccount account) throws JFException {}
   public void onStop() throws JFException {}
}


 
 Post subject: Re: MQL4 ObjectFind analog Post rating: 0   New post Posted: Wed 09 Nov, 2011, 15:16 

User rating: 0
Joined: Sat 06 Aug, 2011, 23:17
Posts: 27
Location: Russian Federation,
May i use hLine.getPrice(0); ?


 
 Post subject: Re: MQL4 ObjectFind analog Post rating: 0   New post Posted: Wed 09 Nov, 2011, 15:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Pirate wrote:
May i use hLine.getPrice(0); ?
Of course. The example just was designed to answer to both of your questions.


 
 Post subject: Re: MQL4 ObjectFind analog Post rating: 0   New post Posted: Wed 09 Nov, 2011, 20:29 

User rating: 0
Joined: Sat 06 Aug, 2011, 23:17
Posts: 27
Location: Russian Federation,
Thanks for help and nice day ;)


 

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