Is it possible to calculate Bollinger bands on the difference of two Symbols?

Created at 10 Feb 2020, 16:07
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DA

david.sanchez

Joined 07.02.2020

Is it possible to calculate Bollinger bands on the difference of two Symbols?
10 Feb 2020, 16:07


Hi,

is it possible to implement something like this?

is it possible to implement something like this?

Trade Idea:

I want to trade spreads of two legs like EUR/USD – EUR/CHF.

 

The Goal is to create a market neutral state in which there is «no» market Risk.

 

In the attachment you find 3 ideal spreads. As you can see the Chart goes only sideways, thus there is no significant Risk neither on the down- nor on the upside.

 

The next step is to calculate the mean with Length = Input value or 10 bars. Then calculate the standard deviation with Input value or 2 as coefficient and Length as Input or 10 Bars.

 

Then adding and substracting the standard deviation to the mean. Thus visually there is an upper and lower Bound to the spread which is self adjusting to volatility.

 

If the current value of the spread is equal or greater than the upper Bound, then sell the spread ( this means sell short EUR/USD and buy EUR/CHF). If there is an open long Position, close the Position (sell EUR/USD and buy to cover EUR/CHF)

 

If the current value of the spread is equal or lower than the lower Bound, then buy the spread (buy EUR/USD and sell short EUR/CHF). If there is an open short Position, close the Position (buy to cover EUR/USD and sell EUR/CHF).

 

Now I there are two ways of doing this:

 

If you are able to take data and send orders to particular Symbols from the script then you can write everything as a single script.

 

If this is not possible with ctrader, then you Need to write two scripts- one for each leg.

In this case, it would be as followed:

Script 1 runs on EUR/USD

sell Spread =  sell short EUR/USD or if there is an open Long pos. Sell

buy Spread = buy EUR/USD or if there is an open short pos. Buy to cover

 

Script 2 runs on EUR/CHF

Sell Spread = buy EUR/CHF or if there is an open short pos. Buy to cover

Buy Spread = sell short EUR/CHF or if there is an open Long pos. Sell

 

Opening a new Position and Closing old ones, would be Happening  simultaneously  since the Signals are the same.

 

The second leg is here for hedging so it does the contrary, this is intended, otherwise there would be now market neutrality

 

By running both scripts on the same time market neutrality should be garanteed.

 

The Goal is to open and close positions as fast as possible so the Signal MUST NOT wait until the close of a bar.

 

As soon as the spread value is lucrative Market orders should be sent immediately.

 

On Multicharts one can use currentbar if there is Nothing comparable on ctrader then tick data is necessary.

 

This makes everything slighty complicated because now two spreads are necessary, a bid spread and ask spread both consisting on bid and ask Prices of the legs.

 

The Bid spread:

Market orders are filled at current bid/ask Prices, so:

Bid spread = EUR/USD.Bid – EUR/CHF.Ask

 

Since we sell the first leg when we want to sell the spread, we Need the bid Price of the first leg, and ask Price of the second leg for hedging.

 

And vice versa

 

The ask spread:

Ask spread = EUR/USD.ask – EUR/CHF.bid

 

This is the reason why there are three spreads on the Picture.

 

From here it gets interesting: We could use the ask spread just for Long entries and short Exits and the bid Spread for short entries and Long Exits.

 

LE = Long entry; LX = Long Exit; SE = short entry; SX = short exit

 

That would mean 4 scripts in total because Bid spread( script 1(SE and LX) on EUR/USD, script 2(LE and SX)  on EUR/CHF)) and ask spread( script3( LE and SX) on EUR/USD and script 4(SE and LX) on EUR/CHF))

 

Because we buy for ask and sell for bid and since buying the spread is buying the first leg and selling the second and selling the spread is selling the first leg and buying the second we get that structure.

 

Now I think it is possible to make a spread, out of the bid and ask spread and returning to only two scripts but I am not certain.

 

This would mean bid – ask (bid = Price to sell and ask = Price to buy)

 

Bid/ask spread >1 bid is currently higher than ask so selling and then immediately buying would return a Profit so logic stays the same with upper Bound.

 

Bid/ask spread<1 ask is currently higher than bid so buying and then immediately selling would return a Profit so logic stays the same here as well.

 

Note that since execution Speed is important, the Code should be as efficient as possible. So the last variant is the best option.

 

If it is possible to write and execute everything from one script I’d prefer that.

 

I hope I could explain it to you properly.

Essentially I only need to know how to calculate bollinger bands on a difference of two contracts...

 

I would be very grateful, if you could help me

 

 


@david.sanchez