|
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 |
condor666
|
Post subject: Bollinger bands strategy |
Post rating: 0
|
Posted: Tue 01 Nov, 2011, 16:52
|
|
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.
|
|
|
|
 |
API Support
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Wed 02 Nov, 2011, 08:17
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
condor666
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Wed 02 Nov, 2011, 23:15
|
|
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); }
|
|
|
|
 |
API Support
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Thu 03 Nov, 2011, 09:24
|
|
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?
|
|
|
|
 |
condor666
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Thu 03 Nov, 2011, 10:41
|
|
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)
|
|
|
|
 |
API Support
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Thu 03 Nov, 2011, 11:54
|
|
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.
|
|
|
|
 |
condor666
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Thu 03 Nov, 2011, 15:52
|
|
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.
|
|
|
|
|
 |
condor666
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Fri 04 Nov, 2011, 17:28
|
|
User rating: 0
Joined: Sun 10 Jul, 2011, 15:44 Posts: 33 Location: FranceFrance
|
5 downloads and no answer... No one has an idea ?
|
|
|
|
 |
API Support
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Mon 07 Nov, 2011, 09:11
|
|
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/Bars4) Please consider logging your values to see what execution paths get taken and why: https://www.dukascopy.com/wiki/index.php ... ing_values5) 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.
|
|
|
|
 |
condor666
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Wed 09 Nov, 2011, 22:22
|
|
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:
|
|
|
|
 |
API Support
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Thu 10 Nov, 2011, 09:26
|
|
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.
|
|
|
|
 |
condor666
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Fri 11 Nov, 2011, 16:47
|
|
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.
|
|
|
|
 |
API Support
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Fri 11 Nov, 2011, 16:56
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
condor666
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Fri 11 Nov, 2011, 18:20
|
|
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; }
|
|
|
|
 |
API Support
|
Post subject: Re: Bollinger bands strategy |
Post rating: 0
|
Posted: Mon 14 Nov, 2011, 08:35
|
|
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.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|