Announcement

Collapse
No announcement yet.

Develope An EFS that has a " Color" as condition

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

  • Develope An EFS that has a " Color" as condition

    I wonder if I can use the color of a study as condition in a EFS.
    In some of my TS (or signals) I always wished to , but unfortunately Nor CQG nor Trade S. allow it.

    ( I.e. if the colour of TJTI is above or below (n) and yellow do not do it if above or below (n) but is blue or red do it)

    Thanks

    Cordially
    Last edited by fabrizio; 06-22-2003, 12:30 PM.
    Fabrizio L. Jorio Fili

  • #2
    Fabrizio
    The following code shows an example of how you can reference the colors of the JTI.
    In this case I am painting the bars in the corresponding JTI colors only if the JTI is less than -30 and the color of JTI is blue or red.
    Alex



    PHP Code:
    //var study = new GetJTIStudy(LengthBand1, LengthBand2, FastMode, TrendLength)

    var study = new GetJTIStudy(30, -30falseGetJTIStudy.SHORT);

    //FastMode can be true OR false
    //TrendLength can be .SHORT .MEDIUM .NORMAL .LONG

    var vLastAlert = -1;

    function 
    preMain() {

        
    setPriceStudy(true);//this study does not plot the indicator
        
    setStudyTitle("JTI paintbar");
        
    setColorPriceBars(true);
    }

    function 
    main() {

    var 
    vJTI=study.getValue(GetJTIStudy.JTI);//this returns the values
    var cJTI=study.getValue(GetJTIStudy.COLORS);//this returns the colors

    //color values are the following 0=noise, 1=low, 2=medium, 3 strong
     
            
    if (vJTI<-30&&cJTI==2)//IF JTI < -30 AND color = blue (medium)
            
    onAction1()//THEN perform this action (see command below)
     
            
    else if (vJTI<-30&&cJTI==3)//IF JTI ,-30 AND color=red (strong)
            
    onAction2()//THEN perform this action
            
            
    else if(1==1)//IF any other condition is true
            
    onAction3();//THEN perform this action
        
        
    return null;
    }

        function 
    onAction1() {
            
    setPriceBarColor(Color.blue);//paint bars blue
            
    vLastAlert 1;
        }
       
        function 
    onAction2() {
            
    setPriceBarColor(Color.red);//paint bars red
            
    vLastAlert 2;
        }
        
       function 
    onAction3() {
            
    setPriceBarColor(Color.black);//paint bars black
            
    vLastAlert 3;
        } 

    Comment


    • #3
      Alexis

      Thanks a lot!

      I will post here the PHP of the development of the TS ( maybe with a little help....)

      Thanks again

      Cordially
      Fabrizio L. Jorio Fili

      Comment


      • #4
        Re: ERROR LINE 52

        Originally posted by fabrizio
        Alexis

        I'v tried to complete with "long part" of the formula, but output formula windows give to me LINE 52: ReferenceError: vJTI is not defined. I believed was already defined in main. Should I repeat it below?

        PHP Code:

        //var study = new GetJTIStudy(LengthBand1, LengthBand2, FastMode, TrendLength)

        var study = new GetJTIStudy(30, -30falseGetJTIStudy.SHORT);

        //FastMode can be true OR false
        //TrendLength can be .SHORT .MEDIUM .NORMAL .LONG

        var vLastAlert = -1;

        function 
        preMain() {

            
        setPriceStudy(true);//this study does not plot the indicator
            
        setStudyTitle("JTI paintbar");
            
        setColorPriceBars(true);
        }

        function 
        main() {

        var 
        vJTI=study.getValue(GetJTIStudy.JTI);//this returns the values
        var cJTI=study.getValue(GetJTIStudy.COLORS);//this returns the colors

        //color values are the following 0=noise, 1=low, 2=medium, 3 strong
         
                
        if (vJTI<-30&&cJTI==2)//IF JTI < -30 AND color = blue (medium)
                
        onAction1()//THEN perform this action (see command below)
         
                
        else if (vJTI<-30&&cJTI==3)//IF JTI ,-30 AND color=red (strong)
                
        onAction2()//THEN perform this action
                
                
        else if(1==1)//IF any other condition is true
                
        onAction3();//THEN perform this action
            
            
        return null;
        }

            function 
        onAction1() {
                
        setPriceBarColor(Color.blue);//paint bars blue
                
        vLastAlert 1;
            }
           
            function 
        onAction2() {
                
        setPriceBarColor(Color.red);//paint bars red
                
        vLastAlert 2;
            }
            
           function 
        onAction3() {
                
        setPriceBarColor(Color.black);//paint bars black
                
        vLastAlert 3;
            }
        //color values are the following 0=noise, 1=low, 2=medium, 3=strong

               
        if (vJTI>30&&cJTI==2)//IF JTI > 30 AND color = BLUE (medium)
               
        onAction1()//THEN perform this action (see command below)
               
               
        else if (vJTI>30&&cJTI==3)//IF JTI, +30 AND color=red (strong)
               
        onAction2()//THEN perform this action
               
               
        else if(1==1)//IF any other conditions is true
               
        onAction3();//THEN perform this action
               
            
               
               
        function onAction1() {
                
        setPriceBarColor(Color.blue);//paint bars blue
                
        vLastAlert 1;
            }
           
            function 
        onAction2() {
                
        setPriceBarColor(Color.red);//paint bars red
                
        vLastAlert 2;
            }
            
           function 
        onAction3() {
                
        setPriceBarColor(Color.black);//paint bars black
                
        vLastAlert 3;
            } 
        Attached Files
        Fabrizio L. Jorio Fili

        Comment


        • #5
          Hello fabrizo,

          You have a large section of your formula repeated at the bottom starting at line 52. Remove the code from that line down and you're good to go.

          PHP Code:
          //var study = new GetJTIStudy(LengthBand1, LengthBand2, FastMode, TrendLength)

          var study = new GetJTIStudy(30, -30falseGetJTIStudy.SHORT);

          //FastMode can be true OR false
          //TrendLength can be .SHORT .MEDIUM .NORMAL .LONG

          var vLastAlert = -1;

          function 
          preMain() {

              
          setPriceStudy(true);//this study does not plot the indicator
              
          setStudyTitle("JTI paintbar");
              
          setColorPriceBars(true);
          }

          function 
          main() {

          var 
          vJTI=study.getValue(GetJTIStudy.JTI);//this returns the values
          var cJTI=study.getValue(GetJTIStudy.COLORS);//this returns the colors

          //color values are the following 0=noise, 1=low, 2=medium, 3 strong
           
                  
          if (vJTI<-30&&cJTI==2)//IF JTI < -30 AND color = blue (medium)
                  
          onAction1()//THEN perform this action (see command below)
           
                  
          else if (vJTI<-30&&cJTI==3)//IF JTI ,-30 AND color=red (strong)
                  
          onAction2()//THEN perform this action
                  
                  
          else if(1==1)//IF any other condition is true
                  
          onAction3();//THEN perform this action
              
              
          return null;
          }

          function 
          onAction1() {
              
          setPriceBarColor(Color.blue);//paint bars blue
              
          vLastAlert 1;
          }
             
          function 
          onAction2() {
              
          setPriceBarColor(Color.red);//paint bars red
              
          vLastAlert 2;
          }
              
          function 
          onAction3() {
              
          setPriceBarColor(Color.black);//paint bars black
              
          vLastAlert 3;

          Attached Files
          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


          • #6
            Jason

            Thank you!


            Cordially
            Fabrizio L. Jorio Fili

            Comment


            • #7
              Jason

              If I cancel from line 52 on , I cancel the whole conditions that should be set IF JTI is >30 and BLUE or RED so , in other words the LONG condition of the formula, being the first part the SHORT side.

              Can expalin me -even just by structure- how should I replicate the ABOVE part of the formula but in the other "direction" ( JTI>30 and BLUE or RED but not YELLOW)?
              Last edited by fabrizio; 06-27-2003, 12:12 PM.
              Fabrizio L. Jorio Fili

              Comment


              • #8
                Hello fabrizo,

                In your original formula, some of your code in main() plus the 3 onAction() functions inadvertently was copied and then pasted below onAction3(). If you look at your original formula, you'll see that you have duplicates of the 3 onAction() functions plus a duplicate section of the code from main(). Your formula really only has about 50 lines. Line 52 that was generating your error was the beginning of the duplicate code that was in main() above. That block of code starting at line 52 ended up outside the main() function. "vJTI" was not initialized in the global scope (outside main()) so that why you got the “not defined” error.
                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


                • #9
                  code,formulas

                  Hi,

                  I saw this chart, has formula color bar in background. I know how to do this in ravenquote. Can I do in 7.4?

                  Can you post a php example? I would be particularly interested in this color bar. RSI(4 )< 50 , RSI(4 )> 50.

                  chart with color bar background

                  TIA,

                  ~j

                  Comment


                  • #10
                    Yes J,

                    The EFS function that colors the background is setBarBgColor().

                    PHP Code:
                    function main() {
                        if (
                    getCurrentBarIndex() > -20 && getCurrentBarIndex() < -10) {
                            
                    setBarBgColor(Color.green);
                        }

                    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


                    • #11
                      Jason
                      I think Fabrizio was trying to add the uptrend JTI signals to my original formula that was only set up to highlight downtrend signals. That is why he added those extra lines of code.

                      Fabrizio
                      To do what you wanted it was sufficient to change Lines 24 and 27 respectively to the following

                      if (vJTI<-30&&cJTI==2||vJTI>30&&cJTI==2)

                      else if (vJTI<-30&&cJTI==3||vJTI>30&&cJTI==3)

                      Notice the || sign which means OR. So the condition in Line 27 for example would now read
                      "IF JTI (value) is less than -30 and JTI (color) is red OR JTI (value) is greater than 30 and JTI (color) is red THEN...

                      However this will paint both the uptrend and downtrend bars of similar strength in the same color which can be confusing if you are not plotting the indicator.
                      You may find it preferable to paint for example the uptrend bars in lime for MEDIUM and blue for STRONG and the downtrend bars in yellow for MEDIUM and red for STRONG.
                      The following code should do that.

                      PHP Code:
                      //var study = new GetJTIStudy(LengthBand1, LengthBand2, FastMode, TrendLength)

                      var study = new GetJTIStudy(30, -30falseGetJTIStudy.SHORT);

                      //FastMode can be true OR false
                      //TrendLength can be .SHORT .MEDIUM .NORMAL .LONG

                      var vLastAlert = -1;

                      function 
                      preMain() {

                          
                      setPriceStudy(true);//this study does not plot the indicator
                          
                      setStudyTitle("JTI paintbar");
                          
                      setColorPriceBars(true);
                      }

                      function 
                      main() {

                      var 
                      vJTI=study.getValue(GetJTIStudy.JTI);//this returns the values
                      var cJTI=study.getValue(GetJTIStudy.COLORS);//this returns the colors

                      //color values are the following 0=noise, 1=low, 2=medium, 3 strong
                       
                              
                      if (vJTI<-30&&cJTI==2)//IF JTI < -30 AND color = blue (medium)
                              
                      onAction1()//THEN perform this action (see command below)
                       
                              
                      else if (vJTI<-30&&cJTI==3)//IF JTI ,-30 AND color=red (strong)
                              
                      onAction2()//THEN perform this action
                              
                              
                      else if (vJTI>30&&cJTI==2)
                              
                      onAction3()
                              
                              else if (
                      vJTI>30&&cJTI==3)
                              
                      onAction4()
                              
                              else if(
                      1==1)//IF any other condition is true
                              
                      onAction5();//THEN perform this action
                          
                          
                      return null;
                      }

                          function 
                      onAction1() {
                              
                      setPriceBarColor(Color.yellow);//paint bars yellow
                              
                      vLastAlert 1;
                          }
                         
                          function 
                      onAction2() {
                              
                      setPriceBarColor(Color.red);//paint bars red
                              
                      vLastAlert 2;
                          }
                          
                         function 
                      onAction3() {
                              
                      setPriceBarColor(Color.lime);//paint bars lime
                              
                      vLastAlert 3;
                          } 
                          
                          function 
                      onAction4() {
                              
                      setPriceBarColor(Color.blue);//paint bars blue
                              
                      vLastAlert 4;
                          } 
                          
                          function 
                      onAction5() {
                              
                      setPriceBarColor(Color.black);//paint bars black
                              
                      vLastAlert 5;
                          } 
                      The result is shown in the chart below.
                      Hope this helps
                      Alex

                      Last edited by ACM; 06-28-2003, 03:48 AM.

                      Comment


                      • #12
                        Alex
                        I followed your instructions so I realized first a ( || ) version of your original formula just to get acquainted with the operator.
                        Then I carefully red your PHP and realized the new one with the (if else) and the new colors.

                        I made a correction for a mistype at line 24.

                        All works fine.

                        Now the eventual aim is to use THIS formula as a further condition for an already realized and thorough fully BT and real world operated TS of mine.

                        Question: May I "call" this study as a whole condition inside an efs? I believe yes but how?

                        Thanks a lot Alexis

                        Cordially
                        Attached Files
                        Last edited by fabrizio; 06-28-2003, 01:31 AM.
                        Fabrizio L. Jorio Fili

                        Comment

                        Working...
                        X