Announcement

Collapse
No announcement yet.

Can I add buttons to change variables?

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

  • Can I add buttons to change variables?

    I have written a script to alert me when buy and sell conditions are met. I use two primary variables for my alerts, 'Trigger' and 'Trade'. Each is asigned a value as the script runs and the conditions are met.

    Is there a way that I can add buttons to the chart to assign values to these variables manually.

    I would like to add a 'Long' and 'Short' button to the chart so that the variable is assigned manually when I click on the button.

    Thanks
    James

  • #2
    Hello James,

    Yes, you can add buttons to the chart that executes a user-defined function to change the value of your global 'Long' and 'Short' variables. Using the drawTextRelative() function, add to the end of the text parameter as a string @URL=EFS:yourFunctionName. Your function will simply set the desired value of the global variables when the text image or button is clicked.

    PHP Code:
    function yourFunctionName() {
        
    Long false;
        return;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Jason,

      Thanks for the help, but I am not able to add the @URL command to the Text parameter correctly.

      Do you have an example?

      Here is the drawText command that I am using to place the 'Long' text on the screen.

      drawTextPixel( 500, 13, 'Long ', Color.black, null, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.BUTTON, null, 12, 300);// display Long Button

      Thanks
      James

      Comment


      • #4
        Hello James,

        The third parameter of the drawText function, 'Long' , is the text parameter. Add the @URL string to the end of it like below.

        drawTextPixel( 500, 13, 'Long@URL=EFS:yourFunctionName ', Color.black, null, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.BUTTON, null, 12, 300);
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Still not working

          JasonK,

          Thanks for the help but I still cannot get the buttons to work.

          I tried it in my original script with no luck. I thought the problem may be that I had the computeOnClose set to true, so I wrote a stand alone script (which I have attached ).

          The theory is that a close on the wrong side of the 20EMA triggers and email alert.

          Can you take a look and see if you can figure out what I am doing wrong.

          Thanks
          James
          Attached Files

          Comment


          • #6
            Hello James,

            Thanks for posting your code. There are a few minor problems.

            1. The Trade variable needs to be declared as a global variable outside of any function.



            2. The text strings in your drawTextPixel calls need to have double quotes and not single quotes.

            "Long@URL=EFS:goLong"
            "Short@URL=EFS:goShort"
            "Flat@URL=EFS:goFlat"

            3. The three functions that the buttons call when clicked are currently inside your main() function. They need to be moved outside of main() as stand alone functions. All you need to do is move the last end brace (i.e. } ) to a line just above the goLong() function declaration.

            4. There is a possible logic problem depending on how you intended this formula to operate. Currently, Trade is initialized as "Flat," which prevents your two conditions from ever being triggered. The only way they will trigger is if you click on either of the Long or Short buttons first. Was that your intention?
            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment


            • #7
              Jason,

              I made the changes that you indicated in your post, but the script is still not working, or is at least not updating the 'Trade' variable on the chart.

              The logic of the script is correct. I want the Trade variable to remain Flat until I assign it another value with one of the buttons.

              I moved the functions outside of the main function. I had moved them inside the main function as a test.

              I am not sure what to try next. I am going to continue to experiment, but if you have any other ideas, please let me know.

              Thanks
              James
              Attached Files

              Comment


              • #8
                Jason,

                I found the problem. I was leaving a space inside the double quotes while trying to call the funciton.

                Its working now. Thanks for all the help.

                James

                Comment

                Working...
                X