Mysterious 'valid script' violation

Hi Folk,

Optuma has gazzumped me in an unfathomable way. Perhaps you can help?

===================================

{some pre code for DPtot, D2P is not duplicated here}

TRADING = SWITCH( (DPtot > 0) and (D2P > 0) and (OFFSET(D2P, OFFSET=1) > 0), (DPtot <= 0) );

BUYPRICE = IF( TRADING, (IF(OFFSET(TRADING, OFFSET=1) , BUYPRICE, ( (close() + open() + high() + low())/4.0) ) ), 0);

SELLPRICE = IF( TRADING, 0, (IF(OFFSET(TRADING, OFFSET=1), ( (close() + open() + high() + low())/4.0 ), 0) ));

THISPROFIT = IF( TRADING, 0, (IF(OFFSET(TRADING, OFFSET=1), (SELLPRICE - BUYPRICE), 0) ));

TOTPROFIT = OFFSET(TOTPROFIT, OFFSET=1) + THISPROFIT;

//Plots

plot1 = DPtot; plot1.Plotstyle = step;

plot1.colour = green;

plot1.visible = 1;

plot2 = D2P;

plot2.Plotstyle = histogram;

plot2.colour = red;

plot3 = TRADING;

plot3.Plotstyle = step;

plot3.colour = black;

plot3.linewidth = 2;

plot3.visible = 1;

plot4 = BUYPRICE;

plot4.Plotstyle = step;

plot4.visible = 1;

plot5 = THISPROFIT;

plot5.Plotstyle = step;

plot5.linewidth = 2;

plot5.visible = 1;

plot6 = SELLPRICE;

plot6.Plotstyle = step;

plot6.linewidth = 2;

plot6.visible = 1;

plot7 = TOTPROFIT;

plot7.Plotstyle = step;

plot7.linewidth = 2;

plot7.visible = 1;

================================

The problem:

If programmed above I get this response from the compiler/interpreter:

Capture1

yet, when I simply comment out one line, leaving one of the variables undefined, I get this

Capture2

.... some the interpreter thinks it's OK but it can't possibly work, and it offers no clue as to what is wrong with the script.

...therein is the source of my ansgt.... :-)

Any wisdom?

cheers

colin hales

 

Hi Colin,

Unfortunately we can not test this without the full script. On the surface I can not see why it is not working but we would need the full script to be able to see if there is a conflict with something further up.

One thing I have seen, but not been able to repeat, is that sometimes there can be a hidden character in the script. The way to solve that is to copy the whole script and then paste it in Notepad. Then copy it again in notepad and paste it back into the script editor. Notepad strips out hidden characters.

Regardless, if you are still having issues with it and you do not want to put the full script in here, email it to us at [email protected] and we’ll have a look at what is going on.

All the best

Mathew

Thanks Mathew,

Here's the whole thing. It's a lashup in early stage of exploration. Note that there's no carriage returns/line feeds anywhere, so Ctrl-C, Ctrl-V makes a mess.

==========================

// create all the change components DPco = open() - close(OFFSET=1); DPoc = close() - open(); DPhh = high() - high(OFFSET=1); DPll = low() - low(OFFSET=1); DPhl = (high() - low()) * ( ((close() - low()) / (high() - low())) - 0.5); // create the total change DPtot = DPco + DPoc + DPhh + DPll + DPhl; // compute the change compared to previous bar D2P = DPtot - OFFSET(DPtot, OFFSET=1); //c1 = (DPtot > 0) and (D2P > 0) and (OFFSET(D2P, OFFSET=1) > 0) //c2 = (DPtot <= 0) ; //TRADING = SWITCH( c1 , c2 ); TRADING = SWITCH( (DPtot > 0) and (D2P > 0) and (OFFSET(D2P, OFFSET=1) > 0), (DPtot <= 0) ); BUYPRICE = IF( TRADING, (IF(OFFSET(TRADING, OFFSET=1) , BUYPRICE, ( (close() + open() + high() + low())/4.0) ) ), 0); SELLPRICE = IF( TRADING, 0, (IF(OFFSET(TRADING, OFFSET=1), ( (close() + open() + high() + low())/4.0 ), 0) )); //THISPROFIT = IF( TRADING, 0, (IF(OFFSET(TRADING, OFFSET=1), (SELLPRICE - BUYPRICE), 0) )); TOTPROFIT = OFFSET(TOTPROFIT, OFFSET=1) + THISPROFIT; //Plots plot1 = DPtot; plot1.Plotstyle = step; plot1.colour = green; plot1.visible = 1; plot2 = D2P; plot2.Plotstyle = histogram; plot2.colour = red; plot3 = TRADING; plot3.Plotstyle = step; plot3.colour = black; plot3.linewidth = 2; plot3.visible = 1; plot4 = BUYPRICE; plot4.Plotstyle = step; plot4.visible = 1; plot5 = THISPROFIT; plot5.Plotstyle = step; plot5.linewidth = 2; plot5.visible = 1; plot6 = SELLPRICE; plot6.Plotstyle = step; plot6.linewidth = 2; plot6.visible = 1; plot7 = TOTPROFIT; plot7.Plotstyle = step; plot7.linewidth = 2; plot7.visible = 1;

==========================

I had a look for dodgy characters in Notepad ... nothing except a blank after one of the semi-colon terminators. It made no difference.

Note that I've made 2 posts and on reflection I think the two problems are possibly symptoms of the same problem: something to do with putting the OFFSET inside an IF() (maybe?).

I'm very interested in getting this running!

cheers

colin

 

 

Cheers

colin

 

Hi Colin

 

I'm "newish" to scripting but thought as a test I'd have a look.

 

Breaking it down and re-creating it, letting Optuma identify variables rather than typing them in (and commenting out line by line to see which it would allow me to comment out (as they all should be commentable I believe) and I got it valid. Hope it helps...

 

DPco = OPEN() - CLOSE();

DPoc = CLOSE()-OPEN();

DPhh = HIGH()-HIGH()[1];

DPll = LOW()-LOW()[1];

DPhl = (HIGH()-LOW())*(((CLOSE()-LOW())/(HIGH()-LOW())) - 0.5);

 

DPtot = DPco + DPoc + DPhh + DPll + DPhl;

PrevDPtot = DPtot[1];

 

DD2P = DPtot - PrevDPtot;

 

DD2P

 

TRADING = SWITCH( (DPtot > 0) and (D2P > 0) and (OFFSET(D2P, OFFSET=1) > 0), (DPtot <= 0) );

 

BUYPRICE = IF( TRADING, (IF(OFFSET(TRADING, OFFSET=1) , BUYPRICE, ( (close() + open() + high() + low())/4.0) ) ), 0);

SELLPRICE = IF( TRADING, 0, (IF(OFFSET(TRADING, OFFSET=1), ( (CLOSE() + OPEN() + HIGH() + LOW())/4.0 ), 0) ));

 

Cond3 = BUYPRICE;

Cond2 = SELLPRICE;

Cond4 = (Cond2-Cond3);

Cond1 = IF(OFFSET(TRADING, OFFSET=1), Cond4, 0);

THISPROFIT = IF (TRADING, 0, Cond1);

 

TOTPROFIT = TOTPROFIT[1] + THISPROFIT;

 

TOTPROFIT

 

 

Hi Colin,

I just wanted to let you know that I am seeing issues with this too and we’re having a look into this for you. It may be a day or two before we have an answer.

Sorry for the bother.

Mathew.