Announcement

Collapse
No announcement yet.

Vertical Line Turned On and Off with Symbol change

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

  • Vertical Line Turned On and Off with Symbol change

    What's wrong with this code?

    I have a switch if turn on it will draw a vertical line and if the Symbol is changed the switch is turn Off and the line is deleted.

    Thank you very much

    ketma


    var vMA1 = null;
    var sSymbol1 = null;
    var sSymbol2 = null;

    function preMain() {

    setPriceStudy(true);
    setStudyTitle("10MA");
    setCursorLabelName("10MA", 0);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarThickness(2, 0);
    setPlotType(PLOTTYPE_LINE, 0);

    var fp1 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(10); //Edit this value to set a new default

    var fp2 = new FunctionParameter("MA1Offset", FunctionParameter.NUMBER);
    fp2.setDefault(0); //Edit this value to set a new default

    var fp3 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
    fp3.setName("MA1Source");
    fp3.addOption("Close");
    fp3.addOption("High");
    fp3.addOption("Low");
    fp3.addOption("Open");
    fp3.addOption("HL/2");
    fp3.addOption("HLC/3");
    fp3.addOption("OHLC/4");
    fp3.setDefault("Close"); //Edit this value to set a new default

    var fp4 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
    fp4.setName("MA1Type");
    fp4.addOption("MAStudy.SIMPLE");
    fp4.addOption("MAStudy.EXPONENTIAL");
    fp4.addOption("MAStudy.WEIGHTED");
    fp4.addOption("MAStudy.VOLUMEWEIGHTED");
    fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default

    var fp5 = new FunctionParameter("Vert", FunctionParameter.NUMBER);
    fp5.setDefault(0); //Edit this value to set a new default
    }

    function main(MA1Length,MA1Offset,MA1Source,MA1Type,Vert) {


    if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Offset, MA1Source, eval(MA1Type));

    if (Vert == 1) {
    if (sSymbol2 == null){
    sSymbol2 = getSymbol();
    }
    sSymbol1 = getSymbol();
    if (sSymbol1 == sSymbol2) {
    drawLineRelative(-1, -100, -1, 100, PS_SOLID, 2, Color.grey, 0 );
    } else {
    Vert = 0;
    removeLine( 0 );
    }
    }

    return (vMA1.getValue(MAStudy.MA));

    }

  • #2
    ketoma
    When I change symbols the line does not get deleted
    What exactly are you trying to accomplish?
    Alex

    Comment


    • #3
      Thank you very much Alexis for the quick respond.

      I'm trying to turn OFF the switch when I change Symbol

      to erase the line when I change Symbol

      For Vert to go back to 0 until I switch it ON again
      Last edited by ketoma21; 01-27-2005, 06:36 PM.

      Comment


      • #4
        ketoma
        Here is one solution to what you are trying to accomplish.
        You set the line by clicking the yellow button in the bottom left corner of the chart. Any time you change symbol, interval or reload the efs the line is cancelled
        Hope this helps
        Alex

        PHP Code:
        var vMA1 null;

        function 
        preMain() {

            
        setPriceStudy(true);
            
        setStudyTitle("10MA");
            
        setCursorLabelName("10MA"0);
            
        setDefaultBarStyle(PS_SOLID0);
            
        setDefaultBarThickness(20);
            
        setPlotType(PLOTTYPE_LINE0);

            var 
        fp1 = new FunctionParameter("MA1Length"FunctionParameter.NUMBER);
            
        fp1.setLowerLimit(1); 
            
        fp1.setDefault(10); //Edit this value to set a new default

            
        var fp2 = new FunctionParameter("MA1Offset"FunctionParameter.NUMBER);
            
        fp2.setDefault(0); //Edit this value to set a new default

            
        var fp3 = new FunctionParameter("MA1Source"FunctionParameter.STRING);
            
        fp3.setName("MA1Source");
            
        fp3.addOption("Close");
            
        fp3.addOption("High");
            
        fp3.addOption("Low");
            
        fp3.addOption("Open");
            
        fp3.addOption("HL/2");
            
        fp3.addOption("HLC/3");
            
        fp3.addOption("OHLC/4");
            
        fp3.setDefault("Close"); //Edit this value to set a new default 

            
        var fp4 = new FunctionParameter("MA1Type"FunctionParameter.STRING);
            
        fp4.setName("MA1Type");
            
        fp4.addOption("MAStudy.SIMPLE");
            
        fp4.addOption("MAStudy.EXPONENTIAL");
            
        fp4.addOption("MAStudy.WEIGHTED");
            
        fp4.addOption("MAStudy.VOLUMEWEIGHTED");
            
        fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
        }

        function 
        main(MA1Length,MA1Offset,MA1Source,MA1Type) {

            if(
        getBarState()==BARSTATE_ALLBARS){
                
        setGlobalValue("line",0);
            }

            if (
        vMA1 == nullvMA1 = new MAStudy(MA1LengthMA1OffsetMA1Source, eval(MA1Type));

            
        drawTextRelative(2,20," LINE "+"@URL=EFS:AddLine",Color.black,Color.yellow,
                             
        Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.BOLD|Text.FRAME,"Arial",11,"Text");

            if(
        getGlobalValue("line")==1){
                
        drawLineRelative(-1, -99999, -199999PS_SOLID2Color.grey);
            }
            
            return (
        vMA1.getValue(MAStudy.MA));
        }

        function 
        AddLine(){
            
        setGlobalValue("line",1);
            
        main()

        Comment


        • #5
          Thank you very Much Alex this is better then what I wanted

          You are just tooooo good

          you are a life saver

          Thank you again

          Ketoma

          Comment


          • #6
            Ketoma
            You are most welcome and thank you for the compliment
            Alex

            Comment

            Working...
            X