logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Homer  
#1 Posted : Thursday, October 20, 2011 8:14:26 PM(UTC)
Homer

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 10/20/2011(UTC)
Posts: 3

Hello,
I have a simple system I want to test in the systems tester but having trouble with the code.
It is based on Bollinger Bands with the paramaters (Price=CLOSE Period=62 Deviations=0.2 and Displacement =0). It can be a system for both long and short however, I just wan to test for long trades.

Buy: The price should begin entirely under the BBandBottom. That is, there needs to be a candle where no part of the candle is touching the BBandBottom and it is bellow that price. Then there needs to be the opposite candle above the bands and where no part is touching BBandTop. [Any number of candles can exist between these two candles.] The enrty is the following day at open as long as the open is still above the BBandTop.

There is a clause to sell for profit and also a stop loss, both based on the width of the BBands. In other words the BBandTop - BBandBottom.

The stop loss is {entry price - (BBandTop-BBandBottom)} and the Sell is {entry price + ((BBandTop-BBandBottom)*2)}

I came up with the below code for a buy order but not sure how to put in a clause "if open is above BBTop" It's confusing because I have already put in info about 'open' and it relates to the previous candle, so how do I talk about the future open?
(CLOSE >(BBandTop(CLOSE, 62, SIMPLE, .2)))
AND (OPEN >(BBandTop(CLOSE, 62, SIMPLE, .2)))
AND (LOW >(BBandTop(CLOSE, 62, SIMPLE, .2)))
AND (HIGH >(BBandTop(CLOSE, 62, SIMPLE, .2)))

I am also not sure how to write the code for the 'entry price' so I cannot write either of the sell conditions.

Thanks in advance.
James.
MS Support  
#2 Posted : Wednesday, November 2, 2011 1:48:05 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,960

Thanks: 92 times
Was thanked: 155 time(s) in 150 post(s)
James,

under normal condition, you do not need to check the open, high, low and close if you want all four to be above some value. The Low should always be equal to or less than the other three so you only need to check if the low is greater than the top band.

However, this is just a small part of the system you described. You still need to check for the prior bar being below the bands. Once you are satisfied the signal is reached, then, since this is for system testing only, you can peak one bar into the future with the Ref function. Just set the periods value to +1. alternately, you can check to see if the current bar's open is above the bands and the signal was given on the previous bar.

The exits you are wanting will have to be coded into the formula for the Sell order. It will likely require a logical switch to impliment. If youi need help with his, I would recommend emailing the requiest to formulas@equis.com

jjstein  
#3 Posted : Wednesday, November 9, 2011 10:52:40 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Your request was interesting, but a bit beyond my skill level, so I asked Roy Larsen (MSTT) to have a look -- here is what he came up with:

{BB System}
D:=Input("Deviations",0.1,10,.2);
N:=Input("Periods",2,500,62);
BT:=BBandTop(C,N,S,D);
BB:=BBandBot(C,N,S,D);
A:=L>BT; {LOW > BBtop}
B:=H<BB; {HIGH < BBbot}
BW:=BT-BB; {BBands width}
I:=Cum(IsDefined(A+B))<3; {2-bar Init signal}
N:=BarsSince(I+A)<BarsSince(I+B) {BB position latch}
AND Cum(B)>0; {inhibit latch B TRUE once}
Buy:=Ref(N*Alert(N=0,2),-1) {truncate buy signal and delay entry}
AND O>Ref(BT,-1); {check entry price is valid}
BP:=ValueWhen(1,I+Buy,O); {buy price}
{BP set by 2nd I bar to stop N/A flow-on effect on Sell, Stop and Tr variables}
Sell:=C>BP+BW*2; {profit exit}
Stop:=C<BP-BW; {stop loss exit}
Tr:=If(PREV<=0,Buy*O,If(Sell+Stop,-PREV,PREV)); {trade latch variable}
Exit:=Tr<0; {sell on CLOSE signal}
Abs(Tr); {entry price / active trade}


If you use this with the System Tester, I suggest you use the following for signals:

BUY: FmlVar("BB System","Buy");
SELL: FmlVar("BB System","Exit");

UserPostedImage

Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.