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.

Buy and Sell not triggered correctly.
 Post subject: Buy and Sell not triggered correctly. Post rating: 0   Post Posted: Fri 24 May, 2013, 09:10 

User rating: 0
Joined: Thu 09 May, 2013, 14:01
Posts: 9
Location: SingaporeSingapore
Hi,

I tried to create my first strategy based off the simple stochastic given in your wiki examples but seem to have some problems with it.

I am attaching the code and the output/debug messages which were obtained as output.

I am trying to trigger buy and sell based on the values of stochastic result[0]. But Buy and Sell seem to be triggered randomly. Can you please help. I know C programming but am completely new to java, so not sure if its a programming mistake.

Thanks,
Vamana.


Attachments:
File comment: Debug message file from historical testing the code for the last day.
Strategy_24052013_162220.csv [9.37 KiB]
Downloaded 314 times
File comment: code
Strategy.java [6.39 KiB]
Downloaded 350 times
File comment: Debug message file from historical testing the code for the last day.
Strategy_24052013_132648.csv [142.76 KiB]
Downloaded 326 times
File comment: Code
Strategy.java [6.28 KiB]
Downloaded 336 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Buy and Sell not triggered correctly. Post rating: 0   Post Posted: Fri 24 May, 2013, 12:01 

User rating: 0
Joined: Thu 09 May, 2013, 14:01
Posts: 9
Location: SingaporeSingapore
I have also set a stop loss of 10 pips in my submitOrder command but the loss in some cases exceeds the 10 pips per the html which pops up after the historical tester is run. Is there something wrong with the way I have set stop loss?

Vamana.


 
 Post subject: Re: Buy and Sell not triggered correctly. Post rating: 0   Post Posted: Fri 24 May, 2013, 16:08 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
vamana2734 wrote:
But Buy and Sell seem to be triggered randomly.
Consider adding more logging statements in the decision points, see:
https://www.dukascopy.com/wiki/#IConsole/Logging_values

Previous_Stoch = indicators.stoch(instrument, period, side, fastKPeriod, slowKPeriod, slowKMaType, slowDPeriod, slowDMaType, shift);
Are you aware that here you calculate the stoch on an arbitrary period bar (most likely 10 secs)? See onBar description here:
https://www.dukascopy.com/wiki/#Strategy_API
if ((instrument == Instrument.GBPUSD) && (period == Period.FIFTEEN_MINS)) {
Consider filtering bars the opposite way, see:
https://www.dukascopy.com/wiki/#Filter_Ticks_Bars
This wise you will reduce the code nesting.
Previous_Stoch = indicators.stoch(instrument, period, side, fastKPeriod, slowKPeriod, slowKMaType, slowDPeriod, slowDMaType, shift);
Current_Stoch = indicators.stoch(instrument, Period.FIFTEEN_MINS, side, fastKPeriod, slowKPeriod, slowKMaType, slowDPeriod, slowDMaType, shift);
If you wish to use the same period here, then consider using the candle interval methods for indicator calculation, see:
https://www.dukascopy.com/wiki/#Indicator_Calculation/Calculate_indicator_by_candle_interval
stoploss = Double.parseDouble(myDF.format(bidBar.getOpen() + 10 * myPipValue));
Calculate the SL/TP price distance as it is done here:
https://www.dukascopy.com/wiki/#SMA_Simple
if ((myOrder.getState().equals(IOrder.State.CANCELED)) || (myOrder.getState().equals(IOrder.State.CLOSED)) || (myOrder == null)) {
if myOrder will be null, the condition will fail with the NPE, hence the last OR condition is redundant in either way.
Consider reducing nesting to make the code more manageable, e.g. the block which starts with the upper mentioned line could be simplified to:
if (myOrder == null || myOrder.getState() == IOrder.State.CANCELED || myOrder.getState() == IOrder.State.CLOSED) {
    canTrade = true;
    return;
}
if ((myOrder.getOrderCommand() == IEngine.OrderCommand.SELL && Previous_Stoch[0] < Current_Stoch[0])
        || myOrder.getOrderCommand() == IEngine.OrderCommand.BUY && Previous_Stoch[0] > Current_Stoch[0]) {
    myOrder.close();
    console.getOut().println("Order Closed");
    canTrade = true;
}


 

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