help with forex strategy  [SOLVED]

Questions about MultiCharts and user contributed studies.
liang323
Posts: 30
Joined: 12 Mar 2006
Has thanked: 1 time

help with forex strategy

Postby liang323 » 23 Oct 2018

Hi I was hoping if someone could help me with a very simple strategy based on Bollinger Band reversal, I'm trading EUR.USD on 1 hour chart (Interactive Brokers). Basically Buy when price is above the upperband and short when price is below the lowerband.

The strategy only had 1 entry order but no exit orders were issued. Much appreciated if someone is able to help me to correct the code:

and here is the quote manager setting:
Price Scale: 1/100000
Min. Movement: 5
Big Point Value: 1

Many thanks!

Code: Select all

Inputs:
BollingerPrice( Close ),
CurrentPrice( Close ),
Length( 20 ),
NumDevsUp( 2 ),
NumDevsDn( -2 ),
TradeAmt(10000),
Threshold (0.0005);

variables:
MidLine ( 0 ),
var0 ( 0 ),
LowerBand ( 0 ),
UpperBand ( 0 ),
UpperPriceThresh ( 0 ),
LowerPriceThresh ( 0 );

{Calculating Bollinger Band}
MidLine = AverageFC( BollingerPrice, Length ) ;
var0 = StandardDev( BollingerPrice, Length, 1) ;
UpperBand = MidLine + NumDevsUp * var0 ;
LowerBand = MidLine + NumDevsDn * var0 ;

{Entry Conditions}
UpperPriceThresh = UpperBand + Threshold; {UpperBand + 5 pips}
LowerPriceThresh = LowerBand - Threshold; {LowerBand - 5 pips}

Condition1 = CurrentPrice < LowerPriceThresh;
Condition2 = CurrentPrice > UpperPriceThresh;

{Long Entry}
if marketposition = 0 and condition1 then
buy TradeAmt contract next bar at market;

{Exit Long}
if marketposition > 0 and CurrentPrice = MidLine then
sell all contract next bar at market;

{Short Entry}
if marketposition = 0 and condition2 then
sellshort TradeAmt contract next bar at market;

{Exit Short}
if marketposition < 0 and CurrentPrice = MidLine then
buytocover all contract next bar at market;

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: help with forex strategy

Postby TJ » 23 Oct 2018

How often do you see the current price ever equals the MidLine ?

liang323
Posts: 30
Joined: 12 Mar 2006
Has thanked: 1 time

Re: help with forex strategy

Postby liang323 » 23 Oct 2018

hi TJ, I can see price crosses the MidLine at least once or twice a day.

Thanks!

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: help with forex strategy  [SOLVED]

Postby TJ » 23 Oct 2018

hi TJ, I can see price crosses the MidLine at least once or twice a day.

Thanks!
So? What can it do for your strategy?
"Cross" is NOT the same as "EQUAL"

{Exit Long}
if marketposition > 0 and CurrentPrice ==== MidLine then
sell all contract next bar at market;

liang323
Posts: 30
Joined: 12 Mar 2006
Has thanked: 1 time

Re: help with forex strategy

Postby liang323 » 23 Oct 2018

Hi TJ, thanks so much for pointing the mistake, I've replace the "=" with "cross above" and "cross under", the strategy worked straight away! I didn't think it would have such big impact on the outcome. Thank you again for helping and wish you a nice day!


Return to “MultiCharts”