Announcement

Collapse
No announcement yet.

Lines not drawing in real time

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

  • Lines not drawing in real time

    The attached code works when loaded, but when run in real time the lines draw in the wrong places.
    Attached Files

  • #2
    Hello Mike2,

    The problem revolves around your logic for the "lineY" variable. The reason the lines draw where you want them on reload is because the bar indexes during the loading process do not change. When getCurrentBarIndex() is executed on a historical bar during the loading process it will return -###, or the current bar index relative to the 0 bar at the time of the reload. Once the formula starts processing in real time getCurrentBarIndex() is returning -1 (because of setComputeOnClose() in preMain). Every new bar that arrives after one of your lines are drawn is leaving "lineY" at the value of -1. You need to manually update this variable at BARSTATE_NEWBAR to reflect is new bar index. At the end of main() before your return statement, try adding the following logic which will look for BARSTATE_NEWBAR in real time.

    PHP Code:
    if (getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == -1) {
        
    lineY--;

    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
      Making money from this code ?.

      Thanks Jason, I think you've pointed me in the right direction, however the code still doesn't work. I have modified the code to work with Stochastics, it's very neat and can be quite predictive. If anyone makes money from this code, please let me know how you went about it. The code is good, but trying to pick which line is best is difficult. Send email to [email protected].

      I have tried making it work as a range indicator (quite successfully on occassions) and as a directional indicator (quite successfully at times). But consistency is the usual problem with most indicators. If you think you know a price is going to trend, it's very good at picking highs and lows. I mostly use it on the Euro.

      I have another version of the code which works with the offset of Moving Averages, it's also quite good (see attached).

      Warning: this code looks great in backtesting, but is tricky to use when live. Definately paper trade it first.
      PHP Code:
      //Mike's FREAK index, bizzare, but works a total treat

      //{{EFSWizard_Description
      //
      //    This formula was generated by the Alert Wizard
      //
      //}}EFSWizard_Description


      //{{EFSWizard_Declarations
      var vStoch14_1 = new StochStudy(1413);
      var 
      vStoch28_1 = new StochStudy(2813);
      var 
      vStoch7_1 = new StochStudy(713);
      var 
      vStoch56_1 = new StochStudy(5613);
      var 
      vLastAlert = -1;
      //}}EFSWizard_Declarations
      var barcount 0;
      var 
      lineX 0;
      var 
      lineY 0;
      var 
      lineX2 0;
      var 
      lineY2 0;
      var 
      FirstTick 0;
      var 
      noPrint true;
      var 
      NoBeep true;
      var 
      NoAlert true;


      var 
      NoShow true;
      function 
      preMain() {
          
      setComputeOnClose();
          
      setPriceStudy(true); // false if want to show array
          
      setStudyTitle("Line");
          
      setCursorLabelName("h1"0);
          
      setCursorLabelName("h2"1);
          
      setCursorLabelName("h3"2);
          
      setCursorLabelName("h4"3);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarStyle(PS_SOLID1);
          
      setDefaultBarStyle(PS_SOLID2);
          
      setDefaultBarStyle(PS_SOLID3);
          
      setDefaultBarFgColor(Color.red0);
          
      setDefaultBarFgColor(Color.darkgrey1);
          
      setDefaultBarFgColor(Color.navy2);
          
      setDefaultBarFgColor(Color.fuchsia3);
          
      setDefaultBarThickness(40);
          
      setDefaultBarThickness(41);
          
      setDefaultBarThickness(42);
          
      setDefaultBarThickness(43);
          
      setPlotType(PLOTTYPE_HISTOGRAM0);
          
      setPlotType(PLOTTYPE_HISTOGRAM1);
          
      setPlotType(PLOTTYPE_HISTOGRAM2);
          
      setPlotType(PLOTTYPE_HISTOGRAM3);


      }

      function 
      main() {
      barcount ++;
      if(
      FirstTick == 2) {
          
      FirstTick =3;
          
      noPrint false;
      }
      if (
      getCurrentBarIndex() > -&& FirstTick ==1FirstTick 2;
      if (
      getCurrentBarIndex() == -2FirstTick 1;


      //if (!noPrint){
      if (vStoch7_1.getValue(StochStudy.FAST, -1) < 7){
          if (
      lineX 0) {
              
      //removeLineTool( LineTool.SEGMENT, "segment1" ); 
              //addLineTool( LineTool.SEGMENT, lineY - barcount, lineX, 0, close(), 2, Color.blue, "segment1" ); 
              //addLineTool( LineTool.SEGMENT, - barcount + lineY , lineX, getCurrentBarIndex(), close(), 2, Color.blue, "segment1" ) // does same thing as following line
              
      addLineToolLineTool.SEGMENTlineY -lineXgetCurrentBarIndex() -getCurrentBarIndex() - lineY -1close(-1) + close(-1) - lineX2Color.blue"segment1" )
          
      //    addLineTool( LineTool.SEGMENT, lineY -1 , lineX, getCurrentBarIndex(), close() , 4, Color.blue, "segment2" )

              //drawTextRelative(0, +5, barcount, Color.green, null,Text.RELATIVETOTOP|Text.TOP|Text.CENTER|Text.FRAME, "Comic Sans MS", 8,  (barcount+"text"+1));
              //drawTextRelative(0, +5, getCurrentBarIndex(), Color.red, null,Text.RELATIVETOTOP|Text.TOP|Text.CENTER|Text.FRAME, "Comic Sans MS", 8,  (barcount+"text"+1));

              
      lineX open(-1);
              if (
      noPrintlineY getCurrentBarIndex(); //barcount;
              
      if(!NoBeepAlert.playSound("c:\\program files\\netmeeting\\blip.wav");
              if(!
      NoAlertAlert.addToList(getSymbol()+"  "+getInterval(),"Line "+close(),Color.blue,Color.blue); 
          }
          else {
              
      lineX open(-1);
              if (
      noPrintlineY barcount;
          }
      }
      if (
      vStoch7_1.getValue(StochStudy.FAST, -1) > 90){
          if (
      lineX 0) {
              
      //removeLineTool( LineTool.SEGMENT, "segment1" ); 
              //addLineTool( LineTool.SEGMENT, lineY - barcount, lineX, 0, close(), 2, Color.blue, "segment1" ); 
              //addLineTool( LineTool.SEGMENT, - barcount + lineY -1, lineX, getCurrentBarIndex()-1, close(), 2, Color.blue, "segment1" ) // does same thing as following line
              
      addLineToolLineTool.SEGMENTlineY2 -lineX2getCurrentBarIndex() -1  getCurrentBarIndex() - lineY2 -1close(-1) + close(-1) - lineX22Color.green"segment1" )
          
      //    addLineTool( LineTool.SEGMENT, lineY2 -1 , lineX2, getCurrentBarIndex(), close() , 4, Color.green, "segment2" )
              //drawTextRelative(0, +5, barcount, Color.green, null,Text.RELATIVETOTOP|Text.TOP|Text.CENTER|Text.FRAME, "Comic Sans MS", 8,  (barcount+"text"+1));
              //drawTextRelative(0, +5, getCurrentBarIndex(), Color.red, null,Text.RELATIVETOTOP|Text.TOP|Text.CENTER|Text.FRAME, "Comic Sans MS", 8,  (barcount+"text"+1));

              
      lineX2 open(-1);
              if (
      noPrintlineY2 getCurrentBarIndex(); //barcount;
          
      }
          else {
              
      lineX open(-1);
              if (
      noPrintlineY barcount;
          }
      }

      if (
      getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == -&& !noPrint) {
          
      lineY--;
      }
      //else lineY = barcount;
      var v100 100
      if (!NoShow){
          return new Array(
              
      vStoch56_1.getValue(StochStudy.FAST),
              
      vStoch28_1.getValue(StochStudy.FAST),
              
      vStoch14_1.getValue(StochStudy.FAST),
              
      vStoch7_1.getValue(StochStudy.FAST),
            
      v100
          
      );
      }

      Attached Files

      Comment


      • #4
        Hello Mike2,

        In the formula you attached to your post, you did not have the code solution I gave you in that version. If you add it, it should solve the problem.

        For your Stochastic code, you are using an additional variable, lineY2, that will also need to follow the same logic as lineY. There is a new problem with this formula introduced with your usage of the noPrint variable. First, you have changed the conditional statement I gave you and added ... && !noPrint . You need to remove that because your formula logic is currently setting noPrint to false once it reaches bar -1, which prevents the code solution from being executed in real time. Change the condition to look like below.

        PHP Code:
        if (getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == -1) {
            
        lineY--;
            
        lineY2--;

        Secondly, you have added the conditional statement, if (noPrint) ... before each line that updates the [/i]lineY[/i] and lineY2 variables. This is also preventing them from getting set to their starting index value of -1 in real time. Remove each instance of this conditional statement when updating these two variables. I'm not sure what you are trying to accomplish with the noPrint logic, but you need to re-evaluate that portion of your formula.
        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
          Jason, appreciate your help. The noprint routine is a standard routine I have in all my programs, because quite often I write an output to file and use it to trade with. I found it the only way to stop writing data before a tick is made in live trading, otherwise I was getting outputs before the first tick (using barstate, etc). I'm sure there's a more efficient way of doing this, but this worked for me.

          I still can't get the routine to work. I changed the code per your suggestions.

          Regards,

          Mike
          Attached Files
          Last edited by Mike2; 07-27-2005, 03:48 AM.

          Comment


          • #6
            Hi Mike2,

            There is still a if (noPrint) condition on line 80 that is preventing lineY from being updated. Remove that condition and try it again.
            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
              That seems to have fixed it. Thanks again.
              Last edited by Mike2; 07-27-2005, 11:38 PM.

              Comment

              Working...
              X