@C_M, we’re getting closer to understanding what you want, but collectively, it’s taken 15 posts, at an average of 45min per post, to read/ understand, think about, develop code, and write a response – if you had hired someone professionally to sort this out for you, it would have cost you the equivalent of 2 days’ wages so-far, at $100/hr.
The first issue I can see, coding efficiency, is:
SetBarFillColor( IIf( C > O, ParamColor( "Candle UP Color", colorGreen ), IIf( C <= O, ParamColor( "Candle Down Color", colorRed ), colorLightGrey ) ) );
Plot( C, "", IIf( C > O, ParamColor( "Wick UP Color", colorDarkGreen ), IIf( C <= O, ParamColor( "Wick Down Color", colorDarkRed ), colorLightGrey ) ), styleBar, 0, 0, 0, 0 );
Whilst this works, it’s cluttered, takes time to untangle and understand what the code is doing, which means that in the longer-run, 6 months later, maintaining it’s going to be a problem. A cleaner way, IMO, is to:
// These variables are dedicated to holding _user selections_, and can now be referenced/ used anywhere in the code
selUpColor = ParamColor( "UP Color", colorDarkGreen ) ;
selDnColor = ParamColor( "Down Color", colorDarkRed ) ;
selNoChangeColor = ParamColor( "No change Color", colorLightGrey) ;
// A dedicated variable to hold the color of the status of the Open:Close.
colorOfBar = IIf( Close > Open, selUpColor, IIf( Close <= Open, selDnColor, selNoChangeColor)) ;
// Now bring it all together
SetBarFillColor(colorOfBar);
Plot(Close, "", colorOfBar, styleBar, 0, 0, 0, 0 );
At the bottom, I had to change the colors because nothing showed-up on my screen, and removed the Iif()
from within the Plot()
- you don’t need it, as you already have the status in the Short
variable:
//Plot( targetarray, "", colorWhite, styleNoRescale, Null, Null, 0, 1, 1 );
//PlotShapes( IIf( short, shapeSMALLdownTRIANGLE, shapeNone ), colorlightyellow, 0, h, -35 );
// It’s always useful to provide a label for the variables that you plot, particularly during
// the development phase, so that the value for a specific bar can be seen in the "Data" window
// enabling you to determine whether it’s appropriate or not
//
// Note: be careful with using "styleNoRescale" - it causes things to disappear from view,
// which means that you're likely to forget about them and how they affect the
// rest of the code - a better way would be to show everything until your absolutely sure that
// it's no longer necessary to do so.
Plot(targetarray, "targetarray", colorBlue, styleLine, Null, Null, 0, 1, 1 );
PlotShapes(Short * shapeSmallDownTriangle, colorGreen, 0, High, -35 );
The body of the code, within the for()
loop, creates one long horizontal line (on some symbols) from the very first short signal, and it persists to the right-hand edge of the chart, 1500 bars later on one of my examples!, even though there are other signals to go Short after the first one.
From memory, you haven’t specified what you want the software to do regarding the following:
- New Short signal – Do they close-out a prior trade?
- Should there be multiple stop lines on the chart, one for each Short signal? This has the potential to display thousands of lines!
- How long does the stop line persist for?