[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LRW strategy works........but its doing bizare stuff



PureBytes Links

Trading Reference Links

Hi all

Thought id post a strategy , feel free to use it. It would be nice too if
you repost it back to the list if you can improve it.
One thought though , something that has been bugging me about this code is
that i keep getting errros like [strategy tried to reference more than
allowed bars , increase max barsback setting]  so i did that right up to 70
on one chart before it worked ....strange thing though the strategy code
only referenced at the time 10 bars back....bizare.... anyone got any ideas
why?? i couldnt work out why.
Another chart wouldnt work untill i set the max barsback setting to 100
....bizaro code?
cheers
Cameron














{LrgRangeRunaway strategy
looks for a large range day that breaks new highs/lows for avgtrue range so
many days ago and opens at the bottom and closes at the top or visa/versa
Writen by Cameron Jones Copyright@xxxx
}

Inputs:
	buyorsell(0),{buys only = 1 , sell only = -1 , both = 0}
	RangePercentFilter(25),{25 percent larger range days than x number of
ranges ago is default}
	NumberofDaysback(3), {number of days back to test the range}
	LongProfitTarget(4000),{long profit target}
    ShortProfitTarget(5000),{short profit target}
	Stoploss(2000),{duh}
	bizaroflag(1); {bizaroflag -1 for opposite signals}



Vars:Rangeval(0),
	Debug(0);



if currentbar > 20 then begin

if bizaroflag <> -1 then begin

Rangeval=AvgTrueRange(NumberOfDaysBack)[1]+AvgTrueRange(NumberOfDaysBack)[1]
*RangePercentFilter/100;
	if debug = 1 then Print (Rangeval,range);
	if range>Rangeval and high >
highest(high,Numberofdaysback)[1]+AvgTrueRange(NumberOfDaysBack)[1]  and
buyorsell <>-1 and close > open then buy at close;
	if marketposition = 1 then setprofittarget(longProfitTarget);

	if marketposition = 1 then sell next bar at low[barssinceentry+1] stop;


	if range>Rangeval and low <
lowest(low,Numberofdaysback)[1]+AvgTrueRange(NumberOfDaysBack)[1]  and
buyorsell <>1 and close < open then sell at market;
	if marketposition = -1 then setprofittarget(shortProfitTarget);

	if marketposition = -1 then buy next bar at high[barssinceentry+1] stop;

	setstoploss(stoploss);
end;

if bizaroflag = -1 then begin

Rangeval=AvgTrueRange(NumberOfDaysBack)[1]+AvgTrueRange(NumberOfDaysBack)[1]
*RangePercentFilter/100;
	if debug = 1 then Print (Rangeval,range);
	if range>Rangeval and high >
highest(high,Numberofdaysback)[1]+AvgTrueRange(NumberOfDaysBack)[1]  and
buyorsell <> -1 and close > open then sell at close;
	if marketposition = 1 then setprofittarget(longProfitTarget);
	if marketposition = 1 then setstoploss(stoploss);
	if marketposition = 1 then sell next bar at low[barssinceentry+1] stop;


	if range>Rangeval and low <
lowest(low,Numberofdaysback)[1]+AvgTrueRange(NumberOfDaysBack)[1]  and
buyorsell <> 1 and close < open then buy at market;
	if marketposition = -1 then setprofittarget(shortProfitTarget);
	if marketposition = -1  then setstoploss(stoploss);
	if marketposition = -1  then buy next bar at high[barssinceentry+1] stop;

	setstoploss(stoploss);
end;


end;
---