Simplifying code to make life easier
This price level study is super useful when scalping.. but adjusting the settings is very tedious the way it is set up
Is there a way to combine the below code so that all the 'P' levels (plot start) can be adjusted together as well as the 'M' levels (midpoint)?
As it stands you have to go in and adjust each individual level, thanks for any help, cheers
Original Code
#Auto Price Levels
#@rlohmeyer shared on UseThinkscript
input gapStart = no;
input gaplevel = 00;
input PLI = 1.00;
input showMidpoints = yes;
DefineGlobalColor("PLI",color.white);
DefineGlobalColor("MP",color.light_gray);
def cl = close(period = AggregationPeriod.DAY);
def ST = Round(cl[1], 0);
def START = if gapstart == 0 then ST else if gapstart == 1 then gaplevel else Double.NaN;
def MP = PLI/2;
#Plot START
plot PLS = START;
PLS.SetDefaultColor(color.orange);
PLS.HideTitle();
PLS.SetPaintingStrategy(PaintingStrategy.horizontal);
#START Up
plot MUS = if showMidpoints then START + MP else Double.NaN;
MUS.SetDefaultColor(globalColor("MP"));
MUS.HideTitle();
MUS.SetPaintingStrategy(PaintingStrategy.dashes);
MUS.HideBubble();
plot P2 = if START > 0 then START + PLI else Double.NaN;
P2.SetDefaultColor(globalColor("PLI"));
P2.HideTitle();
P2.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M2 = if showMidpoints then P2 + MP else Double.NaN;
M2.SetDefaultColor(globalColor("MP"));
M2.HideTitle();
M2.SetPaintingStrategy(PaintingStrategy.dashes);
M2.HideBubble();
plot P3 = if START > 0 then START + (2 * PLI)else Double.NaN;
P3.SetDefaultColor(globalColor("PLI"));
P3.HideTitle();
P3.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M3 = if showMidpoints then P3 + MP else Double.NaN;
M3.SetDefaultColor(globalColor("MP"));
M3.HideTitle();
M3.SetPaintingStrategy(PaintingStrategy.dashes);
M3.HideBubble();
plot P4 = if START > 0 then START + (3 * PLI)else Double.NaN;
P4.SetDefaultColor(globalColor("PLI"));
P4.HideTitle();
P4.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M4 = if showMidpoints then P4 + MP else Double.NaN;
M4.SetDefaultColor(globalColor("MP"));
M4.HideTitle();
M4.SetPaintingStrategy(PaintingStrategy.dashes);
M4.HideBubble();
plot P5 = if START > 0 then START + (4 * PLI)else Double.NaN;
P5.SetDefaultColor(globalColor("PLI"));
P5.HideTitle();
P5.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M5 = if showMidpoints then P5 + MP else Double.NaN;
M5.SetDefaultColor(globalColor("MP"));
M5.HideTitle();
M5.SetPaintingStrategy(PaintingStrategy.dashes);
M5.HideBubble();
plot P6 = if START > 0 then START + (5 * PLI)else Double.NaN;
P6.SetDefaultColor(globalColor("PLI"));
P6.HideTitle();
P6.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M6 = if showMidpoints then P6 + MP else Double.NaN;
M6.SetDefaultColor(globalColor("MP"));
M6.HideTitle();
M6.SetPaintingStrategy(PaintingStrategy.dashes);
M6.HideBubble();
plot P7 = if START > 0 then START + (6 * PLI)else Double.NaN;
P7.SetDefaultColor(globalColor("PLI"));
P7.HideTitle();
P7.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M7 = if showMidpoints then P7 + MP else Double.NaN;
M7.SetDefaultColor(globalColor("MP"));
M7.HideTitle();
M7.SetPaintingStrategy(PaintingStrategy.dashes);
M7.HideBubble();
plot P8 = if START > 0 then START + (7 * PLI)else Double.NaN;
P8.SetDefaultColor(globalColor("PLI"));
P8.HideTitle();
P8.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M8 = if showMidpoints then P8 + MP else Double.NaN;
M8.SetDefaultColor(globalColor("MP"));
M8.HideTitle();
M8.SetPaintingStrategy(PaintingStrategy.dashes);
M8.HideBubble();
plot P9 = if START > 0 then START + (8 * PLI)else Double.NaN;
P9.SetDefaultColor(globalColor("PLI"));
P9.HideTitle();
P9.SetPaintingStrategy(PaintingStrategy.horizontal);
#STARTDown
plot MUD = if showMidpoints then START - MP else Double.NaN;
MUD.SetDefaultColor(globalColor("MP"));
MUD.HideTitle();
MUD.SetPaintingStrategy(PaintingStrategy.dashes);
MUD.HideBubble();
plot P10 = if START > 0 then START - PLI else Double.NaN;
P10.SetDefaultColor(globalColor("PLI"));
P10.HideTitle();
P10.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M10 = if showMidpoints then P10 - MP else Double.NaN;
M10.SetDefaultColor(globalColor("MP"));
M10.HideTitle();
M10.SetPaintingStrategy(PaintingStrategy.dashes);
M10.HideBubble();
plot P11 = if START > 0 then START - (2 * PLI) else Double.NaN;
P11.SetDefaultColor(globalColor("PLI"));
P11.HideTitle();
P11.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M11 = if showMidpoints then P11 - MP else Double.NaN;
M11.SetDefaultColor(globalColor("MP"));
M11.HideTitle();
M11.SetPaintingStrategy(PaintingStrategy.dashes);
M11.HideBubble();
plot P12 = if START > 0 then START - (3 * PLI)else Double.NaN;
P12.SetDefaultColor(globalColor("PLI"));
P12.HideTitle();
P12.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M12 = if showMidpoints then P12 - MP else Double.NaN;
M12.SetDefaultColor(globalColor("MP"));
M12.HideTitle();
M12.SetPaintingStrategy(PaintingStrategy.dashes);
M12.HideBubble();
plot P13 = if START > 0 then START - (4 * PLI)else Double.NaN;
P13.SetDefaultColor(globalColor("PLI"));
P13.HideTitle();
P13.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M13 = if showMidpoints then P13 - MP else Double.NaN;
M13.SetDefaultColor(globalColor("MP"));
M13.HideTitle();
M13.SetPaintingStrategy(PaintingStrategy.dashes);
M13.HideBubble();
plot P14 = if START > 0 then START - (5 * PLI)else Double.NaN;
P14.SetDefaultColor(globalColor("PLI"));
P14.HideTitle();
P14.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M14 = if showMidpoints then P14 - MP else Double.NaN;
M14.SetDefaultColor(globalColor("MP"));
M14.HideTitle();
M14.SetPaintingStrategy(PaintingStrategy.dashes);
M14.HideBubble();
plot P15 = if START > 0 then START - (6 * PLI)else Double.NaN;
P15.SetDefaultColor(globalColor("PLI"));
P15.HideTitle();
P15.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M15 = if showMidpoints then P15 - MP else Double.NaN;
M15.SetDefaultColor(globalColor("MP"));
M15.HideTitle();
M15.SetPaintingStrategy(PaintingStrategy.dashes);
M15.HideBubble();
plot P16 = if START > 0 then START - (7 * PLI)else Double.NaN;
P16.SetDefaultColor(globalColor("PLI"));
P16.HideTitle();
P16.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M16 = if showMidpoints then P16 - MP else Double.NaN;
M16.SetDefaultColor(globalColor("MP"));
M16.HideTitle();
M16.SetPaintingStrategy(PaintingStrategy.dashes);
M16.HideBubble();
plot P17 = if START > 0 then START - (8 * PLI)else Double.NaN;
P17.SetDefaultColor(globalColor("PLI"));
P17.HideTitle();
P17.SetPaintingStrategy(PaintingStrategy.horizontal);
This price level study is super useful when scalping.. but adjusting the settings is very tedious the way it is set up
Is there a way to combine the below code so that all the 'P' levels (plot start) can be adjusted together as well as the 'M' levels (midpoint)?
As it stands you have to go in and adjust each individual level, thanks for any help, cheers
Original Code
#Auto Price Levels
#@rlohmeyer shared on UseThinkscript
input gapStart = no;
input gaplevel = 00;
input PLI = 1.00;
input showMidpoints = yes;
DefineGlobalColor("PLI",color.white);
DefineGlobalColor("MP",color.light_gray);
def cl = close(period = AggregationPeriod.DAY);
def ST = Round(cl[1], 0);
def START = if gapstart == 0 then ST else if gapstart == 1 then gaplevel else Double.NaN;
def MP = PLI/2;
#Plot START
plot PLS = START;
PLS.SetDefaultColor(color.orange);
PLS.HideTitle();
PLS.SetPaintingStrategy(PaintingStrategy.horizontal);
#START Up
plot MUS = if showMidpoints then START + MP else Double.NaN;
MUS.SetDefaultColor(globalColor("MP"));
MUS.HideTitle();
MUS.SetPaintingStrategy(PaintingStrategy.dashes);
MUS.HideBubble();
plot P2 = if START > 0 then START + PLI else Double.NaN;
P2.SetDefaultColor(globalColor("PLI"));
P2.HideTitle();
P2.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M2 = if showMidpoints then P2 + MP else Double.NaN;
M2.SetDefaultColor(globalColor("MP"));
M2.HideTitle();
M2.SetPaintingStrategy(PaintingStrategy.dashes);
M2.HideBubble();
plot P3 = if START > 0 then START + (2 * PLI)else Double.NaN;
P3.SetDefaultColor(globalColor("PLI"));
P3.HideTitle();
P3.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M3 = if showMidpoints then P3 + MP else Double.NaN;
M3.SetDefaultColor(globalColor("MP"));
M3.HideTitle();
M3.SetPaintingStrategy(PaintingStrategy.dashes);
M3.HideBubble();
plot P4 = if START > 0 then START + (3 * PLI)else Double.NaN;
P4.SetDefaultColor(globalColor("PLI"));
P4.HideTitle();
P4.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M4 = if showMidpoints then P4 + MP else Double.NaN;
M4.SetDefaultColor(globalColor("MP"));
M4.HideTitle();
M4.SetPaintingStrategy(PaintingStrategy.dashes);
M4.HideBubble();
plot P5 = if START > 0 then START + (4 * PLI)else Double.NaN;
P5.SetDefaultColor(globalColor("PLI"));
P5.HideTitle();
P5.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M5 = if showMidpoints then P5 + MP else Double.NaN;
M5.SetDefaultColor(globalColor("MP"));
M5.HideTitle();
M5.SetPaintingStrategy(PaintingStrategy.dashes);
M5.HideBubble();
plot P6 = if START > 0 then START + (5 * PLI)else Double.NaN;
P6.SetDefaultColor(globalColor("PLI"));
P6.HideTitle();
P6.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M6 = if showMidpoints then P6 + MP else Double.NaN;
M6.SetDefaultColor(globalColor("MP"));
M6.HideTitle();
M6.SetPaintingStrategy(PaintingStrategy.dashes);
M6.HideBubble();
plot P7 = if START > 0 then START + (6 * PLI)else Double.NaN;
P7.SetDefaultColor(globalColor("PLI"));
P7.HideTitle();
P7.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M7 = if showMidpoints then P7 + MP else Double.NaN;
M7.SetDefaultColor(globalColor("MP"));
M7.HideTitle();
M7.SetPaintingStrategy(PaintingStrategy.dashes);
M7.HideBubble();
plot P8 = if START > 0 then START + (7 * PLI)else Double.NaN;
P8.SetDefaultColor(globalColor("PLI"));
P8.HideTitle();
P8.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M8 = if showMidpoints then P8 + MP else Double.NaN;
M8.SetDefaultColor(globalColor("MP"));
M8.HideTitle();
M8.SetPaintingStrategy(PaintingStrategy.dashes);
M8.HideBubble();
plot P9 = if START > 0 then START + (8 * PLI)else Double.NaN;
P9.SetDefaultColor(globalColor("PLI"));
P9.HideTitle();
P9.SetPaintingStrategy(PaintingStrategy.horizontal);
#STARTDown
plot MUD = if showMidpoints then START - MP else Double.NaN;
MUD.SetDefaultColor(globalColor("MP"));
MUD.HideTitle();
MUD.SetPaintingStrategy(PaintingStrategy.dashes);
MUD.HideBubble();
plot P10 = if START > 0 then START - PLI else Double.NaN;
P10.SetDefaultColor(globalColor("PLI"));
P10.HideTitle();
P10.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M10 = if showMidpoints then P10 - MP else Double.NaN;
M10.SetDefaultColor(globalColor("MP"));
M10.HideTitle();
M10.SetPaintingStrategy(PaintingStrategy.dashes);
M10.HideBubble();
plot P11 = if START > 0 then START - (2 * PLI) else Double.NaN;
P11.SetDefaultColor(globalColor("PLI"));
P11.HideTitle();
P11.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M11 = if showMidpoints then P11 - MP else Double.NaN;
M11.SetDefaultColor(globalColor("MP"));
M11.HideTitle();
M11.SetPaintingStrategy(PaintingStrategy.dashes);
M11.HideBubble();
plot P12 = if START > 0 then START - (3 * PLI)else Double.NaN;
P12.SetDefaultColor(globalColor("PLI"));
P12.HideTitle();
P12.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M12 = if showMidpoints then P12 - MP else Double.NaN;
M12.SetDefaultColor(globalColor("MP"));
M12.HideTitle();
M12.SetPaintingStrategy(PaintingStrategy.dashes);
M12.HideBubble();
plot P13 = if START > 0 then START - (4 * PLI)else Double.NaN;
P13.SetDefaultColor(globalColor("PLI"));
P13.HideTitle();
P13.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M13 = if showMidpoints then P13 - MP else Double.NaN;
M13.SetDefaultColor(globalColor("MP"));
M13.HideTitle();
M13.SetPaintingStrategy(PaintingStrategy.dashes);
M13.HideBubble();
plot P14 = if START > 0 then START - (5 * PLI)else Double.NaN;
P14.SetDefaultColor(globalColor("PLI"));
P14.HideTitle();
P14.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M14 = if showMidpoints then P14 - MP else Double.NaN;
M14.SetDefaultColor(globalColor("MP"));
M14.HideTitle();
M14.SetPaintingStrategy(PaintingStrategy.dashes);
M14.HideBubble();
plot P15 = if START > 0 then START - (6 * PLI)else Double.NaN;
P15.SetDefaultColor(globalColor("PLI"));
P15.HideTitle();
P15.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M15 = if showMidpoints then P15 - MP else Double.NaN;
M15.SetDefaultColor(globalColor("MP"));
M15.HideTitle();
M15.SetPaintingStrategy(PaintingStrategy.dashes);
M15.HideBubble();
plot P16 = if START > 0 then START - (7 * PLI)else Double.NaN;
P16.SetDefaultColor(globalColor("PLI"));
P16.HideTitle();
P16.SetPaintingStrategy(PaintingStrategy.horizontal);
plot M16 = if showMidpoints then P16 - MP else Double.NaN;
M16.SetDefaultColor(globalColor("MP"));
M16.HideTitle();
M16.SetPaintingStrategy(PaintingStrategy.dashes);
M16.HideBubble();
plot P17 = if START > 0 then START - (8 * PLI)else Double.NaN;
P17.SetDefaultColor(globalColor("PLI"));
P17.HideTitle();
P17.SetPaintingStrategy(PaintingStrategy.horizontal);
Last edited by a moderator: