Reply To: SWITCH function script usage

Optuma Forums Optuma Scripting SWITCH function script usage Reply To: SWITCH function script usage

#46687

Colin
  • Topics: 4
  • Replies: 6
  • Posts: 10

Hi Matthew,

I’ve put the entire thing in my other thread. 

FWIW here is the same script:

// 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;

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

This covers both my pending queries.

I’m really keen to get this sorted. I hope it’s simple!

cheers

colin

 

Pin It on Pinterest

Share This

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close