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.

Equivalents for MetaTrader functions?
 Post subject: Equivalents for MetaTrader functions? Post rating: 0   New post Posted: Mon 16 Feb, 2009, 04:05 

User rating: 0
Joined: Mon 22 Dec, 2008, 13:00
Posts: 17
Greetings to Dukas IT team!

In MetaTrader, there are certain functions such as MarketInfo( ) that provide basic real-time information about an instrument/market, etc. Please take a look below and if possible, can you provide code snippets as to how these functions can be implemented in JForex:

MarketInfo(Symbol(), MODE_MAXLOT) - this function returns the Maximum lot size in MT4 for the specified Instrument, which is indicated by Symbol(). I'm guessing that, in JForex, the maximum order size would depend on the remaining Trading Line. I know there's a function getCreditLine() under the IAccount interface. But how do I call this function in start() itself? I declared this line (private IAccount account = null;) at the top of my strategy's code, but if I attempt to call getCreditLine() under start(), I get an error.


MarketInfo(Symbol(), MODE_SPREAD) - This one returns the real-time spread in MT4 for the specified instrument. Is there a function in JForex that can do this?


As I come up with more questions about such MT4 functions, i shall post them here. If there's anyone else over here who has written your own equivalent code for any of the ready-made MT4 functions, kindly share them if you will...

Thanx in advance!


 
 Post subject: Re: Equivalents for MetaTrader functions? Post rating: 0   New post Posted: Mon 16 Feb, 2009, 17:58 

User rating: 0
Joined: Mon 22 Dec, 2008, 13:00
Posts: 17
In the meantime, I'm posting a few snippets that I coded (with the help of examples from this forum) to correspond with some of the MT4 functions. Those of you who're good at coding in MT4 and JForex, please make suggestions or contribute here:

NormalizeDouble( , )
double NormalizeDouble(double operand, int numofdigits) {
   if(numofdigits>5) numofdigits=5;
   String decimalplaces="###0.";
   for(int i=0; i<numofdigits; i++){
      decimalplaces += "0";
   }
   DecimalFormat applydeci = new DecimalFormat(decimalplaces);
   Double result = new Double(applydeci.format(operand)).doubleValue();
   return(result);
}


DayOfWeek( )
int DayOfWeek(long currtime) {
        // You have to pass tick.getTime() as the parameter currtime
   Calendar newCal = Calendar.getInstance(TimeZone.getTimeZone("GMT 0"));
   newCal.setTimeInMillis(currtime);
   int daynum = newCal.get(Calendar.DAY_OF_WEEK);
        return(daynum);
}


Hour( )
int Hour(long currtime){
        // Similar to DayOfWeek, pass tick.getTime() as the parameter currtime
   Calendar newCal = Calendar.getInstance(TimeZone.getTimeZone("GMT 0"));
   newCal.setTimeInMillis(currtime);
   int hour = newCal.get(Calendar.HOUR_OF_DAY);
   return(hour);
}


Minute( )
int Minute(long currtime){
        // Similar to DayOfWeek, pass tick.getTime() as the parameter currtime
   Calendar newCal = Calendar.getInstance(TimeZone.getTimeZone("GMT 0"));
   newCal.setTimeInMillis(currtime);
   int mins = newCal.get(Calendar.MINUTE);
   return(mins);
}


 

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