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.

Bollinger bands strategy
 Post subject: Bollinger bands strategy Post rating: 0   Post Posted: Tue 01 Nov, 2011, 16:52 
User avatar

User rating: 0
Joined: Sun 10 Jul, 2011, 15:44
Posts: 33
Location: FranceFrance
Hello,
i tried to code a strategy based on bollinger bands but i couldn't achieve it.
Is there something out there who is sommething like this that i could modify, the strategy is easy :
- buy if price was under lower bolllinger band and is now over it
- sell if price was over upper bollinger band and is now under it.


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Wed 02 Nov, 2011, 08:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
From approach standpoint the algorithm is similar to the following strategy in wiki:
https://www.dukascopy.com/wiki/index.php ... SMA_Simple
See here more, on how to work with Bollinger bands:
https://www.dukascopy.com/wiki/index.php ... nger_Bands
Also this example works with Bollinger bands (value retrieval and logging):
https://www.dukascopy.com/wiki/index.php ... ing_values

Keep us posted if you need any further assistance on this.


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Wed 02 Nov, 2011, 23:15 
User avatar

User rating: 0
Joined: Sun 10 Jul, 2011, 15:44
Posts: 33
Location: FranceFrance
I've almost done my strategy but i've one other question, where could i put a conditional close of my strategy ?
After this ?
      double stopLossPrice, takeProfitPrice;

      // Calculating stop loss and take profit prices
      if (orderCmd == OrderCommand.BUY) {
         stopLossPrice = history.getLastTick(this.instrument).getBid() - getPipPrice(this.stopLossPips);
         takeProfitPrice = history.getLastTick(this.instrument).getBid() + getPipPrice(this.takeProfitPips);
      } else {
         stopLossPrice = history.getLastTick(this.instrument).getAsk() + getPipPrice(this.stopLossPips);
         takeProfitPrice = history.getLastTick(this.instrument).getAsk() - getPipPrice(this.takeProfitPips);
      }


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Thu 03 Nov, 2011, 09:24 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
In SMA Simple example strategy already two close conditions get applied - stop loss and take profit prices (in IEngine.submitOrder call). What kind of additional close condition do you want to apply? Is it time or price condition?


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Thu 03 Nov, 2011, 10:41 
User avatar

User rating: 0
Joined: Sun 10 Jul, 2011, 15:44
Posts: 33
Location: FranceFrance
I want to add a close condition when the price crosses the sma(middle bollinger line)


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Thu 03 Nov, 2011, 11:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Then you should do it in onTick method, since you want to close the position as soon as the price condition gets fulfilled. If you need any further assistance on this, please provide the relevant code fragments.


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Thu 03 Nov, 2011, 15:52 
User avatar

User rating: 0
Joined: Sun 10 Jul, 2011, 15:44
Posts: 33
Location: FranceFrance
What i've written don't does what it should do, take a look :


Attachments:
BollMaster.java [4 KiB]
Downloaded 369 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: Bollinger bands strategy Post rating: 0   Post Posted: Fri 04 Nov, 2011, 17:28 
User avatar

User rating: 0
Joined: Sun 10 Jul, 2011, 15:44
Posts: 33
Location: FranceFrance
5 downloads and no answer... :(
No one has an idea ?


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Mon 07 Nov, 2011, 09:11 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
1) instead of:
return engine.submitOrder(getLabel(instrument), this.instrument, orderCmd, this.amount, 0, 20, stopLossPrice, takeProfitPrice);
try
IOrder order = engine.submitOrder(getLabel(instrument), this.instrument, orderCmd, this.amount, 0, 20, stopLossPrice, takeProfitPrice);
return order;
And then you won't need to use additional variables like buyopen and sellopen, but then it will suffice to check:
order.getOrderCommand() == IEngine.OrderCommand.BUY

2) Why do you use such huge TP and SL? If you don't want to use those values, then just set them to 0 or rather use an IEngine.submitOrder method without them, see:
https://www.dukascopy.com/client/javadoc//com/dukascopy/api/IEngine.html#submitOrder(java.lang.String,%20com.dukascopy.api.Instrument,%20com.dukascopy.api.IEngine.OrderCommand,%20double)

3) Use tick and bar filtering (filter also instruments):
https://www.dukascopy.com/wiki/index.php ... Ticks/Bars

4) Please consider logging your values to see what execution paths get taken and why:
https://www.dukascopy.com/wiki/index.php ... ing_values

5) If you still encounter some problems, please describe more precisely:
a) The intended algorithm.
b) What you expect the strategy to do.
c) And what it does instead.


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Wed 09 Nov, 2011, 22:22 
User avatar

User rating: 0
Joined: Sun 10 Jul, 2011, 15:44
Posts: 33
Location: FranceFrance
I don't think that it's a huge SL and TP, to better explain what i want to do i'll show you a screenshot :
Attachment:
Chart_EUR_USD_4-Hours_snapshot.png [39.29 KiB]
Downloaded 481 times


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Thu 10 Nov, 2011, 09:26 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
condor666 wrote:
I don't think that it's a huge SL and TP, to better explain what i want to do i'll show you a screenshot
The remark about the TP and SL was made just to provide you with extra information on order submission, in case you needed it.


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Fri 11 Nov, 2011, 16:47 
User avatar

User rating: 0
Joined: Sun 10 Jul, 2011, 15:44
Posts: 33
Location: FranceFrance
I've entirely reprogrammed the strategy and now it works better, i have just one little problem : it doesn't allocates dynamically the trade volume.
For example, if i've 100.000$ in my account i want to open exactly a 1 million transaction.


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Fri 11 Nov, 2011, 16:56 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/index.php?title=Account_Info


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Fri 11 Nov, 2011, 18:20 
User avatar

User rating: 0
Joined: Sun 10 Jul, 2011, 15:44
Posts: 33
Location: FranceFrance
I tried this but it opens too big positions :
public void onAccount(IAccount account) throws JFException {
      double compte = account.getCreditLine();
      amount = compte/1000000;
   }


 
 Post subject: Re: Bollinger bands strategy Post rating: 0   Post Posted: Mon 14 Nov, 2011, 08:35 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
IAccount.creditLine() returned amount is in units (e.g. USD, if it is your account currency), but for orders amount is in millions, so you snippet returns an order amount which would equal your all available credit.


 

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