Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Code works in Historical Tester while back testing but not in DEMO forward testing.
 Post subject: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Thu 11 Jan, 2018, 14:23 

User rating: 1
Joined: Mon 01 Sep, 2014, 13:39
Posts: 34
Location: AustraliaAustralia
Hi,

I have a strategy which works in Historical Tester while backtesting and when I run the strategy in DEMO Remote Server it exits. I believe the line in red is the problem as it runs properly when I remove it and hard code a value for pipAmount. The blue line is from the log of the backtest, showing that it works as expected by returning a value of 0.00009. API Version is 3.0.18.

acc=USD ins=GBP/JPY getEquity=48935 getBalance=48935 slPips=0.24000 riskAmount=979 pipAmount=0.00009 pipValue=0.01000 slPips10=24.00000 riskPips=207.98489 lots=0.47000 riskPips2=200.49435 lots2=0.98000 position=0.66000

Here is the method and the erroneous line is below in red, basically the first line of code. Now is this a bug? It would seem so if it works in one environment and not another.

double pipAmount = myJFUtils.convertPipToCurrency(tradeIns, myAccount.getAccountCurrency());

Thanks,
Chrysos.

    private double calculatePosition(int posType, Instrument tradeIns, double getEquity, double entry, double slPips, double atrPips, double pipValue) throws JFException {
        double pipAmount = myJFUtils.convertPipToCurrency(tradeIns, myAccount.getAccountCurrency());
        double riskAmount = getEquity * (myRisk / 100d);
        double slPips10   = slPips / pipValue;
        double riskPips   = slPips10 * pipAmount * 100000d;
        double lots       = round((riskAmount / riskPips) / 10d, 2);
       
        double atrPips10  = atrPips / pipValue;
        double riskPips2  = atrPips10 * pipAmount * 100000d;
        double lots2      = round((riskAmount / riskPips2) / 10d, 2) * 2d;
       
        double position = round((((myRisk / 100d) * getEquity * entry) / (slPips * pipAmount * 10000d)) / 1000000d, 2);
       
        print2(String.format("acc=%s ins=%s getEquity=%.0f getBalance=%.0f slPips=%.05f riskAmount=%.0f pipAmount=%.05f pipValue=%.05f slPips10=%.05f riskPips=%.05f lots=%.05f riskPips2=%.05f lots2=%.05f position=%.05f",  myAccount.getAccountCurrency(), tradeIns, getEquity, myAccount.getBalance(), slPips, riskAmount, pipAmount, pipValue, slPips10, riskPips, lots, riskPips2, lots2, position));

             if (posType == 1)
                 return lots; 
        else if (posType == 2)
                 return lots2;
       
        return lots;
    }


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Fri 12 Jan, 2018, 17:37 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Cannot reproduce. Please, provide strategy example.


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Sun 14 Jan, 2018, 15:53 

User rating: 1
Joined: Mon 01 Sep, 2014, 13:39
Posts: 34
Location: AustraliaAustralia
API Support wrote:
Cannot reproduce. Please, provide strategy example.

Hi and thanks for the response,

I'd like to do that but I'd like to run the strategy with the latest API, but now that has given me trouble. Here's the errors I get.

Description   Resource   Path   Location   Type
The project cannot be built until build path errors are resolved   JForex-3-SDK      Unknown   Java Problem
Missing artifact com.dukascopy:dev-tools:jar:0.0.29   pom.xml   /JForex-3-SDK   line 8    Maven Dependency Problem
Missing artifact com.dukascopy.dds2:Login-Form:jar:2.6   pom.xml   /JForex-3-SDK   line 8    Maven Dependency Problem
Missing artifact com.dukascopy.api:JForex-API:jar:2.13.46   pom.xml   /JForex-3-SDK   line 8    Maven Dependency Problem
The container 'Maven Dependencies' references non existing library 'C:\Users\CHRYSOS\.m2\repository\com\dukascopy\api\JForex-API\2.13.46\JForex-API-2.13.46.jar'   JForex-3-SDK      Build path   Build Path Problem


It says line 8 of the POM file is in error. Line 8 is the 2nd line below.
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Mon 15 Jan, 2018, 09:31 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
For some reason Maven doesn't see JForex API jar file.
1)Check location('C:\Users\CHRYSOS\.m2\repository\com\dukascopy\api\JForex-API\2.13.46\JForex-API-2.13.46.jar') for the presence of jar file.
2)Open cmd from JForex SDK folder and do 'mvn clean install'


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Mon 15 Jan, 2018, 11:45 

User rating: 1
Joined: Mon 01 Sep, 2014, 13:39
Posts: 34
Location: AustraliaAustralia
Hi,

I tried what you suggested - go to CMD in the JForex-3-SDK directory and it said command 'mvn' and 'mvn clean install' not a recognized internal, external or batch command.

Here is what is in directory of C:\Users\CHRYSOS\.m2\repository\com\dukascopy\api\JForex-API\2.13.46

It seems the JForex-API-2.13.46.jar file has a Type of LASTUPDATED as well as .lastUpdated extension and the dates are 26/12/2017.

 Directory of C:\Users\CHRYSOS\.m2\repository\com\dukascopy\api\JForex-API\2.13.46

15/01/2018  09:16 PM    <DIR>          .
15/01/2018  09:16 PM    <DIR>          ..
26/12/2017  03:06 PM           605,164 JForex-API-2.13.46-sources.jar
26/12/2017  03:06 PM                40 JForex-API-2.13.46-sources.jar.sha1
26/12/2017  03:06 PM               385 JForex-API-2.13.46.jar.lastUpdated
26/12/2017  03:05 PM             5,254 JForex-API-2.13.46.pom
26/12/2017  03:05 PM                40 JForex-API-2.13.46.pom.sha1
26/12/2017  03:06 PM               207 _maven.repositories


Can I back out of this and install the SDK as I did the very first time? I have the code saved elsewhere and I can just copy it. That means I would have to delete the .m2 directory and what else?

Thanks,
Chrysos.


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Mon 15 Jan, 2018, 14:10 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Seems like you have some problem with dependency references in pom.xml. Have you also updated JClient version? You can copy and post here all code inside <dependecies></dependecies> tags
And i advise you to install Maven: https://maven.apache.org/install.html


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Mon 15 Jan, 2018, 15:20 

User rating: 1
Joined: Mon 01 Sep, 2014, 13:39
Posts: 34
Location: AustraliaAustralia
API Support wrote:
Seems like you have some problem with dependency references in pom.xml. Have you also updated JClient version? You can copy and post here all code inside <dependecies></dependecies> tags
And i advise you to install Maven: https://maven.apache.org/install.html

I haven't updated the JClient but I did install Maven and run the command 'mvn clean install'. I now have 3 errors but importantly, my Java strategy is error free and compiles. However, it behaves worse than before. It only runs for a couple of minutes and stops even though I have commented the line I think is the problem.

Now this line causes a problem.

IBar prevBar = myHistory.getBar(instrument, period, OfferSide.BID, 1);


- Description Resource Path Location Type
07:40:00 Strategy tester: com.dukascopy.api.JFException: Could not load bar for instrument [EUR/GBP], period [5 Mins], side [Bid], start time [2017.12.11 07:35:00 000], current bar start time [2017.12.11 07:40:00 000] @ cgm.EMA_MACD.onBar(EMA_MACD.java:296)

Errors from build.
Description   Resource   Path   Location   Type
Missing artifact com.dukascopy:dev-tools:jar:0.0.29           pom.xml   /JForex-3-SDK   line 8    Maven Dependency Problem
Missing artifact com.dukascopy.dds2:Login-Form:jar:2.6   pom.xml   /JForex-3-SDK   line 8 Maven Dependency Problem
Missing artifact com.dukascopy.api:JForex-API:jar:2.13.46   pom.xml   /JForex-3-SDK   line 8 Maven Dependency Problem


Please tell me how to completely uninstall everything so I can install it all again so I can start as new.

I delete the workspace, then what about directory C:\Users\CHRYSOS\.m2, C:\Users\CHRYSOS\.jmc ?


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Wed 17 Jan, 2018, 00:06 

User rating: 1
Joined: Mon 01 Sep, 2014, 13:39
Posts: 34
Location: AustraliaAustralia
Alright, I've fixed the problems with the API, but the original strategy problem still stands. It runs in backtest, but not in real time DEMO. How can I look at the log of it running on real time DEMO? The logs in C:\Users\UserName\JForex\logs do not seem to show where the error occurs.

Here is the error. I then comment some code out and get the second error - overload. What is wrong? How can I look at the logs to fix this? There appear to not be too be useful logs for Remote Server strategies. The strategy subscribes to 15 instruments. It would seem this might cause a problem, but why?

22:50:18 Strategy "EMA_MACD" is stopped at 2018-01-16 22:50:18.927 GMT on the remote server with parameters "MACD Multiplier:"=[0], "Period to use:"=[5 Mins], "Large MA Value:"=[89], "MACD MA Type:"=[SMA], "Medium MA Value:"=[21], "Use Large MA Filter:"=[false], "MACD signalPeriod:"=[8], "Slow MA Value:"=[55], "Log 2 Enabled:"=[false], "MA Type:"=[EMA], "RSI +/- 50:"=[0], "TP Multiplier:"=[1.5], "Take Profit:"=[0], "Fast MA Value:"=[13], "Log 3 Enabled:"=[true], "Begin Trade hour:"=[4], "Stop Loss:"=[0], "Trade weekends:"=[false], "MACD slowPeriod:"=[21], "SL Management:"=[2], "Instrument to use:"=[EUR/USD], "N Bars Forward:"=[5], "Control time:"=[false], "SL Type:"=[2], "SS +/- 80/20:"=[0.0], "SStoch fast K Period:"=[5], "Large MA Value:"=[SMA], "Log 1 Enabled:"=[false], "ATR Multiplier:"=[2.0], "End trade hour"=[21], "MACD fastPeriod:"=[8], "Positioning Type:"=[1], "Profit Percent:"=[0.7], "RSI Period:"=[15], "Increase Deposit:"=[40.0], "Risk % (100/risk):"=[2.0], "Max spread allowed:"=[4.0]. Reason: Strategy <EMA_MACD> is going to be stopped - due to caught exception from strategy.

23:12:40 Strategy "EMA_MACD" is stopped at 2018-01-16 23:12:40.816 GMT on the remote server with parameters "MACD Multiplier:"=[0], "Period to use:"=[5 Mins], "Large MA Value:"=[89], "MACD MA Type:"=[SMA], "Medium MA Value:"=[21], "Use Large MA Filter:"=[false], "MACD signalPeriod:"=[8], "Slow MA Value:"=[55], "Log 2 Enabled:"=[false], "MA Type:"=[EMA], "RSI +/- 50:"=[0], "TP Multiplier:"=[1.5], "Take Profit:"=[0], "Fast MA Value:"=[13], "Begin Trade hour:"=[4], "Stop Loss:"=[0], "Trade weekends:"=[false], "MACD slowPeriod:"=[21], "SL Management:"=[2], "Instrument to use:"=[EUR/USD], "N Bars Forward:"=[5], "Control time:"=[false], "SL Type:"=[2], "SS +/- 80/20:"=[0.0], "SStoch fast K Period:"=[5], "Large MA Value:"=[SMA], "Log 1 Enabled:"=[false], "ATR Multiplier:"=[2.0], "End trade hour"=[21], "MACD fastPeriod:"=[8], "Positioning Type:"=[1], "Profit Percent:"=[0.7], "RSI Period:"=[15], "Increase Deposit:"=[40.0], "Log 3 Enabled:"=[false], "Risk % (100/risk):"=[2.0], "Max spread allowed:"=[4.0]. Reason: Strategy <EMA_MACD> is going to be stopped - Max overload period exceeded : 60 seconds


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Wed 17 Jan, 2018, 10:07 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
By this information isn't possible to identify problem.
Write on [email protected]. Attach your strategy


 
 Post subject: Re: Code works in Historical Tester while back testing but not in DEMO forward testing. Post rating: 0   New post Posted: Fri 19 Jan, 2018, 11:26 

User rating: 1
Joined: Mon 01 Sep, 2014, 13:39
Posts: 34
Location: AustraliaAustralia
Thanks,

I am going to try to add some asynchronous coding for subscribing to instruments and getting historical data and then send the strategy to support.

Regards,
Chrysos.


 

Jump to:  

  © 1998-2024 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