Announcement

Collapse
No announcement yet.

Stuck...AGAIN!! Please could someone help me???

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

  • #16
    The simplest way is to use a flag as in:
    PHP Code:
    var Flag=0//or false or whatever
    function main(){
        if(
    high (-1) > high (0) && Flag == 0){
            
    drawtext...
            
    Flag 1//now the conditional will no longer evaluate to true since Flag is a global variable and retains the newly assigned value
        
    }

    If instead you only want to drawtext... on the last instance that the original conditional was true so previous drawtext... objects are erased, don't use the Flag routine and have a unique tag ID for the drawtext.... This will force drawtext... object to be overwritten by the new instance of drawtext....
    Last edited by waynecd; 01-17-2013, 11:53 PM.

    Comment


    • #17
      hey waynecd...thanks again for all your help...but im afraid i may not have been very clear...(ill keep it simple)...my code says " if ( high (0) > high (-1) then save (0) to an array...next check the current high(0) and if its higher than the array value drawtext on that bar....and all that works great ..but i want it to stop evaluating each bar after the first qualified bar is met...as it stands it keeps evaluating and drawtexting every bar even after the first one is ID...also i need it to begin re-evaluating after a new value is passed to the array..does this make sense... can you make a suggestion? i tried your flag example but it keep drawtexting for some reason..i allso tried a while loop but that nearly crashed my computer (even with the ++ line)...can you help?...thanks again for everything...john
      Last edited by pleaman2; 01-18-2013, 09:41 PM.

      Comment


      • #18
        thanks again ...

        Hey wayne ...i was just re-reading the code you posted with the red and green horizontal line...what a great piece of code!!! thanks again!! john

        Comment


        • #19
          Hey wayne ...
          yw.

          How and where to add the flag and when to reset the flag is dependent on the logic of the conditionals.
          So if you post or PM a relevant snippet of the code I'll see what I can do.
          Last edited by waynecd; 01-19-2013, 12:14 AM.

          Comment


          • #20
            hey Wanye...Thanks for offering to help with my code but after studying the code you posted (with the horizontal lines) ive determined that it works soooo much better than mine !!!! Your clearly a much better programmer than myself.. (BRILLIANT piece of code ,btw!) Thanks again for ALL your help...All the best, John
            Last edited by pleaman2; 01-20-2013, 07:13 PM.

            Comment


            • #21
              Glad it worked.

              Comment


              • #22
                hey wayne...one question ..can you tell me how to code it where instead of the green line drawing from the high, draws one from the open AND one from the close ,of the same bar?...thank you in advance...john
                Last edited by pleaman2; 01-21-2013, 07:35 PM.

                Comment


                • #23
                  PHP Code:
                  //gives bar count for bars at specific times
                  //blue arrows mark the 3rd bar in the sequence of 3 higher high bars 
                  //red horizontal lines mark the open of the 3rd bar in the sequence of 3 higher high bars starting at that bar and ending on the bar that breaks below it.
                  //green horizontal lines mark the high of the bar that broke below the open of the 3rd bar in the sequence of 3 higher high bars starting at that bar and ending on the bar that broke above that high
                  //NOTE: horizontal lines are only drawn when a bar breaks below the open of the 3rd bar in the sequence of 3 higher high bars 
                  debugClear();
                  function 
                  preMain(){
                      
                  setPriceStudy(true);
                  }
                  var 
                  bInit false;
                  var 
                  grID 0;
                  var 
                  openTrigger,highTrigger,openTrigger2,closeTrigger2;
                  var 
                  TriggerBar 0;
                  var 
                  TriggerBar1 0;

                  function 
                  main( ){
                      var 
                  barCnt,barCnt1;
                      if(
                  getBarState()==BARSTATE_ALLBARS){ //resets variables upon loading more bars via scrolling chart back in time
                          
                  openTrigger null;
                          
                  highTrigger null;
                          
                  TriggerBar 0;
                          
                  TriggerBar1 0;
                          
                  openTrigger2 null;
                          
                  closeTrigger2 null;
                      }
                      if(!
                  bInit){
                          
                  setCursorLabelName("barCnt: "0); //used here only for debug purposes
                          
                  setCursorLabelName("openTrigger: "1); //used here only for debug purposes
                          
                  setCursorLabelName("barCnt1: "2); //used here only for debug purposes
                          
                  setCursorLabelName("highTrigger: "3); //used here only for debug purposes
                          
                  setCursorLabelName("openTrigger2: "4); //used here only for debug purposes
                          
                  setCursorLabelName("closeTrigger2: "5); //used here only for debug purposes
                          
                  bInit true;
                      }
                      if ( 
                  high(-1) > high(-2) && high(-2) > high(-3) ) { //you describe sequence of 3 higher highs yet your example conditional uses close instead of high which won't necessarily give you 3 consecutive higher highs
                          
                  openTrigger open(-1); // the open of the 3rd bar in the sequence of 3 higher high bars
                          
                  TriggerBar getCurrentBarCount() - 1//logs the bar count at the time the conditional is true
                          
                  drawShapeRelative(-1BelowBar3Shape.UPARROWnullColor.blueShape.PRESET"a"+gID());   //to mark the 3rd bar in the sequence of 3 higher high bars
                      
                  }
                      if(
                  openTrigger != nullbarCnt getCurrentBarCount() - TriggerBar//tracks the bar index # of the 3rd bar in the sequence of 3 higher high bars
                      
                  if(high(0) > openTrigger && low(0) < openTrigger){ //"instead of "low(0)" use "close(0)" for realtime only, for backtesting use "low(0) or Math.min(close(0),open(0))" if you only want to trigger based on the candle body
                          
                  highTrigger high(0); //logs the high of the bar that broke below the open of the 3rd bar in the sequence of 3 higher high bars
                          
                  openTrigger2 open(0); 
                          
                  closeTrigger2 close(0);
                          
                  TriggerBar1 getCurrentBarCount(); //logs the bar count at the time the conditional is true
                          
                  drawLineRelative( -barCntopenTrigger0openTriggerPS_SOLID2Color.red"x1"+gID());
                          
                  openTrigger null;
                      }
                      if(
                  highTrigger != nullbarCnt1 getCurrentBarCount() - TriggerBar1//tracks the bar index # of bar that broke below the open of the 3rd bar in the sequence of 3 higher high bars
                       
                  if(low(0) < highTrigger && high(0) > highTrigger){
                          
                  //drawLineRelative( -barCnt1, highTrigger, 0, highTrigger, PS_SOLID, 2, Color.green, "x2"+gID());
                          
                  drawLineRelative( -barCnt1openTrigger20openTrigger2PS_SOLID2Color.green"x3"+gID());
                          
                  drawLineRelative( -barCnt1closeTrigger20closeTrigger2PS_SOLID2Color.green"x4"+gID());
                          
                  highTrigger null;
                      }
                      return [
                  barCnt+"",openTrigger+"",barCnt1+"",highTrigger+"",openTrigger2+"",closeTrigger2+""]; //used here only for debug purposes
                  }
                  //== gID function assigns unique identifier to graphic/text routines
                  function gID() {
                      
                  grID ++;
                      return( 
                  grID );

                  Wayne
                  Last edited by waynecd; 01-22-2013, 03:32 AM.

                  Comment


                  • #24
                    Thanks again Wayne...U R the Bomb!!!!..regards, John

                    Comment


                    • #25
                      hello wayne...would you mind explaining to me where in the code you wrote does it tell the computer to stop the horizontal lines from drawing once theyve been crossed??? i need to adjust them to a different bar but cant figure out how you coded it to make the lines print forward on each new bar until there crossed...thank you and sorry to keep bugging you..i wouldnt ask if i hadnt exhausted all my other options....best regards, john

                      example...heres my current code... drawLineRelative(-1, close(-1), 3, close (-1), PS_SOLID, 2, Color.blue, "high_line");
                      How /what would i need to do to get it to continue drawing the straight line until price crosse it????

                      thank you again for all your help....
                      Last edited by pleaman2; 01-25-2013, 11:13 PM.

                      Comment


                      • #26
                        Hi John,

                        The draw functions only execute once for each new "openTrigger" or "highTrigger" when the conditional they are in evaluates to true because "openTrigger" and "highTrigger" in their respective conditionals are reset to null. So only on the first instance when the conditional is true will the lines be drawn using the 3rd parameter in drawLineRelative() to stop the line at the bar that met the respective conditional, that would be bar 0 at that time.

                        PHP Code:
                        drawLineRelative( -barCntopenTrigger0openTriggerPS_SOLID2Color.red"x1"+gID()); 
                        PHP Code:
                        drawLineRelative( -barCnt1openTrigger20openTrigger2PS_SOLID2Color.green"x3"+gID());
                        drawLineRelative( -barCnt1closeTrigger20closeTrigger2PS_SOLID2Color.green"x4"+gID()); 
                        In the code you posted above the line will only draw from bar -1 to 4 bars after "-1,0,1,2,3" when the conditional it's in evaluates to true.

                        "Any line object created with drawlineRelative will 'stick' to the location where it was originally anchored."
                        That is why using bar index of 0 as the 3rd parameter in drawLineRelative() works since the bar that caused the conditional to evaluate to true is bar 0 at that time and drawLineRelative now sticks to that bar.
                        A search for "drawLineRelative()" in the KB will provide more information.

                        Wayne
                        Last edited by waynecd; 01-26-2013, 02:43 AM.

                        Comment


                        • #27
                          hey wayne...thank you for your response....youve given me alot to go on ... really appreciate your help...best regards, john

                          Comment


                          • #28
                            /////////////////////////////////////////////////////////////////////////////////////
                            // MajorPeak.efs
                            // This script finds a high with 10 bars on each side with lower highs. It uses this
                            // high as a starting point for a line, with the end point being the current bar.
                            //
                            // Written by Steve Meyer © October 2007
                            // Use and/or modify this code freely. If you redistribute it please include this
                            // and/or any other comment blocks and a description of any changes you make.
                            /////////////////////////////////////////////////////////////////////////////////////

                            // define constants
                            //const BARSLOWER = 10; // look for 10 lower bars on each side of the high

                            // define global variables
                            var barCount; // holds the count of the total number of bars on the chart
                            var stopBar = null; // the bar to stop looking for a new major high
                            var lineCount=2; // used to allow more than one high pivot to be plotted.



                            function preMain()
                            {
                            setPriceStudy(true); // this draws on the price section of the chart
                            setComputeOnClose(); // only run main when a new bar comes in
                            setStudyTitle("higher high");

                            // define function parameters
                            FP0 = new FunctionParameter("BARSLOWER", FunctionParameter.NUMBER);
                            FP0.setName("Number of Lower bars on each side of pivot");
                            FP0.setLowerLimit(2);
                            FP0.setDefault(3);

                            FP1 = new FunctionParameter("HighsToDisplay", FunctionParameter.NUMBER);
                            FP1.setName( "Number of High Pivots to display" );
                            FP1.setLowerLimit( 1 );
                            FP1.setDefault( 2 );

                            FP2 = new FunctionParameter("LineThickness", FunctionParameter.NUMBER);
                            FP2.setName( "Line Thickness" );
                            FP2.setLowerLimit( 2 );
                            FP2.setDefault( 2 );

                            FP3 = new FunctionParameter("LineColor", FunctionParameter.COLOR);
                            FP3.setName( "Line Color");
                            FP3.setDefault(Color.blue);

                            } // end preMain



                            function main(BARSLOWER, HighsToDisplay, LineThickness, LineColor)
                            {

                            barCount = getOldestBarIndex(); // find out how many bars are on the chart
                            if(stopBar === null) // set the initial stopBar value
                            stopBar = barCount+BARSLOWER;

                            // at each new bar, the stop bar gets one bar farther back, so make that adjustment here
                            if(getBarState() == BARSTATE_NEWBAR)
                            stopBar--;

                            // scan thru all the bars from BARSLOWER bars back to the stopBar looking for a new high
                            for(i=-BARSLOWER; i>stopBar; i--)
                            if(CheckLower(i, BARSLOWER)) // we found a high with BARSLOWER lower bars on each side
                            {
                            stopBar = i+1; // adjust our stop bar to no longer look for highs past this one

                            // draw a line from the high now to 2000 bars in the future
                            drawLineRelative(i, high(i), 5, high(i), PS_SOLID, LineThickness, LineColor, lineCount--);

                            // draw a verticle line at the peak from price $0 to price $1000.00
                            // drawLineRelative(i, 0, i, 1000, PS_SOLID, LineThickness, Color.red, lineCount--);

                            // if we're allowing more than one high pivot to be shown, then adjust the counter that
                            // keeps track of how many lines are displayed. The counter counts down until it reaches
                            // zero and then resets to MAX_HIGHS_TO_DISPLAY*2. Since the counter is used as a tag in the
                            // drawLineRelative calls, this will result in old lines being erased and replaced by new ones
                            if(lineCount == 0)
                            lineCount = HighsToDisplay*5;

                            break; // out of for loop since we don't need to keep looking
                            } // end if

                            } // end main




                            ////////////////////////////////////////////////////////////////
                            // This function checks for BARSLOWER lower bars on each side
                            // of the barIndex bar.
                            //
                            // inputs: barIndex - the index of the bar to check
                            // Must be less than -BARSLOWER and BARSLOWER
                            // greater than oldest bar.
                            // BARSLOWER - how many bars on each side of the high
                            // that must be lower to mark a high pivot
                            //
                            // returns: true if BARSLOWER lower bars on each side,
                            // false otherwise
                            ////////////////////////////////////////////////////////////////
                            function CheckLower(barIndex, BARSLOWER)
                            {
                            // check for a valid barIndex value
                            if(barIndex > -BARSLOWER)
                            throw("CheckLower: barIndex must be less than -"+BARSLOWER+". Value passed was "+barIndex);

                            if(barIndex < (barCount + BARSLOWER))
                            throw("CheckLower: barIndex must be "+BARSLOWER+" greater than the total bar count. Bar count="+barCount+" Value passed was "+barIndex);

                            var i;
                            var TestHigh = high(barIndex); // the high we compare every other bar to
                            // check if the BARSLOWER bars following were all lower
                            for(i=barIndex+1; i<=barIndex+BARSLOWER; i++)
                            if(TestHigh < high(i)) // check for a higher high
                            return false;

                            // check if the BARSLOWER bars prior were all lower
                            for(i=barIndex-1; i>=barIndex-BARSLOWER; i--)
                            if(TestHigh < high(i))
                            return false;

                            // if we get here it means we found a high with BARSLOWER lower bars on each side
                            return true;
                            } // end of function CheckLower

                            Comment


                            • #29
                              Very Nice!

                              Wayne
                              Last edited by waynecd; 02-04-2013, 06:00 PM.

                              Comment


                              • #30
                                Super Cool Wayne!!! Thank You so very much for everything youve helped me with...I bought a book on javascript... read it, then re-read it but its just not that simple.... so your input really helped move things along...Thanks again, john

                                Comment

                                Working...
                                X