Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 662 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
First script and need some correction #438428
03/14/14 03:03
03/14/14 03:03
Joined: Mar 2014
Posts: 9
H
hermit2795 Offline OP
Newbie
hermit2795  Offline OP
Newbie
H

Joined: Mar 2014
Posts: 9
Hi Guys

new to programming, and would like someone to point out where I went wrong "Error line 12, wrong number of parameters"

Code:
// -----------------------------------------------------------------
// bias line used for deciding whether to go long or short
function rule01Bias()
{
	rule01Bias = series(SMA(series(priceClose()),100)) ;
}
// -----------------------------------------------------------------
// rule01_Buy bar pattern definition for going Long
function rule01_Buy()
{
	rule01_Buy = priceClose(1) > rule01Bias(1) && priceHigh(1) < priceHigh(2) && priceLow(1) < priceLow(2) ;
}
// -----------------------------------------------------------------
// rule01_Sell bar pattern definition for going Short
function rule01_Sell()
{
	rule01_Sell = priceClose(1) < rule01Bias(1) &&	(priceHigh(1) > priceHigh(2)	&& priceLow(1) > priceLow(2) ;
}
// -----------------------------------------------------------------
// setting a stop loss by ATR
function rule01_loss_Exit()
{
	rule01_loss_Exit = 1*ATR(100) ;
}
// -----------------------------------------------------------------
// setting a profit target in PIPS
function rule01_profit_Exit()
{
	rule01_profit_Exit = 50*PIPS ;
}
// -----------------------------------------------------------------
// setting a trailing stop by ATR
function rule01_profit_Trail()
{
	rule01_profit_Trail = 4*ATR(100) ;
}
// -----------------------------------------------------------------
// used for setting target entry price for Long
function market_Long()
{
	market_Long = (priceHigh(1) + 3*PIPS) ;
}
// -----------------------------------------------------------------
// used for setting target entry price for Short
function market_Short()
{
	market_Short = (priceLow(1) - 3*PIPS) ;
}
// -----------------------------------------------------------------
// logic execution
function run()
{
	Stop = rule01_loss_Exit ;
	TakeProfit = rule01_profit_Exit ;
	Trail = rule01_profit_Trail ;
	
	vars Price = series(priceClose()) ;
	
	if (rule01_Buy)
		enterLong(market_Long) ;
	else if (rule01_Sell)
		enterShort(market_Short) ;
}
// -----------------------------------------------------------------



thank, Peter

Re: First script and need some correction [Re: hermit2795] #438433
03/14/14 09:02
03/14/14 09:02
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
In my system the twelveth line is a mere "}"
So, i don't know...

Re: First script and need some correction [Re: Aku_Aku] #438436
03/14/14 10:56
03/14/14 10:56
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
You should tell us what line 12 is, but I see many bizarre lines in your code, like this:

rule01Bias = series(SMA(series(priceClose()),100)) ;

rule01Bias is a function, not a series. How to use functions is described in Workshop 2 in the tutorial.

Re: First script and need some correction [Re: jcl] #438443
03/14/14 15:25
03/14/14 15:25
Joined: May 2013
Posts: 245
S
swingtraderkk Offline
Member
swingtraderkk  Offline
Member
S

Joined: May 2013
Posts: 245
Peter,

I think you are over complicating, there is nothing I see that needs a function.

Code:
function run()
{
	Stop = 1*ATR(100);
	TakeProfit = 50*PIP;
	Trail = 4*ATR(100);
	
	vars Price = series(priceClose());
	vars rule01Bias = series(SMA(Price,100));
	
	if (priceClose(1) > rule01Bias[1]
	 and priceHigh(1) < priceHigh(2)
	  and priceLow(1) < priceLow(2))
		enterLong(1,(priceHigh(1) + 3*PIP));
	if (priceClose(1) < rule01Bias[1]
	 and	priceHigh(1) > priceHigh(2)
	 	and priceLow(1) > priceLow(2))
	 	enterShort(1,(priceLow(1) - 3*PIP));
}



Note that index 0 is the last bar, in this script you are using the 2nd & 3rd most recent bars. Is that intentional?

Also the trail distance at 4*ATR seems a little high considering the stop is only 1*ATR and the TP is 50 pips.

Last edited by swingtraderkk; 03/14/14 15:27.
Re: First script and need some correction [Re: swingtraderkk] #438466
03/15/14 02:08
03/15/14 02:08
Joined: Mar 2014
Posts: 9
H
hermit2795 Offline OP
Newbie
hermit2795  Offline OP
Newbie
H

Joined: Mar 2014
Posts: 9
thanks for your replies. over complicated, yep! but I want to learn, and making mistakes is a good way. especially when someone has the patience to point it out (swingtraderkk).

I unintentionally used (1) instead of (0) for last closed bar. some of my best trading methodology has been discovered by accident.

Code:
function run()
{
	Stop = (priceClose(1) - 1.5*ATR(100));
	TakeProfit = 300*PIP;
	Trail = 1.0*ATR(100);
	
	vars Price = series(priceClose());
	vars BiasLarge = series(SMA(Price,70));
	
	if (priceClose(1) > BiasLarge[1]
	 and priceHigh(1) < priceHigh(2)
	  and priceLow(1) < priceLow(2))
		enterLong(1,(priceHigh(1) + 3*PIP));
	if (priceClose(1) < BiasLarge[1]
	 and	priceHigh(1) > priceHigh(2)
	 	and priceLow(1) > priceLow(2))
	 	enterShort(1,(priceLow(1) - 3*PIP));
}



Peter

Re: First script and need some correction [Re: hermit2795] #439766
04/08/14 21:49
04/08/14 21:49
Joined: Mar 2014
Posts: 9
H
hermit2795 Offline OP
Newbie
hermit2795  Offline OP
Newbie
H

Joined: Mar 2014
Posts: 9
Hi Guys

what I would like to do is use a 3 day pivot point as a BIAS line (close above for long & below for short) with 4 hour bars. I know the problem I have is simple, but I can't see it. I hope someone can point out the error of my ways.

Thanks, Peter

Code:
// 4 hour (240 minute) bars used in this strategy 
BarPeriod = 240;
TimeFrame = 1;

// define bar open,high,low,close
vars H = series(priceHigh()),
	L = series(priceLow()),
	O = series(priceOpen()),
	C = series(priceClose());

// = MTF Pivot Point
// timeframe 6 * barperiod 240 = 1 day bar
TimeFrame = 6
// define HH & LL for MTF Pivot Point
vars HH = series(priceHigh());
vars LL = series(priceLow());
// define BIAS calculation
vars BIAS = series((HH()+LL()+C())/3);
// back to 4 hour time frames
TimeFrame = 1;	

// describe MB calculation
// = midpoint of bar()
vars MB = series((H()-L())/2);
// if C() > MB[] // then close above midpoint
// if C() < MB[] // then close below midpoint


Re: First script and need some correction [Re: hermit2795] #439771
04/09/14 09:13
04/09/14 09:13
Joined: May 2013
Posts: 245
S
swingtraderkk Offline
Member
swingtraderkk  Offline
Member
S

Joined: May 2013
Posts: 245
Hi Peter,

A couple of things I've spotted:

1) If you are using different timeframes, I think you need different series for the price hi,lo,cl in each or simply call the relevant price().

2) HH & LL are built in functions that take a period parameter. you are declaring them as a series of vars and assigning them the value of price high or low for the current bar.

3) midpoint is H+L/2.

Code:
function run()
{
// 4 hour (240 minute) bars used in this strategy 
StartDate = 2014;
BarPeriod = 240;

// = MTF Pivot Point
// timeframe 6 * barperiod 240 = 1 day bar
TimeFrame = 6;

// define BIAS calculation
vars BIAS = series(((HH(3)+LL(3)+priceClose(0))/3));

// back to 4 hour time frames
TimeFrame = 1;	

// describe MB calculation
// = midpoint of bar()
vars MB = series((priceHigh(0)+priceLow(0))/2);

// if C() > MB[] // then close above midpoint
// if C() < MB[] // then close below midpoint

plot("MB",MB[0],0,GREEN);
plot("Pivot",BIAS[0],0,YELLOW);
}


Re: First script and need some correction [Re: swingtraderkk] #439860
04/11/14 00:29
04/11/14 00:29
Joined: Mar 2014
Posts: 9
H
hermit2795 Offline OP
Newbie
hermit2795  Offline OP
Newbie
H

Joined: Mar 2014
Posts: 9
Hi.

I have attached an image of what I was trying to do with the pivot taken from the last 3 days, and the bars 240mins.

The midpoint should be a series as it compares the close to the midpoint for last bar closed and the close to the midpoint of the 2nd last bar closed.

Is it...
xxx(0) for current open bar
xxx(1) for last closed bar
xxx(2) for 2nd last closed bar?
as all the referenced bars are closed bars

Peter

Attached Files
eurusdh4.png (9 downloads)
Re: First script and need some correction [Re: hermit2795] #439869
04/11/14 08:21
04/11/14 08:21
Joined: May 2013
Posts: 245
S
swingtraderkk Offline
Member
swingtraderkk  Offline
Member
S

Joined: May 2013
Posts: 245
Hi Peter,

vars MB = series((priceHigh(0)+priceLow(0))/2);

This calculates the series of the mid-points of the bars.

Zorro only runs at the start of a new bar, so in your example the midpoint of last bar(the one immediately closed) is MB[0]. There is no data yet in the current open bar.

MB[1] is then 2nd last closed bar etc.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1