What's wrong in my strategy?

Questions about MultiCharts and user contributed studies.
z7c9
Posts: 7
Joined: 31 Jul 2010

What's wrong in my strategy?

Postby z7c9 » 27 Aug 2010

hi,all
I develop a intraday strategy like this,

if thisbar's high > the highest of pre 52 bar's high then buy;
if thisbar's low < the lowest of pre 24 bar's low then sell;
if thisbar's low < the lowest of pre 52 bar's low then sellshort;
if thisbar's high > the highest of pre 24 bar's high then buytocover;

concret code:

Code: Select all

[intrabarordergeneration=True]
inputs:fastlen(24),slowlen(52);
vars:tradingtime(false);

tradingtime=time>=1001 and time<=1458;

if marketposition=0 then begin
   if high > Highest(high,52)[1] then
      buy 1 contract this bar at close;
   
   if tradingtime and low crosses below Lowest(low[1],slowlen) then
      sellshort 1 contract next bar at Lowest(low[1],slowlen) limit;       
end;

if marketposition>0 then begin
   if tradingtime and low crosses below Lowest(low[1],fastlen) then
      sell currentcontracts contracts next bar at Lowest(low[1],fastlen) limit;
   if not tradingtime then
      sell currentcontracts contracts next bar at close limit;   
end;

if marketposition<0 then begin
   if tradingtime and high crosses above Highest(high[1],fastlen) then
      buytocover currentcontracts contracts next bar at Highest(high[1],fastlen) limit;
   if not tradingtime then
      buytocover currentcontracts contracts next bar at close limit;   
end


but i found this code is wrong on chart because miss some entrys although apply my rule.
I wonder what's wrong in my code.

please help me root out bugs in my strategy.

thanks in advance.

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: What's wrong in my strategy?

Postby TJ » 27 Aug 2010

z7c9 wrote:hi,all
I develop a intraday strategy like this,

if thisbar's high > the highest of pre 52 bar's high then buy;
if thisbar's low < the lowest of pre 24 bar's low then sell;
if thisbar's low < the lowest of pre 52 bar's low then sellshort;
if thisbar's high > the highest of pre 24 bar's high then buytocover;

concret code:

Code: Select all

[intrabarordergeneration=True]
inputs:fastlen(24),slowlen(52);
vars:tradingtime(false);

tradingtime=time>=1001 and time<=1458;

if marketposition=0 then begin
   if high > Highest(high,52)[1] then
      buy 1 contract this bar at close;
   
   if tradingtime and low crosses below Lowest(low[1],slowlen) then
      sellshort 1 contract next bar at Lowest(low[1],slowlen) limit;       
end;

if marketposition>0 then begin
   if tradingtime and low crosses below Lowest(low[1],fastlen) then
      sell currentcontracts contracts next bar at Lowest(low[1],fastlen) limit;
   if not tradingtime then
      sell currentcontracts contracts next bar at close limit;   
end;

if marketposition<0 then begin
   if tradingtime and high crosses above Highest(high[1],fastlen) then
      buytocover currentcontracts contracts next bar at Highest(high[1],fastlen) limit;
   if not tradingtime then
      buytocover currentcontracts contracts next bar at close limit;   
end


but i found this code is wrong on chart because miss some entrys although apply my rule.
I wonder what's wrong in my code.

please help me root out bugs in my strategy.

thanks in advance.


before you embark on a "strategy",
you should test out your logic with an indicator.

try replace your Buy/Sell with a plot...

eg.

change

Code: Select all

if marketposition=0 then begin
   if high > Highest(high,52)[1] then
      buy 1 contract this bar at close;


to

Code: Select all

if high > Highest(high,52)[1] then
   PLOT10( HIGH, "BUY1");


Set the plot style to a large point.
If you do not see a plot... you won't likely get an order.

z7c9
Posts: 7
Joined: 31 Jul 2010

Re: What's wrong in my strategy?

Postby z7c9 » 27 Aug 2010

I found the root of the problem.
In Strategy properties,
when set maxbarsback 100 then some entry signals not send out.

when set maxbarsback 52,alert a message says "Tried to reference back more bars(53) than allowed by the current maxbarsback setting".

when set maxbarsback 64,all the problems disappear.

so what's the real mean about maxbarsback?

i think my strategy only reference max back bars is 52,why set the value from 52 to 63 all get the noise alert?
Attachments
Untitled.png
Untitled.png (17.64 KiB) Viewed 88 times


Return to “MultiCharts”