STD exception: invalid argument - While using Data2

Questions about MultiCharts and user contributed studies.
GSATrader
Posts: 15
Joined: 24 Jan 2006

STD exception: invalid argument - While using Data2

Postby GSATrader » 06 Oct 2009

I am trying to automate a strategy i have in which i require Data2 functions, in this case Stochastic.



When i try to get the stochastic i get an error message
"Message: Error in study "Name":STD exception: invalid argument" on the following code:

Code: Select all

value1 = Stochastic(high, low , close, StochLenght, StochAvg, 3, 2, oFastK, oFastD, oSlowK, oSlowD) of data2;
Even if i use the following:

Code: Select all

value1 = Stochastic(high of data2, low of data2, close of data2, StochLenght, StochAvg, 3, 2, oFastK, oFastD, oSlowK, oSlowD) of data2;

Wasnt this suposed to be already fixed from the latest fixes of MC, sinse 2008?

Best Regards

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 06 Oct 2009

I compiled the 2nd code with no problem.

GSATrader
Posts: 15
Joined: 24 Jan 2006

Postby GSATrader » 06 Oct 2009

i tried isolating the 2nd code only, and i get the same errors all over. i dont understand how something as simple as getting a data2 stochastic gets errors :$

HELP plz!

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 06 Oct 2009

i tried isolating the 2nd code only, and i get the same errors all over. i dont understand how something as simple as getting a data2 stochastic gets errors :$

HELP plz!

the 2nd code compiled in my MC...
that means there is nothing wrong with the code.


which version of MC/PLE you are using?
I am using 5.5.2723.400, 1.6.2723.400

please go to your PLE, click on Help>About to find out.



p.s. if all effort fails, reboot the computer.

GSATrader
Posts: 15
Joined: 24 Jan 2006

Postby GSATrader » 06 Oct 2009

I am using the same version as you are. But the problem is deeper than this

So i want a fastK from a Data 2 then i want to smooth it. That is the goal

So i broke things into small pieces.

I created a Manual Fastk

Code: Select all


Var:Var0(0),Var1(0),var2(2),Var3(0);
var0 = Lowest( low, 4 )of data2 ;
var1 = Highest( high, 4 )of data2 ;
var2 = close of data2 - var0 ;
var3 = var1 - var0 ;

if var3 > 0 then
value1 = var2 / var3 * 100 ;
So far so good, i have the 2 timeframes, i replicated the code to see the FastK naked on the higher tf, which is data2 , and i can see the code plotting on the fastk from data 2 correctly in the Master Chart.

1 problem emerges imediatly. It plots 2 values instead of only 1. Which means, if i try now to make a Average(value1,Smoothingfactor) to get a SlowD, it will NEVER match.

nor will formulas as IF value1 > value1[1] will work because they will be comparing every now and again with a 2nd plot of the same value. i attached a picture with what i get.

Now i know you will tell me to change the indicator and base it on Data2. But my question is this, as i want to develop a strategy based uppon 2 diferent data streams, how do i diferenciate that in the strategy code?

I must be able to make the indicator plot correctly from the code, without having to change its settings, as i am not able to select the source of the data inside the strategy code.

Any help would be hugely apreciated
Attachments
data2.png
(50.84 KiB) Downloaded 1186 times

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 06 Oct 2009

Another method, would be to set up a separate chart with the data2 timeframe and use a global variable to send that value of Stoch to your strategy.

GSATrader
Posts: 15
Joined: 24 Jan 2006

Postby GSATrader » 06 Oct 2009

well, yes thats true.

Or use the ADE's TSZ and ELDCollections, but...... the purpuse of having data2 on the same chart isnt exactly avoiding that?

Besides which with GlobalVariables its impossible to backtest not to say the reability of the codes and its complexity grows exponentialy.

Best Regards

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 06 Oct 2009

I am using the same version as you are. But the problem is deeper than this...

make up your mind on what you want to fix.

does your code#2 has problem?

or MC has problem that's supposed to be fixed sinse 2008?

or do you want to shift to something else now?

GSATrader
Posts: 15
Joined: 24 Jan 2006

Postby GSATrader » 06 Oct 2009

Thank you TJ

MC is completly unable to plot the code using the fucntion of Stochastic. it gives me the error
"STD exception: invalid argument"
With any variation of it.
I think it referes to this bug reported some time back

http://forum.tssupport.com/viewtopic.ph ... e8b1c8f8c1

So to try to see why that was happening i stoped using the stochastic fucntion and i wrote the Stochastic code myself.

Code: Select all

Var:Var0(0),Var1(0),var2(2),Var3(0);
var0 = Lowest( low, 4 )of data2 ;
var1 = Highest( high, 4 )of data2 ;
var2 = close of data2 - var0 ;
var3 = var1 - var0 ;

if var3 > 0 then
value1 = var2 / var3 * 100 ;
By doing so i am able to properly see the FastK from data2.
So i asume the error message i get by using the stochastc function comes from the function itself.

I dont mind at all not using the function and write the base code, but by doing so i got into this second problem. Which is:

As i want to use the Stochastic from data2 as a strategy generating signals, i must be able to use properly the "value1>value1(1)" kinda references.
And as you can see in the picture i attached, even writing the full stochastic based "of data2" in the 1000v timeframe it plots me 2 similar plots.

So any calculation i make uppon the data ploted will be faulty. A simple moving average would be faulty because of the 2 similar plots.

I know as an indicator i would have to edit its properties, reference it as based on data of 2000v chart and that would fix the 2 similar plots problem.

Never the less, i cant do that inside a signal/strategy code.
So how can i prevent, by code, to have the 2 similar plots? is that possible?


Best Regards
Attachments
data2.png
(50.84 KiB) Downloaded 1172 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 06 Oct 2009

have you tried declaring the variables first.

e.g.

Code: Select all

var:
high2 = high of data2,
low2 = low of data2,
open2 = open of data2,
close2 = close of data2;

I found that by assigning the data2 to a set of variable, you do not need to tag "data2" behind everything... and the MC tend to know exactly what you are referring to without doubt.


p.s. try NOT to use generic variables. i.e. value1, var1, condition1, etc.
in a complex program, they inevitably get mixed up with something you did not intend.

GSATrader
Posts: 15
Joined: 24 Jan 2006

Postby GSATrader » 06 Oct 2009

I see what you mean TJ yes thank you.

but still that still wont solve my issue of double value plotting.

I declared as following

Code: Select all

Var:Myhigh(0),Mylow(0),myClose(0),Var0(0),Var1(0),var2(2),Var3(0);

myhigh= high of data2;
Mylow = Low of data2;
myclose=close of Data2;
var0 = Lowest( Mylow , 4 ) ;
var1 = Highest( myhigh, 4 );
var2 = myclose - var0 ;
var3 = var1 - var0 ;

if var3 > 0 then
value1 = (var2 / var3 * 100) ;
value2=Average(value1, 8) ;
Plot1 (value1 ,"fastk") ;
plot2(value2 ,"slowd");
but still i get the chart plotting data in every bar of 1000v.
Again i know if i change the "source" of the data to 2000v chart it will fix that, but how can i do that inside the signal/strategy? is there anyway to work arround this problem? because in a Signal/strategy code i cant tell it to "read" from the data2 only. it will always plot data on each 1000v bar. so a simple Value1> value1[1] will be missleading.


Thank you so much
Best Regards

Image of current chart in attachement
Attachments
data22.png
(48.53 KiB) Downloaded 1166 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 06 Oct 2009

... because in a Signal/strategy code i cant tell it to "read" from the data2 only. it will always plot data on each 1000v bar. so a simple Value1> value1[1] will be missleading.
...

I don't think I am fully following the problem...
I need to re-read your posts again.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 06 Oct 2009

on your indicator, go to Format Study,

choose Properties tab,

under Base Study On section,

make sure it is on the slower fractal.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 06 Oct 2009

I should note that most people structure the signals with:

the faster fractal being the trading data series,
and the slower fractal as the supporting data series.



.
Last edited by TJ on 07 Oct 2009, edited 2 times in total.

GSATrader
Posts: 15
Joined: 24 Jan 2006

Postby GSATrader » 06 Oct 2009

I just did that yes, and the double plotting of data disapears. Only 1 plot per 2000v bar.

However, how do i reference that inside a Strategy, automated strategy code.

I cant define inside a Signal/strategy code that the Indicator that is based on data2 needs to be based on the slower chart plotted.

So this implys 2 things.
1) indicator shows one thing when ploted, but the strategy code will read a diferent thing as it will recieve diferent results from the indicator (which is not based on the slower chart plotted anymore because inside a strategy i cant define that)

2) if i say "value1 > value1[1]" where value1 is the stoch of the data2, it will read me value1[1] as the previous 1000v bar, not the previous 2000v bar.

i guess i could always refer to Value1 > Value1[2] but is this the only work arround possible?


How do i deal with the fact the data2 stoch will give me diferent results as an indicator and as a "function" inside the strategy/signal?


Best Regards
Gil

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 06 Oct 2009

you can put lots of Print statement at every juncture of your program,
you can then read the changes happening to various variables as the market unfolds.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Postby SUPER » 07 Oct 2009


So this implys 2 things.
1) indicator shows one thing when ploted, but the strategy code will read a diferent thing as it will recieve diferent results from the indicator (which is not based on the slower chart plotted anymore because inside a strategy i cant define that)
Indicators are updated on every tick and to replicate same effect for a strategy you will have to use intrabarordergeneration in your strategy code, mind you it is not trivial task. Standard strategies update data on close of bar –which may be the case with your code. Like TJ suggested, "print" statement will assist you to compare computation in your code.

GSATrader
Posts: 15
Joined: 24 Jan 2006

Postby GSATrader » 07 Oct 2009

Thank you TJ and Super. i understand what both of you mean.

Although the issue dont come from there.

What happens is the same code, exactly the same code, will produce data from the indicator that is completly diferent if plotted (and referencing the higher/slower timeframe) in a chart as an indicator, and if read from inside a strategy code (where we cant tell it to reference the higher/slower timeframe).

The values from the indicator/function just have no correlation between them. So theres little use for the print statements when the indicator itself cant be even compared. Its use as a filter dies there imediatly.

I find this completly surprising because i am sure more users may use the same functionalitys.

Thank you again for your help
Best Regards
Gil


Return to “MultiCharts”