Announcement

Collapse
No announcement yet.

drawText

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

  • drawText

    Need a 2nd look. I'm trying to show buy and sell stops which are based on the previous bar. The first drawText "sell" is not drawing. Both arrows are being displayed and so is the 2nd drawText "buy". Need to understand why the first text is erased when the 2nd text is drawn and what the fix is.

    PHP Code:
    var nTick .25;

    function 
    preMain() {
        
    setPriceStudy(true);
    }

    function 
    main() {
        var 
    nState getBarState();
        if (
    nState == BARSTATE_NEWBAR && getCurrentBarIndex() == 0) {
            
    clearText();
            
    clearShape();
            
    nHi high(-1);
            
    nLo low(-1);
            
    nBuyStop nLo-nTick;
            
    nSellStop nHi+nTick;
            
            
    drawTextAbsolute(4high(-1) + nTicknSellStopColor.redColor.RGB(165,165,165), Text.ONTOPnull10), "sell";
            
    drawShapeAbsolute(3high(-1) + nTickShape.LEFTARROWnullColor.RGB(255,0,0), Shape.ONTOP"ss");
            
            
    drawTextAbsolute(4low(-1) - nTicknBuyStopColor.blueColor.RGB(165,165,165), Text.ONTOPnull10), "buy";
            
    drawShapeAbsolute(3low(-1) - nTickShape.LEFTARROWnullColor.RGB(0,0,255), Shape.ONTOP"bs");
        }    
        return;


  • #2
    DUH
    had the paren in the wrong place

    Comment


    • #3
      pj909
      FWIW, once you have corrected the errors you found, you do not need to use clearText() and clearShape() in the context of your script since you are recycling the same tagID for each type of graphic object. Because there can only be one graphic object per tagID [ie there can only be one left arrow called “ss”] at every new bar a new one will be drawn while the previously drawn one will be removed
      Alex


      Originally posted by pj909
      Need a 2nd look. I'm trying to show buy and sell stops which are based on the previous bar. The first drawText "sell" is not drawing. Both arrows are being displayed and so is the 2nd drawText "buy". Need to understand why the first text is erased when the 2nd text is drawn and what the fix is.

      PHP Code:
      var nTick .25;

      function 
      preMain() {
          
      setPriceStudy(true);
      }

      function 
      main() {
          var 
      nState getBarState();
          if (
      nState == BARSTATE_NEWBAR && getCurrentBarIndex() == 0) {
              
      clearText();
              
      clearShape();
              
      nHi high(-1);
              
      nLo low(-1);
              
      nBuyStop nLo-nTick;
              
      nSellStop nHi+nTick;
              
              
      drawTextAbsolute(4high(-1) + nTicknSellStopColor.redColor.RGB(165,165,165), Text.ONTOPnull10), "sell";
              
      drawShapeAbsolute(3high(-1) + nTickShape.LEFTARROWnullColor.RGB(255,0,0), Shape.ONTOP"ss");
              
              
      drawTextAbsolute(4low(-1) - nTicknBuyStopColor.blueColor.RGB(165,165,165), Text.ONTOPnull10), "buy";
              
      drawShapeAbsolute(3low(-1) - nTickShape.LEFTARROWnullColor.RGB(0,0,255), Shape.ONTOP"bs");
          }    
          return;

      Comment


      • #4
        Thanks Alex,

        I must have something else not quite right. If I eliminate the clear commands, all the draw objects are erased and redrawn EXCEPT the object with the "s1" tag. I'm using Tick Replay since I don't have streaming data (while testing on the weekend).


        Also, the drawLine for entry stop and exit are not working.

        PHP Code:
        debugClear();
        var 
        nTick .25;

        var 
        nBuyStop null;
        var 
        nSellStop null;
        var 
        vTrade "notrade";
        var 
        nLastnBidnAsk;

        function 
        preMain() {
            
        setPriceStudy(true);
        }

        function 
        main() {
        var 
        nState getBarState();
            if (
        nState == BARSTATE_ALLBARS){
                
        nBuyStop low().toFixed(2);
                
        nSellStop high().toFixed(2);
                }
            
            if (
        nState == BARSTATE_NEWBAR && getCurrentBarIndex() == 0) {
        //        clearText();
        //        clearShape();
                
        nHi high(-1);
                
        nLo low(-1);
                
        nBuyStop = (nLo-nTick).toFixed(2);
                
        nSellStop = (nHi+nTick).toFixed(2);

                
        drawTextAbsolute(4high(-1) + nTicknSellStopColor.redColor.RGB(165,165,165), Text.ONTOP Text.BOTTOMnull10"s1");
                
        drawShapeAbsolute(3high(-1) + nTickShape.LEFTARROWnullColor.RGB(255,0,0), Shape.ONTOP"ss");
                
                
        drawTextAbsolute(4low(-1) - nTicknBuyStopColor.blueColor.RGB(165,165,165), Text.ONTOP Text.TOPnull10), "b1";
                
        drawShapeAbsolute(3low(-1) - nTickShape.LEFTARROWnullColor.RGB(0,0,255), Shape.ONTOP"bs");
            }
            
        nLast getMostRecentTrade().toFixed(2);
            
        nAsk getMostRecentAsk().toFixed(2);
            
        nBid getMostRecentBid().toFixed(2);


        debugPrintln(getCurrentBarIndex() + "last= " nLast "  sell stop= " nSellStop "  buy stop =" nBuyStop " " vTrade );
            if (
        vTrade == "notrade"  && getCurrentBarIndex()==0) {

                if (
        nLast >= nSellStop) {
                    
        vTrade "short";
                    
        myEntry nBid;
                    
        myPT = (myEntry 2*nTick);
                    
        mySL = (myEntry 8*nTick);            
                    
        drawLineRelative( -1myEntry3myEntryPS_SOLID2Color.black"e1" );
                    
        drawLineRelative( -1myPT3myPTPS_SOLID2Color.lime"pt" );
                    
        drawLineRelative( -1mySL3mySLPS_SOLID2Color.red"sl" );

                } else if (
        nLast <= nBuyStop) {
                    
        vTrade "long";
                    
        myEntry nAsk;
                    
        myPT = (myEntry 2*nTick);
                    
        mySL = (myEntry 8*nTick);
                    
        drawLineRelative( -1myEntry3myEntryPS_SOLID2Color.black"e1" );
                    
        drawLineRelative( -1myPT3myPTPS_SOLID2Color.lime"pt" );
                    
        drawLineRelative( -1mySL3mySLPS_SOLID2Color.red"sl" );            
                }
              
            else {
            
        // is in a trade - check for exit  
                
        if (vTrade == "short" && nLast myPTdebugPrintln("Short Win at: " getCurrentBarIndex());
                if (
        vTrade == "short" && nLast mySSdebugPrintln("Short Loss at: " getCurrentBarIndex());
                if (
        vTrade == "long" && nLast myPTdebugPrintln("Long Win at: " getCurrentBarIndex());
                if (
        vTrade == "long" && nLast myPTdebugPrintln("Long Loss at: " getCurrentBarIndex());
                
        vTrade "notrade"
                
        }

            }

           return;

        Comment


        • #5
          pj909

          all the draw objects are erased and redrawn EXCEPT the object with the "s1" tag
          That is because the close parenthesis in the related line of code ie
          PHP Code:
          drawTextAbsolute(4low(-1) - nTicknBuyStopColor.blueColor.RGB(165,165,165), Text.ONTOP Text.TOPnull10), "b1"
          is in the wrong location. Additionally the command that draws the nBuyStop text also has this error
          FWIW these are the same errors you indicated you had already resolved
          Alex


          Originally posted by pj909
          Thanks Alex,

          I must have something else not quite right. If I eliminate the clear commands, all the draw objects are erased and redrawn EXCEPT the object with the "s1" tag. I'm using Tick Replay since I don't have streaming data (while testing on the weekend).


          Also, the drawLine for entry stop and exit are not working.

          PHP Code:
          debugClear();
          var 
          nTick .25;

          var 
          nBuyStop null;
          var 
          nSellStop null;
          var 
          vTrade "notrade";
          var 
          nLastnBidnAsk;

          function 
          preMain() {
              
          setPriceStudy(true);
          }

          function 
          main() {
          var 
          nState getBarState();
              if (
          nState == BARSTATE_ALLBARS){
                  
          nBuyStop low().toFixed(2);
                  
          nSellStop high().toFixed(2);
                  }
              
              if (
          nState == BARSTATE_NEWBAR && getCurrentBarIndex() == 0) {
          //        clearText();
          //        clearShape();
                  
          nHi high(-1);
                  
          nLo low(-1);
                  
          nBuyStop = (nLo-nTick).toFixed(2);
                  
          nSellStop = (nHi+nTick).toFixed(2);

                  
          drawTextAbsolute(4high(-1) + nTicknSellStopColor.redColor.RGB(165,165,165), Text.ONTOP Text.BOTTOMnull10"s1");
                  
          drawShapeAbsolute(3high(-1) + nTickShape.LEFTARROWnullColor.RGB(255,0,0), Shape.ONTOP"ss");
                  
                  
          drawTextAbsolute(4low(-1) - nTicknBuyStopColor.blueColor.RGB(165,165,165), Text.ONTOP Text.TOPnull10), "b1";
                  
          drawShapeAbsolute(3low(-1) - nTickShape.LEFTARROWnullColor.RGB(0,0,255), Shape.ONTOP"bs");
              }
              
          nLast getMostRecentTrade().toFixed(2);
              
          nAsk getMostRecentAsk().toFixed(2);
              
          nBid getMostRecentBid().toFixed(2);


          debugPrintln(getCurrentBarIndex() + "last= " nLast "  sell stop= " nSellStop "  buy stop =" nBuyStop " " vTrade );
              if (
          vTrade == "notrade"  && getCurrentBarIndex()==0) {

                  if (
          nLast >= nSellStop) {
                      
          vTrade "short";
                      
          myEntry nBid;
                      
          myPT = (myEntry 2*nTick);
                      
          mySL = (myEntry 8*nTick);            
                      
          drawLineRelative( -1myEntry3myEntryPS_SOLID2Color.black"e1" );
                      
          drawLineRelative( -1myPT3myPTPS_SOLID2Color.lime"pt" );
                      
          drawLineRelative( -1mySL3mySLPS_SOLID2Color.red"sl" );

                  } else if (
          nLast <= nBuyStop) {
                      
          vTrade "long";
                      
          myEntry nAsk;
                      
          myPT = (myEntry 2*nTick);
                      
          mySL = (myEntry 8*nTick);
                      
          drawLineRelative( -1myEntry3myEntryPS_SOLID2Color.black"e1" );
                      
          drawLineRelative( -1myPT3myPTPS_SOLID2Color.lime"pt" );
                      
          drawLineRelative( -1mySL3mySLPS_SOLID2Color.red"sl" );            
                  }
                
              else {
              
          // is in a trade - check for exit  
                  
          if (vTrade == "short" && nLast myPTdebugPrintln("Short Win at: " getCurrentBarIndex());
                  if (
          vTrade == "short" && nLast mySSdebugPrintln("Short Loss at: " getCurrentBarIndex());
                  if (
          vTrade == "long" && nLast myPTdebugPrintln("Long Win at: " getCurrentBarIndex());
                  if (
          vTrade == "long" && nLast myPTdebugPrintln("Long Loss at: " getCurrentBarIndex());
                  
          vTrade "notrade"
                  
          }

              }

             return;

          Comment


          • #6
            Originally posted by Alexis C. Montenegro
            pj909

            FWIW these are the same errors you indicated you had already resolved
            Alex
            Well you're quite right. I grabbed an earlier version and thought I had already fixed that problem. Must have been in zombieland at the time.

            Any ideas why my Entry, PT and SL lines are not being drawn. It appears as though nLast, nAsk, and nBid are not getting updated by getMostrecentxxx

            Comment


            • #7
              pj909
              With regards to the lines you will need to review the entire logic used to draw them.
              As it is now it first evaluates if the current bar is being processed and vTrade is equal to notrade in which case it then evaluates the conditions included in that conditional statement and draws the lines when one of them is met.
              However when that happens vTrade gets set to either short or long accordingly which means that all the conditions that check for the exits which are contained in the else statement are never evaluated since the latter is inside the primary condition that checks if vTrade is equal to notrade [which at this point it is not]
              Alex


              Originally posted by pj909
              Well you're quite right. I grabbed an earlier version and thought I had already fixed that problem. Must have been in zombieland at the time.

              Any ideas why my Entry, PT and SL lines are not being drawn. It appears as though nLast, nAsk, and nBid are not getting updated by getMostrecentxxx

              Comment

              Working...
              X