Could someone help me with some newby efs questions which I can't find the answers to:
1. Am I correct in saying that an EFS executes in the following order
Declaring any variables before premain
premain()
main()
postmain()
and then restarts at the top of main() through postmain() and loops until it is ended.
2. I am getting a "getButtons is not defined" error message on the following efs. Could you explain why this is? I have not found anything in the literature about having to declare an object.
from the top to the bottom of the main section
3. How would I specify drawing an object in the top right hand corner of a chart so that it would stay there?
4. Is there any literature on coding and using buttons in efs? All I have found is http://kb.esignalcentral.com/display...id=1162&n=1&s=
1. Am I correct in saying that an EFS executes in the following order
Declaring any variables before premain
premain()
main()
postmain()
and then restarts at the top of main() through postmain() and loops until it is ended.
2. I am getting a "getButtons is not defined" error message on the following efs. Could you explain why this is? I have not found anything in the literature about having to declare an object.
from the top to the bottom of the main section
3. How would I specify drawing an object in the top right hand corner of a chart so that it would stay there?
4. Is there any literature on coding and using buttons in efs? All I have found is http://kb.esignalcentral.com/display...id=1162&n=1&s=
PHP Code:
var dp0 = true;
var flg = Text.RELATIVETOLEFT|Text.RELATIVETOTOP| Text.FRAME | Text.ONTOP;//required
var xx = 480;//required
var yy = 0;//required
var nButtonTitle = "Reset";//required
var backcolor = Color.red;//required
var forcolor = Color.white;//required
//}}EFSWizard_Declarations
function preMain() {
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
//{{EFSWizard_PreMain
setPriceStudy(true);
setStudyTitle("Positive COG");
setCursorLabelName("Armed?");
//}}Set variable to true. Will switch to false once the efs is executed
var dp0 = true;
}
function main() {
// For only the newest bar
var nState = getBarState();
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
if (nState == BARSTATE_CURRENTBAR) {
if (dp0 == true){
//{{EFSWizard_Expressions
//if the close price is 10c higher than the open send the alert
if (
close(0) > (open(0)+.1)
){
// change dp to stop the efs and put a button on the chart to restart the efs
dp0 = false;
// Call the alerts, play a sound and draw a flag
onAction1();
getButtons();
}
//}}EFSWizard_Expression_1
}
function getButtons() {
drawTextPixel( xx, yy, nButtonTitle +" @URL=EFS:catchme", forcolor, backcolor, flg,"Comic Sans MS", 20, -5);
}
}
//}}EFSWizard_Expressions
//{{EFSWizard_Return
return null;
//}}EFSWizard_Return
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
//{{EFSWizard_Actions
//{{EFSWizard_Action_1
function onAction1() {
Alert.playSound("C:\\Documents and Settings\\Patrick\\My Documents\\Sounds\\tone2.wav");
vLastAlert = 1;
drawTextRelative(0, high(), "ALERT", Color.blue, null,
Text.BOLD|Text.BOTTOM|Text.FRAME, null, 12);
//}}EFSWizard_Action_1
}
//}}EFSWizard_Actions
function catchme( nButtonPressed ){
if ( getButtonPressed( nButtonPressed ) == 1 ) {
dp0 = true;
}
}
function getButtonPressed(nButtonPressed) {
if(nButtonPressed == BUTTON_LEFT){
dp0 = true;
}
}
Comment