Announcement

Collapse
No announcement yet.

plot problems

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

  • plot problems

    Good Morning,

    I have a program running the macd in 3 differents intervals...
    5, 30 and 240...

    When it comes to plot the signal it only plots it where
    it is suppose on the 5 min chart.

    On the 30 min and 240 min it plots the signal a few candles
    after.

    could somebody please help me ?

    great day

    Jaime

  • #2
    Jaime
    You need to post your code for someone to be able to offer any assistance
    Alex

    Comment


    • #3
      plot problems 2

      Posts: 13
      Status: ONLINE

      Good Morning,

      I have a program running the macd in 3 differents intervals...
      5, 30 and 240...

      When it comes to plot the signal it only plots it where
      it is suppose on the 5 min chart.

      On the 30 min and 240 min it plots the signal a few candles
      after.

      could somebody please help me ?

      here is my code:

      Code:
      var bInit = false;
      var vAlert_240 = false;
      var vAlert_30 = false;
      var vAlert_5 = false;
      var vSignal_240_LastCandle = 0;
      var vValue_240_LastCandle = 0;
      var vSignal_240 = 0;
      var vValue_240 = 0;
      var vSignal_30_LastCandle = 0;
      var vValue_30_LastCandle = 0;
      var vSignal_30 = 0;
      var vValue_30 = 0;
      var vSignal_5_LastCandle = 0;
      var vValue_5_LastCandle = 0;
      var vSignal_5 = 0;
      var vValue_5 = 0;
      
      var vCruzadoEn240_Arriba = 0;
      var vCruzadoEn30_Arriba = 0;
      var vCruzadoEn5_Arriba = 0;
      var myTexto = "";
      
      var AlertCntr_240 = 0;
      var AlertCntr_30 = 0;
      var AlertCntr_5 = 0;
      function preMain() {
          setStudyTitle("MACD 240 - 30 - 5");
          setDefaultBarFgColor(Color.magenta, 0); // hist
          setDefaultBarFgColor(Color.red, 1); // signal
          //setDefaultBarFgColor(Color.blue, 2); // macd
          
          //setPlotType(PLOTTYPE_HISTOGRAM, 0);
          
          setCursorLabelName("Hist", 0);
          setCursorLabelName("Signal", 1);
          //setCursorLabelName("MACD", 2);
          
          //setDefaultBarThickness(1, 0);
      }
      
      
      
      function main() {
      
      var nState = getBarState();
      
        
      
         if ( bInit == false ) { 
             
            myStudyValue_240 = macd( 12, 26, 9 , inv(240));
            myStudySignal_240 = macdSignal( 12, 26, 9 , inv(240));
            myStudyValue_30 = macd( 12, 26, 9 , inv(30));
            myStudySignal_30 = macdSignal( 12, 26, 9 , inv(30));
            myStudyValue_5 = macd( 12, 26, 9 , inv(5));
            myStudySignal_5 = macdSignal( 12, 26, 9 , inv(5));
            bInit = true; 
      
         } 
      
         //retrieve the current values 
         
          
          
          //Arriba INTERVALO 5
          
          //Abajo INTERVALO 5
          
          
          
         
         
         
          if (nState == BARSTATE_NEWBAR) {
              if (vValue_240 != null)
                  vValue_240_LastCandle = vValue_240;
              if (vSignal_240 != null)
                  vSignal_240_LastCandle = vSignal_240;
              if (vValue_30 != null)
                  vValue_30_LastCandle = vValue_30;
              if (vSignal_30 != null)
                  vSignal_30_LastCandle = vSignal_30;
              if (vValue_5 != null)
                  vValue_5_LastCandle = vValue_5;
              if (vSignal_5 != null)
                  vSignal_5_LastCandle = vSignal_5;    
                  
              vAlert_240 = false;
              vAlert_30 = false;
              vAlert_5 = false;
              
          }
          
          vValue_240_LastCandle = vValue_240;
          vSignal_240_LastCandle = vSignal_240;
          vValue_30_LastCandle = vValue_30;
          vSignal_30_LastCandle = vSignal_30;
          vValue_5_LastCandle = vValue_5;
          vSignal_5_LastCandle = vSignal_5;
          
          vValue_240  = myStudyValue_240.getValue(0); 
          vSignal_240 = myStudySignal_240.getValue(0);  
          vValue_30  = myStudyValue_30.getValue(0); 
          vSignal_30 = myStudySignal_30.getValue(0); 
          vValue_5  = myStudyValue_5.getValue(0); 
          vSignal_5 = myStudySignal_5.getValue(0); 
          
          
          
          if (vAlert_240 == false) {
              if (vValue_240_LastCandle < vSignal_240_LastCandle && vValue_240 >= vSignal_240) {  // crossing up
                  vAlert_240 = true;
                  AlertCntr_240 += 1;
                  
                  
                  /*if (myTexto.length > 0) {
                    UltimaLetra = myTexto.substr(myTexto.length-1, 1);
                    
                    
                      if (UltimaLetra == "C") myTexto = myTexto + "A";
                  } else */myTexto = "A";
                  
                  if  (getInterval() == 240)
                  drawShapeRelative(0, vSignal_240, Shape.UPARROW, null, Color.red, Image.TOP | Image.ONTOP, "Alert" + AlertCntr_240);
                  vCruzadoEn240_Arriba = vCruzadoEn240_Arriba + 1;
                  
                   //drawTextRelative( 0, vSignal_240, myTexto, Color.red, null, Text.PRESET | Text.BOLD, null, 12 );
                  
              }
              if (vValue_240_LastCandle > vSignal_240_LastCandle && vValue_240 < vSignal_240) {  // crossing down
                  vAlert_240 = true;
                  AlertCntr_240 += 1;
                  if  (getInterval() == 240)
                  drawShapeRelative(0, vSignal_240, Shape.DOWNARROW, null, Color.black, Image.BOTTOM | Image.ONTOP, "Alert" + AlertCntr_240);
              }
          }else {
              if ((vValue_240_LastCandle < vSignal_240_LastCandle && vValue_240 < vSignal_240) || (vValue_240_LastCandle > vSignal_240_LastCandle && vValue_240 > vSignal_240)) {
                  vAlert_240 = false;
                  removeShape("Alert" + AlertCntr_240);
              }
          }
          
          
           /*Alert.addToList("vValue_240", vValue_240,  Color.red, Color.red);
          Alert.addToList("vValue_240_LastCande", vValue_240_LastCandle,  Color.blue, Color.blue);*/
          
          if (vAlert_30 == false) {
              if (vValue_30_LastCandle < vSignal_30_LastCandle && vValue_30 >= vSignal_30) {  // crossing up
                  vAlert_30 = true;
                  AlertCntr_30 += 1;
                  if  (getInterval() == 30)
                  drawShapeRelative(0, vSignal_30, Shape.UPARROW, null, Color.blue, Image.TOP | Image.ONTOP, "Alert" + AlertCntr_30);
                  //drawTextRelative( 0, vSignal_240, UltimaLetra + "-" + myTexto, Color.red, null, Text.PRESET | Text.BOLD, null, 12 );
                  if (myTexto.length > 0) {
                    UltimaLetra = myTexto.substr(myTexto.length-1, 1);
                    
                    
                      if (UltimaLetra == "A") myTexto = myTexto + "B";
                  }
              }
              if (vValue_30_LastCandle > vSignal_30_LastCandle && vValue_30 <= vSignal_30) {  // crossing down
                  vAlert_30 = true;
                  AlertCntr_30 += 1;
                  if  (getInterval() == 30)
                  drawShapeRelative(0, vSignal_30, Shape.DOWNARROW, null, Color.black, Image.BOTTOM | Image.ONTOP, "Alert" + AlertCntr_30);
              }
          } else {
              if ((vValue_30_LastCandle < vSignal_30_LastCandle && vValue_30 < vSignal_30) || (vValue_30_LastCandle > vSignal_30_LastCandle && vValue_30 > vSignal_30)) {
                  vAlert_30 = false;
                  removeShape("Alert" + AlertCntr_30);
              }
          }
          
          
          
          
          if (vAlert_5 == false) {
              if (vValue_5_LastCandle < vSignal_5_LastCandle && vValue_5 >= vSignal_5) {  // crossing up
                  vAlert_5 = true;
                  AlertCntr_5 += 1;
                  if (myTexto.length > 1) {
                    UltimaLetra = myTexto.substr(myTexto.length-1, 1);
                    
                    
                      if (UltimaLetra == "B") {
                          myTexto = myTexto + "C";
                          if  (getInterval() == 5) drawTextRelative( 0, vSignal_5, myTexto, Color.red, null, Text.PRESET | Text.BOLD, null, 12 );
                          if  (getInterval() == 30) drawTextRelative( 0, vSignal_30, myTexto, Color.red, null, Text.PRESET | Text.BOLD, null, 12 );
                          if  (getInterval() == 240) drawTextRelative( 0, vSignal_240, myTexto, Color.red, null, Text.PRESET | Text.BOLD, null, 12 );
                         // drawShapeRelative(
                          
                          myTexto = "";
                      }
                  }
                  if  (getInterval() == 5)
                      drawShapeRelative(0, vSignal_5, Shape.UPARROW, null, Color.green, Image.TOP | Image.ONTOP, "Alert" + AlertCntr_5);
              }
              if (vValue_5_LastCandle > vSignal_5_LastCandle && vValue_5 <= vSignal_5) {  // crossing down
                  vAlert_5 = true;
                  AlertCntr_5 += 1;
                  //drawShapeRelative(0, vSignal_5, Shape.DOWNARROW, null, Color.black, Image.BOTTOM | Image.ONTOP, "Alert" + AlertCntr_5);
              }
          } else {
              if ((vValue_5_LastCandle < vSignal_5_LastCandle && vValue_5 < vSignal_5) || (vValue_5_LastCandle > vSignal_5_LastCandle && vValue_5 > vSignal_5)) {
                  vAlert_5 = false;
                  removeShape("Alert" + AlertCntr_5);
              }
          }
          
          if  (getInterval() == 240) return new Array(/*vValue_240, vSignal_240, */vValue_30, vSignal_30);
          if  (getInterval() == 30)  return new Array(vValue_30, vSignal_30);
          if  (getInterval() == 5) return new Array(vValue_5, vSignal_5); 
            
             //return new Array(vValue_240, vSignal_240, vValue_30, vSignal_30, vValue_5, vSignal_5);
          /*if (getInterval() == 240) 
             return new Array(vValue_240, vSignal_240);*/
          //if (getInterval()  == 10)
            // return new Array(vUpper_10, vMiddle_10, vLower_10, vUpper2_10/*, vMiddle2*/, vLower2_10);
      }
      function postMain() {
         /**
          *  The postMain() function is called only once, when the EFS is no longer used for
          *  the current symbol (ie, symbol change, chart closing, or application shutdown).
          */
      }

      Comment

      Working...
      X