1 registered members (Ayumi),
662
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
First script and need some correction
#438428
03/14/14 03:03
03/14/14 03:03
|
Joined: Mar 2014
Posts: 9
hermit2795
OP
Newbie
|
OP
Newbie
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"
// -----------------------------------------------------------------
// 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: jcl]
#438443
03/14/14 15:25
03/14/14 15:25
|
Joined: May 2013
Posts: 245
swingtraderkk
Member
|
Member
Joined: May 2013
Posts: 245
|
Peter, I think you are over complicating, there is nothing I see that needs a function.
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
hermit2795
OP
Newbie
|
OP
Newbie
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.
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
hermit2795
OP
Newbie
|
OP
Newbie
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
// 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
swingtraderkk
Member
|
Member
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.
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);
}
|
|
|
|