BullCharts Forum Homepage
Forum Home Forum Home > BullCharts > BullScript
  New Posts New Posts RSS Feed: Variable in argument list
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Variable in argument list

 Post Reply Post Reply
Author
Message Reverse Sort Order / View First Unread Post
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post Topic: Variable in argument list
    Posted: 23 Feb 2008 at 1:48am

I might as well include the Keltner channel indicator here with the same default settings as above, so you can see how it uses the bands in its logic.  Though notice the lines do not retreat in the above indicator.

{ Keltner Channel SuperTrend }

nb := input("Nb Periods",5,1);

A := input("ATR Multiplier",2,1);

[target=Price; category=Bands; color=dodger blue]

[linestyle=dotted]

Vatr:=ma((HHV(H,nb)-LLV(L,nb))*0.38,nb,E);

{Upper Keltner Band}

ma((H+L)*0.5,Nb,E) + A * Vatr;

{Lower Keltner Band}

ma((H+L)*0.5,Nb,E) - A * Vatr;

  

Back to Top
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post Posted: 23 Feb 2008 at 1:33am

Here's one you might find more effective as a Stop And Reverse indicator.  I call it Stop Trend as it is useful for both Stoploss setting and Trend indication.  Though i programmed it in Bullscript the original idea for using Keltner channels for this goes to Oliver Siban who created the SuperTrend indicator.  

{ TrendStop }

[Target=Price; LineStyle=Solid; Author=Michael, Max]

TDate:=InputDate("Start Date", date(2004,12,01));

HoldingDays:=BarsSince(OnOrSkipped(TDate));

A:=Input("ATR Multiplier",2,1);

Nb:=Input("Nb Periods",5,3);

Vatr:=ma((HHV(H,nb)-LLV(L,Nb))*0.38,Nb,E);

Short:=ma((H+L)*0.5,Nb,E) + A * Vatr;

Long:=ma((H+L)*0.5,Nb,E) - A * Vatr;

LStop := If(Long>PREV and HoldingDays,Long,If(Long<=PREV and HoldingDays,HHV(Long,10),Long));

SStop := If(Short<PREV and HoldingDays,Short,If(Short>=PREV and HoldingDays,LLV(Short,10),Short));

up:=if(Close<LStop and hist(Close,1) > hist(LStop,1),1,0);

down:=if(Close>SStop and hist(Close,1) < hist(SStop,1),1,0);

Dtrend:=if(up,1,if(down,0,prev));

Utrend:=if(down,1,if(up,0,prev));

V4:=if(Barssince(Dtrend)<=10,8,15);

LongStop :=if(Dtrend and HoldingDays,Long,If(Long>PREV and HoldingDays,Long,If(Long<=PREV and HoldingDays,if(Barssince(Dtrend)<=10,HHV(Long,8),HHV(Long,15)),Long)));

Shortstop :=if(Utrend and HoldingDays,Short,If(Short<PREV and HoldingDays,Short,If(Short>=PREV and HoldingDays,if(Barssince(Utrend)<=10,LLV(Short,8),LLV(Short,15)),Short)));

[drawundefined=gap]

init:=if(Dtrend=0 and Utrend=0 and HoldingDays,1,0);

[Color=lime green]

if(Utrend and HoldingDays and hist(Dtrend,1)=1,LongStop,if(Dtrend and HoldingDays,ShortStop,undefined));

[Color=red]

if(Dtrend and HoldingDays,ShortStop,if(hist(Dtrend,1)=0 and HoldingDays,LongStop,undefined));

[Color=lime green]

if(Utrend and HoldingDays or init,LongStop,undefined);

 

Back to Top
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post Posted: 23 Feb 2008 at 12:55am

Okay here's my attempt at Parabolic SAR in bullscript.  Looks very close to standard SAR settings on Paladin Energy.   What it really needs is a parabolic weighted average to be exactly the same, which i could not find so i simply used an exponantial average to get the  parabolic effect based on HHV and LLV as SAR uses.

[description="An attempt to create Parabolic SAR using bullscript"]

Lsig:=if(HHV(H,6)>hist(HHV(H,6),1),1,0);

Ssig:=if(LLV(L,6)<hist(LLV(L,6),1),1,0);

Long:=If(Lsig and prev<>1,1,If(Ssig,0,prev));

Short:=If(Ssig and prev<>1,1,If(Lsig,0,prev));

[linestyle=points; color=Dark Violet; Target=Price]

If(Long,if(hist(Long,1) and ma(LLV(L,6),3,E)<prev, prev, ma(LLV(L,6),3,E)),undefined);

If(Short,if(hist(Short,1) and ma(HHV(H,6),3,E)>prev, prev, ma(HHV(H,6),3,E)),undefined);

  

Back to Top
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jan 2008 at 4:41am

Hi Gordon,

I only just found your post by searching for Parabolic SAR and was hoping to find the source in bullscript myself.  Like why reinvent the wheel if you can find it already?  Anyway it looks like I will have to do that myself, wont be too difficult since i've had a year or so of bullscripting.  Unless someone wants to beat me to it in the next week or so?   I have the code for it in Wealthlab and it looks doable.  Just have to add those extra variables because bullscript cannot set a variable more than once.   Is this the price we pay for an Object Oriented  Language or Bullscript?   Will get round to it in the next few days.

Cheers!          ;

Back to Top
Gordon View Drop Down
Newbie
Newbie
Avatar

Joined: 21 Apr 2006
Location: Australia
Posts: 6
Post Options Post Options   Quote Gordon Quote  Post ReplyReply Direct Link To This Post Posted: 26 Apr 2006 at 11:52pm
The problem with this is that the input command is something that you have to enter. I would like something where I calculate numbars and then be able to use that calculated result in functions like hist.

I don't know why the developers of BullScript have only allowed constant values for many of their function calls (except possibly to keep it as close to metastocks script language as possible) but it's very limited and frustratingly difficult to get around.

I might add that Bullscript is a purely recursive language and it's lack of basic iterative constructs like loops is a real pain. I've noticed, for instance, that rather than give you the script for Parabolic SAR (which they do for most other indicators) the creators of Bullscript have made it a hard coded function. I'm guessing because it's almost impossible to create with BullScript. I'd be very interested to see if anyone can create the Parabolic SAR indicator while only using basic Bullscript.
Back to Top
REKAU View Drop Down
Newbie
Newbie


Joined: 06 Apr 2006
Posts: 4
Post Options Post Options   Quote REKAU Quote  Post ReplyReply Direct Link To This Post Posted: 24 Apr 2006 at 11:06pm

I seemed to get this working see below:

[Color=lime green; Target=Price]

numbars := Input("numbars ");

[linestyle=dash]

[width=2]

result := hist(C, numbars);

result;

Back to Top
Gordon View Drop Down
Newbie
Newbie
Avatar

Joined: 21 Apr 2006
Location: Australia
Posts: 6
Post Options Post Options   Quote Gordon Quote  Post ReplyReply Direct Link To This Post Posted: 21 Apr 2006 at 11:21pm
I would like to be able to do something like the following

result := hist(C, numbars);

where numbars is a variable.

However the hist command requires a constant value for number of bars (causes error 110). A lot of other commands require a constant numeric value as well. Can someone tell me how to do this.

Thanks
Gordon
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz