Announcement

Collapse
No announcement yet.

More efsNewby questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • More efsNewby questions

    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=

    PHP Code:

    var dp0 true;
    var 
    flg Text.RELATIVETOLEFT|Text.RELATIVETOTOPText.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() {
            
    drawTextPixelxxyynButtonTitle +" @URL=EFS:catchme"forcolorbackcolorflg,"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(0high(), "ALERT"Color.bluenull,
            
    Text.BOLD|Text.BOTTOM|Text.FRAMEnull12);
            
        
        
    //}}EFSWizard_Action_1

        
    }
    //}}EFSWizard_Actions

        
    function catchmenButtonPressed ){
            if ( 
    getButtonPressednButtonPressed ) == ) {
            
            
    dp0 true;
            }
        }
        function 
    getButtonPressed(nButtonPressed) {
            if(
    nButtonPressed == BUTTON_LEFT){ 
            
    dp0 true;
            }   
        } 

  • #2
    Patch,

    Your getButton function is inside of the main function. It needs to be outside of main for it to work correctly.

    You are mostly correct in your efs execution sequence, but postMain isn't called until the efs is being removed from a chart or the chart is closing.

    main is called on every tick or every newbar if setComputeOnClose() has been used.

    You can use the drawing functions to draw thing on the chart. Look up drawShapeAbsolute, drawTextAbsolute, drawImageAbsolute, drawShapeRelative, and drawTextRelative functions in the knowledge base.

    Steve

    Comment


    • #3
      Thanks a lot for the help Steve, it is MUCH appreciated

      Comment


      • #4
        You're very welcome.

        That's what the forum is for, to help others.

        Steve

        Comment

        Working...
        X