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.

JFOREX SDK - How to convert
 Post subject: JFOREX SDK - How to convert Post rating: 0   New post Posted: Thu 08 May, 2014, 11:04 
User avatar

User rating: 6
Joined: Tue 11 Feb, 2014, 11:38
Posts: 60
Location: PolandPoland
Hi,
how to convert this c# to java strategies

        protected void comparePositions()
        {
 
            try
            {
 // position string
                string inp = "" + responseFromServer;
                // cut [GO] and [OG]
                inp = inp.Substring(4);
                inp = inp.Substring(0, inp.Length - 6);
 
                // pociapać na pozycję lista
                string[] posin = inp.Split('|');
                PosServerAll = new List<string>(posin);
 
                initializePositions();
 
                Print("OPEN POS LIST ===============================");
                // Loop through List with foreach
                foreach (string prime in PosOpenID)
                {
                    Print("OPEN POS ID " + prime);
                }
 
                Print("CLOSE POS LIST ===============================");
                // Loop through List with foreach
                foreach (string prime1 in PosCloseID)
                {
                    Print("CLOSE POS ID " + prime1);
                }
 
 
                foreach (string pos in posin)
                {
                    Print(pos);
                    string[] p = pos.Split(';');
 
                    if (!PosOpenID.Contains(p[0]) && p[0] != "" && !PosCloseID.Contains(p[0]))
                    {
 
                        Symbol symbol = MarketData.GetSymbol(p[1]);
 
                        if (p[2] == "BUY")
                        {
                            Print("BUY " + p[1]);
                            double pips1 = Convert.ToDouble(p[4]) - Convert.ToDouble(p[5]);
                            double sl1 = pips1 / symbol.PipSize;
                            double pips2 = Convert.ToDouble(p[6]) - Convert.ToDouble(p[4]);
                            double tp1 = pips2 / symbol.PipSize;
                            ExecuteMarketOrder(TradeType.Buy, symbol, Convert.ToInt64(Convert.ToDecimal(p[3])), "", sl1, tp1, 1, p[0]);
 
                            //ExecuteMarketOrder(TradeType.Buy, Symbol, Convert.ToInt64(Convert.ToDecimal(p[4])), "Slave", Convert.ToDouble(p[6]), Convert.ToDouble(p[7]));
                        }
 
                        if (p[2] == "SELL")
                        {
                            Print("SELL " + p[1]);
                            double pips1 = Convert.ToDouble(p[5]) - Convert.ToDouble(p[4]);
                            double sl = pips1 / symbol.PipSize;
                            double pips2 = Convert.ToDouble(p[4]) - Convert.ToDouble(p[6]);
                            double tp = pips2 / symbol.PipSize;
                            ExecuteMarketOrder(TradeType.Sell, symbol, Convert.ToInt64(Convert.ToDecimal(p[3])), "", sl, tp, 1, p[0]);
                            //ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, MyLabel, StopLoss, TakeProfit);
                        }
                    }
                    initializePositions();
                }
 
            } catch (Exception rrr)
            {
                Print(rrr);
            }
        }


Regards


 
 Post subject: Re: JFOREX SDK - How to convert Post rating: 0   New post Posted: Thu 08 May, 2014, 15:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The simplest way would be to rewrite the code in java.


 
 Post subject: Re: JFOREX SDK - How to convert Post rating: 0   New post Posted: Thu 08 May, 2014, 15:34 
User avatar

User rating: 6
Joined: Tue 11 Feb, 2014, 11:38
Posts: 60
Location: PolandPoland
Support is amazing :lol:


 
 Post subject: Re: JFOREX SDK - How to convert Post rating: 1   New post Posted: Fri 09 May, 2014, 00:47 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
C# is such a rip-off of Java that I found it very
natural to code Java-type idioms in C# using
Microsoft Visual Studio, with decent threading.

But the rewrite is absolutely the best way to go,
there ain't any translator that will do it right
for you.

Once you understand the IStrategy interface and
callback sequences, you should find it easy to
slot that logic in and make a working strategy.

HyperScalper


 
 Post subject: Re: JFOREX SDK - How to convert Post rating: 0   New post Posted: Fri 09 May, 2014, 08:18 
User avatar

User rating: 6
Joined: Tue 11 Feb, 2014, 11:38
Posts: 60
Location: PolandPoland
Hi,

so also suspected but I thought that instead of writing someone so much smarter peek and write this code in 5 minutes.
I have to bury the whole day :P

how to replace the instrument, depending on the string we have in the array to not write the condition for each currency for create order?

How to subscribe All instruments?
And why position label cant be the same for each positions?

Regards
zix


 
 Post subject: Re: JFOREX SDK - How to convert Post rating: 0   New post Posted: Fri 09 May, 2014, 09:06 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
zix wrote:
so also suspected but I thought that instead of writing someone so much smarter peek and write this code in 5 minutes.
I have to bury the whole day
In this forum we don't write the code for you, rather assist you such that you can write it yourself.
zix wrote:
how to replace the instrument, depending on the string we have in the array to not write the condition for each currency for create order?
You can use Instrument.fromString method to get the Instrument object. In case there is no direct match between the instrument names, consider making a java.util.Map which would map your instrument names to the JForex ones.
zix wrote:
How to subscribe All instruments?
See: https://www.dukascopy.com/wiki/#Subscribe_to_an_instrument
If you really want to subscribe all of the available instruments you can iterate over Instrument.values(), mind that only the available instruments will get subscribed.
zix wrote:
And why position label cant be the same for each positions?
This is a system restriction. If you want to identify positions by their label, consider using a prefix which is common to all of your positions.


 
 Post subject: Re: JFOREX SDK - How to convert Post rating: 0   New post Posted: Fri 09 May, 2014, 09:26 
User avatar

User rating: 6
Joined: Tue 11 Feb, 2014, 11:38
Posts: 60
Location: PolandPoland
Quote:
You can use Instrument.fromString method to get the Instrument object. In case there is no direct match between the instrument names, consider making a java.util.Map which would map your instrument names to the JForex ones.


Here was the point (and what support did not hurt) :lol:

Thanks
zix


 
 Post subject: Re: JFOREX SDK - How to close position Post rating: 0   New post Posted: Fri 09 May, 2014, 10:43 
User avatar

User rating: 6
Joined: Tue 11 Feb, 2014, 11:38
Posts: 60
Location: PolandPoland
it is possible closing off positions for the contest account from JForex sdk

and it is posible to create button to open positions for the contest account from JForex sdk

i want create small java wiget (show contest open position and allow open or close positon whitout open jForex platform)

Regards
zix


 
 Post subject: Re: JFOREX SDK - How to convert Post rating: 0   New post Posted: Fri 09 May, 2014, 11:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please ask contest-related questions in the Strategy Contest forum.


 
 Post subject: Bye Post rating: 0   New post Posted: Fri 09 May, 2014, 18:33 
User avatar

User rating: 6
Joined: Tue 11 Feb, 2014, 11:38
Posts: 60
Location: PolandPoland
Unfortunately, the next error in the Java and JForex SDK - have enough to fight with windmills.

fortunately is cAlgo with C# and. NET and fxcm C + + or C# .NET

java awful .... ugh.

Bye.


 

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