- Topics: 9
- Replies: 19
- Posts: 28
Thanks. A great deal of understanding arose and I have completely revised my script. I see that the SWITCH function acts as a toggle when both inputs are on. You might want to update the knowledge base.
I have 1 final nasty bug. I’ll put the full code at the end. The troublesome bit is this:
BUYPRICE = IF( Ton, THISPRICE, BUYPRICE);
plot4 = BUYPRICE;
SELLPRICE = IF( Toff, THISPRICE,0);
plot5 = SELLPRICE;
THISPROFIT = IF( ((TRADING <= 0) and Toff), (SELLPRICE – BUYPRICE), 0);
//THISPROFIT = IF( ((TRADING <= 0) and Toff), SELLPRICE -(1.0 * BUYPRICE) , 0);
plot6 = THISPROFIT;
//plot6 = 0.5 * BUYPRICE; // this plot works, BUYPRICE is as expected
- not surviving the trip between computation, plotting and its subsequent use in TOTPROFIT
- somehow being re-typed from a float to a boolean?
If I install the bold lines to plot BUYPRICE I get it plotted at 0.5 where you’d expect.
If I re-type BUYPRICE by coercing to a float by multiplying by 1.0 it still doesn’t work.
No matter how I do it, if I include BUYPRICE it in TOTPROFIT IF(), it is as if it’s always zero. The SELLPRICE – BUYPRICE fails.
The full code….
// 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); // Special plot placement to avoid optuma bug 1 May 2018 plot1 = DPtot; plot2 = D2P; c1 = (DPtot > 0) and (D2P > 0) and (OFFSET(D2P, OFFSET=1) > 0); c2 = (DPtot <= 0) ; TRADING = SWITCH( c1 , c2 ); // Positive edge on TRADING plot3 = TRADING; Ton = (TRADING > 0) and (OFFSET(TRADING, OFFSET=1) <= 0); // Positive edge on TRADING Toff = (TRADING <= 0) and (OFFSET(TRADING, OFFSET=1) > 0); // Negative edge on TRADING THISPRICE = (close() + open() + high() + low())/4.0; BUYPRICE = IF( Ton, THISPRICE, BUYPRICE); plot4 = BUYPRICE; SELLPRICE = IF( Toff, THISPRICE,0); plot5 = SELLPRICE; THISPROFIT = IF( ((TRADING <= 0) and Toff), (SELLPRICE – BUYPRICE), 0); //THISPROFIT = IF( ((TRADING <= 0) and Toff), SELLPRICE , 0); plot6 = THISPROFIT; //plot6 = 1.0 * BUYPRICE; //TOTPROFIT = IF( TRADING, OFFSET(TOTPROFIT, OFFSET=1), (IF(OFFSET(TRADING, OFFSET=1), (OFFSET(TOTPROFIT, OFFSET=1) + THISPROFIT), OFFSET(TOTPROFIT, OFFSET=1)) )); //TOTPROFIT = OFFSET(TOTPROFIT, OFFSET=1) + THISPROFIT; //plot7 = TOTPROFIT; plot1.Plotstyle = Step; plot1.colour = green; plot2.Plotstyle = Histogram; plot2.colour = red; plot3.Plotstyle = step; plot3.colour = black; plot3.linewidth = 2; plot4.Plotstyle = step; plot4.linestyle = dash; plot5.Plotstyle = step; plot5.linewidth = 2; plot6.Plotstyle = step; plot6.Colour = lightgreen; plot6.linewidth = 2; //plot7.Plotstyle = step; //plot7.linewidth = 2;
Also: In the absense of its automation, is there anyplace I can get the DOT functions and settings for PLOT.etc = somevalue?
I’m exploring workarounds for my TOTPROFIT computation, but feel you ought to know there’s something severely amiss in the script compiler/interpreter.
Or I’ve messed up somehow!