Hi!
I am using this study which places buttons on my charts that allow me to change the variable "Shares". When clicked, the speed with which the variable is changed seems adequate. However, the second part of the script, which toggles the buttons so that it is easy to tell at a glance which one is active, is very sluggish. I am hoping that someone might have some coding recommendations that would make this script more efficient.
Thank you, Charley
I am using this study which places buttons on my charts that allow me to change the variable "Shares". When clicked, the speed with which the variable is changed seems adequate. However, the second part of the script, which toggles the buttons so that it is easy to tell at a glance which one is active, is very sluggish. I am hoping that someone might have some coding recommendations that would make this script more efficient.
Thank you, Charley
PHP Code:
var fpArray = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("Shares Buttons");
setShowCursorLabel(false);
setShowTitleParameters(false);
var x=0;
fpArray[x] = new FunctionParameter("sFont", FunctionParameter.STRING);
with(fpArray[x++]){
setName("Font");
setDefault("Arial Black");
}
fpArray[x] = new FunctionParameter("nFontSize", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Font Size")
setLowerLimit(6);
setDefault(9);
}
fpArray[x] = new FunctionParameter("cBGColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("BG Color");
setDefault(Color.RGB(22,65,110));
}
fpArray[x] = new FunctionParameter("cFontColor", FunctionParameter.COLOR);
with(fpArray[x++]){
setName("Font Color");
setDefault(Color.RGB(150,150,150));
}
}
function main(sFont, nFontSize, cBGColor, cFontColor) {
Find_SharesButtons(sFont, nFontSize, cBGColor, cFontColor);
return;
}
var Shares = 5;
var nID = getCurrentBarCount();
function Shares5(nButtonPressed) {
if (Shares != 1) {
Shares = 5; } }
function Shares10(nButtonPressed) {
if (Shares != 2) {
Shares = 10; } }
function Shares25(nButtonPressed) {
if (Shares != 3) {
Shares = 25; } }
function Shares50(nButtonPressed) {
if (Shares != 4) {
Shares = 50; } }
function Shares100(nButtonPressed) {
if (Shares != 5) {
Shares = 100; } }
function Shares200(nButtonPressed) {
if (Shares != 6) {
Shares = 200; } }
function Shares300(nButtonPressed) {
if (Shares != 7) {
Shares = 300; } }
function Shares500(nButtonPressed) {
if (Shares != 8) {
Shares = 500; } }
function Shares1000(nButtonPressed) {
if (Shares != 9) {
Shares = 1000; } }
function Find_SharesButtons(sFont, nFontSize, cBGColor, cFontColor) {
SharesButton1();
SharesButton2();
SharesButton3();
SharesButton4();
SharesButton5();
SharesButton6();
SharesButton7();
SharesButton8();
SharesButton9();
if (Shares == 5) {
drawTextPixel(120, 2, "5" + "@URL=EFS:Shares5", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB1 + nID", 48, 17);
drawTextPixel(176, 2, "10" + "@URL=EFS:Shares10", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB2 + nID", 48, 17);
drawTextPixel(232, 2, "25" + "@URL=EFS:Shares25", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB3 + nID", 48, 17);
drawTextPixel(288, 2, "50" + "@URL=EFS:Shares50", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB4 + nID", 48, 17);
drawTextPixel(344, 2, "100" + "@URL=EFS:Shares100", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB5 + nID", 48, 17);
drawTextPixel(400, 2, "200" + "@URL=EFS:Shares200", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB6 + nID", 48, 17);
drawTextPixel(456, 2, "300" + "@URL=EFS:Shares300", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB7 + nID", 48, 17);
drawTextPixel(512, 2, "500" + "@URL=EFS:Shares500", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB8 + nID", 48, 17);
drawTextPixel(568, 2, "1000" + "@URL=EFS:Shares1000", cFontColor, cBGColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER, sFont, nFontSize, "SB9 + nID", 48, 17);
}
function SharesButton1() {
if (Shares == 5) {
drawTextPixel(120, 2, "5", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
function SharesButton2() {
if (Shares == 10) {
drawTextPixel(176, 2, "10", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
function SharesButton3() {
if (Shares == 25) {
drawTextPixel(232, 2, "25", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
function SharesButton4() {
if (Shares == 50) {
drawTextPixel(288, 2, "50", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
function SharesButton5() {
if (Shares == 100) {
drawTextPixel(344, 2, "100", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
function SharesButton6() {
if (Shares == 200) {
drawTextPixel(400, 2, "200", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
function SharesButton7() {
if (Shares == 300) {
drawTextPixel(456, 2, "300", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
function SharesButton8() {
if (Shares == 500) {
drawTextPixel(512, 2, "500", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
function SharesButton9() {
if (Shares == 1000) {
drawTextPixel(568, 2, "1000", cBGColor, cFontColor, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.CENTER | Text.ONTOP, sFont, 12, "Active", 48, 24);
}
}
}
function getButtonPressed(nButtonPressed) {
if (nButtonPressed == BUTTON_LEFT) {
return(1);
}
else {
return(0);
}
return;
}
Comment