Lack of execution on data1 when using data2 for calculations

Questions about MultiCharts and user contributed studies.
MeiHua
Posts: 26
Joined: 12 Aug 2012
Has thanked: 1 time

Lack of execution on data1 when using data2 for calculations

Postby MeiHua » 25 Sep 2012

I have created a strategy that uses daily bars. however contracts do not last 200 days so i needed to use data2 to do those calculations however because the current contract does not have 200 days it wont put in an order. I dont understand why not it should execute on data1 (the current contract) and calculate on data2 (the custom contract). However only if i place 200+ bars on the data1 stream do i get entries. Is there a way to correct his problem? i have used the calls to data2 both inside and outside the parenthesis as shown on TJs thread for questions. I still get the same result.

How can i get the calculations done on data 2 and the execution on data1? thanks


Code: Select all


Variables: HighestHigh ( 0 ), LowestLow ( 0 ), SMAvalue ( 0 );


HighestHigh = Highest( Close data2, HLLength)[1];

LowestLow = Lowest( Close data2, HLLength)[1];

SMAvalue = AverageFC(Close data2, SMAlength);

if Close < LowestLow and Close > SMAvalue then
   Buy ("7/7 LE") next bar at market;

If MP = 1 and close > HighestHigh then
   Sell (" 7/7 LX") next bar at market;


here are screen shots
Attachments
standard contract loaded.jpg
current contract
standard contract loaded.jpg (137.1 KiB) Viewed 132 times
365 days loaded.jpg
custom contract loaded with 365 days
365 days loaded.jpg (152.91 KiB) Viewed 134 times

User avatar
TJ
Posts: 6571
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1899 times

Re: Lack of execution on data1 when using data2 for calculat

Postby TJ » 25 Sep 2012

MeiHua wrote:I have created a strategy that uses daily bars. however contracts do not last 200 days so i needed to use data2 to do those calculations however because the current contract does not have 200 days it wont put in an order. I dont understand why not it should execute on data1 (the current contract) and calculate on data2 (the custom contract). However only if i place 200+ bars on the data1 stream do i get entries. Is there a way to correct his problem? i have used the calls to data2 both inside and outside the parenthesis as shown on TJs thread for questions. I still get the same result.

How can i get the calculations done on data 2 and the execution on data1? thanks

You sure can.


Code: Select all

Variables: HighestHigh ( 0 ), LowestLow ( 0 ), SMAvalue ( 0 );
HighestHigh = Highest( Close data2, HLLength)[1];
LowestLow = Lowest( Close data2, HLLength)[1];
SMAvalue = AverageFC(Close data2, SMAlength);
if Close < LowestLow and Close > SMAvalue then
   Buy ("7/7 LE") next bar at market;
If MP = 1 and close > HighestHigh then
   Sell (" 7/7 LX") next bar at market;


here are screen shots


see post #5
viewtopic.php?f=16&t=6929
These users thanked the author TJ for the post (total 2):
Andrew MultiChartsHenry MultiСharts

MeiHua
Posts: 26
Joined: 12 Aug 2012
Has thanked: 1 time

Re: Lack of execution on data1 when using data2 for calculat

Postby MeiHua » 26 Sep 2012

I have tried those techniques as outlined in the post you linked. I even referenced reading them in the first post. However the execution is still lacking. Can you please explain to me how to fix that problem. I understand that you can execute that way but the strategy wont even though all the calculations have been done on data2. i have tried formatting both in and outside the parenthesis as you stated in your referenced post.

User avatar
TJ
Posts: 6571
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1899 times

Re: Lack of execution on data1 when using data2 for calculat

Postby TJ » 26 Sep 2012

MeiHua wrote:I have tried those techniques as outlined in the post you linked. I even referenced reading them in the first post. However the execution is still lacking. Can you please explain to me how to fix that problem. I understand that you can execute that way but the strategy wont even though all the calculations have been done on data2. i have tried formatting both in and outside the parenthesis as you stated in your referenced post.


Why are you posting the code with the wrong syntax?
Where should we start to debug you code?

User avatar
TJ
Posts: 6571
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1899 times

Re: Lack of execution on data1 when using data2 for calculat

Postby TJ » 26 Sep 2012

I trade HSI, which is a monthly contract. I have no problem with data1/data2.

User avatar
TJ
Posts: 6571
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1899 times

Re: Lack of execution on data1 when using data2 for calculat

Postby TJ » 26 Sep 2012

Look up these in Wiki:

Custom Futures
Continuous Futures Contract

User avatar
TJ
Posts: 6571
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1899 times

Re: Lack of execution on data1 when using data2 for calculat

Postby TJ » 26 Sep 2012


MeiHua
Posts: 26
Joined: 12 Aug 2012
Has thanked: 1 time

Re: Lack of execution on data1 when using data2 for calculat

Postby MeiHua » 30 Sep 2012

I have used the custom contract. Back adjusted for the YM, which i am trying to trade for this. This is fine. also when i just use 1 data stream it trades fine. The only problem is shifting from 1 data stream to 2 data streams in order to actually execute on the current front month contract. I just dont understand why it isn't doing that. All my variables are valid and it trades fine on a single data stream custom contract. I have used print to debug as well as indicator. I have tried shifting the calculations to data2 then just leave the buy/sell statements. I use a custom contract and have it plot and execute on back test on that single stream.

here is a more complicated code that also has the same problem. I posted the most simple system that contains the problem assuming it could be fixed easily and i could transfer that info into more of my systems that require it.

Code: Select all

Input:
//Price Channel
LookBack ( 7 ), 
//SMA Bias Filter
MAlength ( 200 );
Variables:
// Price Channel
 HighBar ( 0 ), LowBar ( 0 ),
 // System Variables
 LongBias (false),
 //SMA bias filter
 SMAvalue ( 0 ),
 //Trend Strength Index
 TSIvalue ( 0 ),
 // Adaptive Profit Target/ Entry
ProfitTarget ( 0 ) , EnterLongPrice ( 0 );
 
{Simple Moving Average Calculations}
SMAvalue = Average(Close data2, MALength );

{Set Trend Bias Logic}

If Close data2 > SMAValue then
LongBias = True
else
Longbias = False;

{Trend Strength Index}
TSIvalue = TrendStrengthIndex(10) data2;

// Adaptive Entry

IF TSIvalue[1] > TSIvalue[0] then
EnterLongPrice = Lowest(Low data2, LookBack)[1]
else
EnterLongPrice = Lowest(Close data2, LookBack)[1];


{Order Logic and Entry}
If LongBias = true then
   Buy (" 77 LE" ) next bar at(EnterLongPrice - 1 point) limit ;
   
{Trade Exit}
   
// Adaptive Exit

IF TSIvalue < 1.65 then
ProfitTarget = Highest(High data2, Lookback)[1]
else
ProfitTarget = Highest(Close data2, LookBack)[1];

IF MP = 1 then
   Sell (" 77 LX") next bar at ProfitTarget Limit;


http://my.jetscreenshot.com/12147/20120930-9bt3-171kb

screenshot of plots on single datastream as you can see its all valid.

User avatar
TJ
Posts: 6571
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 968 times
Been thanked: 1899 times

Re: Lack of execution on data1 when using data2 for calculat

Postby TJ » 30 Sep 2012

MeiHua wrote:I have used the custom contract. Back adjusted for the YM, which i am trying to trade for this. This is fine. also when i just use 1 data stream it trades fine. The only problem is shifting from 1 data stream to 2 data streams in order to actually execute on the current front month contract. I just dont understand why it isn't doing that. All my variables are valid and it trades fine on a single data stream custom contract. I have used print to debug as well as indicator. I have tried shifting the calculations to data2 then just leave the buy/sell statements. I use a custom contract and have it plot and execute on back test on that single stream.

here is a more complicated code that also has the same problem. I posted the most simple system that contains the problem assuming it could be fixed easily and i could transfer that info into more of my systems that require it.

Code: Select all

Input:
//Price Channel
LookBack ( 7 ), 
//SMA Bias Filter
MAlength ( 200 );
Variables:
// Price Channel
 HighBar ( 0 ), LowBar ( 0 ),
 // System Variables
 LongBias (false),
 //SMA bias filter
 SMAvalue ( 0 ),
 //Trend Strength Index
 TSIvalue ( 0 ),
 // Adaptive Profit Target/ Entry
ProfitTarget ( 0 ) , EnterLongPrice ( 0 );
 
{Simple Moving Average Calculations}
SMAvalue = Average(Close data2, MALength );

{Set Trend Bias Logic}

If Close data2 > SMAValue then
LongBias = True
else
Longbias = False;

{Trend Strength Index}
TSIvalue = TrendStrengthIndex(10) data2;

// Adaptive Entry

IF TSIvalue[1] > TSIvalue[0] then
EnterLongPrice = Lowest(Low data2, LookBack)[1]
else
EnterLongPrice = Lowest(Close data2, LookBack)[1];


{Order Logic and Entry}
If LongBias = true then
   Buy (" 77 LE" ) next bar at(EnterLongPrice - 1 point) limit ;
   
{Trade Exit}
   
// Adaptive Exit

IF TSIvalue < 1.65 then
ProfitTarget = Highest(High data2, Lookback)[1]
else
ProfitTarget = Highest(Close data2, LookBack)[1];

IF MP = 1 then
   Sell (" 77 LX") next bar at ProfitTarget Limit;


http://my.jetscreenshot.com/12147/20120930-9bt3-171kb

screenshot of plots on single datastream as you can see its all valid.


Have you read the link on post #2 and actually understood what it meant?
I am still seeing the same data2 mistakes.

MeiHua
Posts: 26
Joined: 12 Aug 2012
Has thanked: 1 time

Re: Lack of execution on data1 when using data2 for calculat

Postby MeiHua » 30 Sep 2012

I have tried every iteration of examples in the post#2 both inside and outside parentheses. and of data2 as well as declaring variables with ,data2. the reason you see the same "mistakes" is because i didn't keep the changes. if you would like to show me what changes you think would fix it i would be happy to try them.


Return to “MultiCharts”