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.

who can help me convert a KDJcross MT4 strategy into java?
 Post subject: who can help me convert a KDJcross MT4 strategy into java? Post rating: 0   New post Posted: Fri 02 Apr, 2010, 09:40 

User rating: -
HI,all kind classmates,who can help me convert a KDJcross MT4 strategy into java?
I am not good at speaking.The best wishes and too much 3KS to you,god bless those kind man!!

extern int total=1;
extern int PPP=10;
extern int MN=666666;
extern double Lots =1;
extern double TP =0.0010;
extern double SL =0.0030;
extern int starthour=8;
extern int endhour=12;


int init()
  {
   return(0);
  }

int deinit()
  {
   return(0);
  }




int start()
  {     
    double K1=iStochastic(NULL, PERIOD_M15, 8, 3, 3,MODE_SMA, 0, MODE_MAIN, 1);
    double K2=iStochastic(NULL, PERIOD_M15, 8, 3, 3,MODE_SMA, 0, MODE_MAIN, 2);
    double D1=iStochastic(NULL, PERIOD_M15, 8, 3, 3,MODE_SMA, 0, MODE_SIGNAL, 1);
    double D2=iStochastic(NULL, PERIOD_M15, 8, 3, 3,MODE_SMA, 0, MODE_SIGNAL, 2);
   
   if (TimeHour(CurTime())>=starthour && TimeHour(CurTime())<=endhour)
 
  {
  if(D2>K2 && D1<K1 && D1<=20) openbuy();
  if(D2<K2 && D1>K1 && D1>=80) opensell();
  }
      return(0);
    }
 




int openbuy()
 { 
   int totals=OrdersTotal();
   int k,cnt=0;
   for(k=0;k<totals;k++)
  {
    OrderSelect(k, SELECT_BY_POS, MODE_TRADES); 
    if(OrderType()==OP_BUY && OrderSymbol() == Symbol()&& OrderMagicNumber() == MN) cnt++;
  }
    if (cnt<total)
    OrderSend(Symbol(),OP_BUY,Lots,Ask,PPP,Ask-SL,Ask+TP,"My order buy",MN,0,Green);
   
   return(0);
 
 }
 

int opensell()
 {
   int totals=OrdersTotal();
   int h,cntt=0;
   for(h=0;h<totals;h++)
  {
    OrderSelect(h, SELECT_BY_POS, MODE_TRADES); 
    if(OrderType()==OP_SELL && OrderSymbol() == Symbol()&& OrderMagicNumber() == MN) cntt++;
  }
    if (cntt<total)
    OrderSend(Symbol(),OP_SELL,Lots,Bid,PPP,Bid+SL,Bid-TP,"My order SELL",MN,0,Green);
   
   return(0);
 }


 
 Post subject: Re: who can help me convert a KDJcross MT4 strategy into java? Post rating: 0   New post Posted: Mon 05 Apr, 2010, 17:31 

User rating: 0
Joined: Fri 02 Apr, 2010, 19:59
Posts: 20
Location: South West England
Using my shiny new version 2.2.10 it converted, compiled and ran OK for me.

Jim


 
 Post subject: Re: who can help me convert a KDJcross MT4 strategy into jav Post rating: 0   New post Posted: Fri 14 May, 2010, 09:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The problem is that it is not an indicator but a strategy

We have opened your code as a Strategy and converted to JForex

package jforex.converted;
import java.awt.Color;
import com.dukascopy.api.*;
public class KDJ extends ConnectorStrategy {


@Configurable("") public int total=toInt(1);
@Configurable("") public int PPP=toInt(10);
@Configurable("") public int MN=toInt(666666);
@Configurable("") public double Lots=toDouble(1);
@Configurable("") public double TP=toDouble(0.0010);
@Configurable("") public double SL=toDouble(0.0030);
@Configurable("") public int starthour=toInt(8);
@Configurable("") public int endhour=toInt(12);

protected int start() throws JFException {
double K1 = 0.0;
double K2 = 0.0;
double D1 = 0.0;
double D2 = 0.0;

K1 = toDouble(iStochastic(null,PERIOD_M15,8,3,3,MODE_SMA,0,MODE_MAIN,1));

K2 = toDouble(iStochastic(null,PERIOD_M15,8,3,3,MODE_SMA,0,MODE_MAIN,2));

D1 = toDouble(iStochastic(null,PERIOD_M15,8,3,3,MODE_SMA,0,MODE_SIGNAL,1));

D2 = toDouble(iStochastic(null,PERIOD_M15,8,3,3,MODE_SMA,0,MODE_SIGNAL,2));

if (Bool(TimeHour(CurTime()) >= starthour && TimeHour(CurTime()) <= endhour)){

if (Bool(D2 > K2 && D1 < K1 && D1 <= 20)){

openbuy();
}
if (Bool(D2 < K2 && D1 > K1 && D1 >= 80)){

opensell();
}}
if(true)return toInt(0);return 0;
}

int openbuy() throws JFException {
int totals = 0;
int k = 0;
int cnt=toInt(0);

totals = toInt(OrdersTotal());

for(k=(int)0;k<totals;k++){

OrderSelect(k,SELECT_BY_POS,MODE_TRADES);

if (Bool(OrderType() == OP_BUY && OrderSymbol().equals(Instrument()) && OrderMagicNumber() == MN)){

cnt++;
}
}

if (Bool(cnt < total)){

OrderSend(Instrument(),OP_BUY,Lots,Ask,PPP,Ask-SL,Ask+TP,"My order buy",MN,0,Green);
}
if(true)return toInt(0);return 0;
}

int opensell() throws JFException {
int totals = 0;
int h = 0;
int cntt=toInt(0);

totals = toInt(OrdersTotal());

for(h=(int)0;h<totals;h++){

OrderSelect(h,SELECT_BY_POS,MODE_TRADES);

if (Bool(OrderType() == OP_SELL && OrderSymbol().equals(Instrument()) && OrderMagicNumber() == MN)){

cntt++;
}
}

if (Bool(cntt < total)){

OrderSend(Instrument(),OP_SELL,Lots,Bid,PPP,Bid+SL,Bid-TP,"My order SELL",MN,0,Green);
}
if(true)return toInt(0);return 0;
}


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


 
 Post subject: Re: who can help me convert a KDJcross MT4 strategy into jav Post rating: 0   New post Posted: Fri 29 Oct, 2010, 11:32 

User rating: -
To be honest, I think the platform doesn't like MT4-Codes at all. I couldn't manage to convert any MT4-Strategy using the "Compile" -Function. The message board was full of error messages.

Even the code above provided by the support won't work. I got this message:

Quote:
10:28:14 com.dukascopy.api.JFException: Parse exception, Encountered " <ID> "package "" at line 1, column 1.
Was expecting: <EOF>


 
 Post subject: Re: who can help me convert a KDJcross MT4 strategy into jav Post rating: 0   New post Posted: Fri 21 Jan, 2011, 19:34 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
It is already converted code. There is no need to convert it twice.


 

Jump to:  

cron
  © 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