Download MetaTrader 5
To add comments, please log in or register
Publish the program in the Market and sell it to millions of traders!
Paul
529
Paul 2014.12.09 14:25 

I want to be able to draw a series of lines, 30 pips apart, from the high of the day to the low.  The code below accomplishes this, but no matter where I put the code in my EA, some lines don't draw.  I think it's because of other objects being drawn.  If I keep compiling the code, I get different results, but same problem.  Some lines get skipped.  If I run the code in as a script or indicator, only the first line is drawn.  Can anyone tell me what I'm doing wrong?  Also, would like the lines to be dashed.

Thanks!

         int NXCnt;
         double NX;
         double vDH=iHigh(NULL,1440,0);       // Daily High
         double vDL=iLow(NULL,1440,0);        // Daily Low  
         
        NXCnt = NXCnt + 1;   
           
        double TX = ( 0.00030 * NXCnt );
        NX = (vDH - TX);
        
        //  Alert("NX =  ",DoubleToStr(NormalizeDouble(NX,5),5),"   vDH =  ",DoubleToStr(NormalizeDouble(vDH,5),5),"   vDL =  ",DoubleToStr(NormalizeDouble(vDL,5),5),"   NXCnt =  ",NXCnt);
        
        if( NX > vDL )
        {  
        //  ChartRedraw();
        ObjectCreate(StringConcatenate("T30",TimeCurrent()),OBJ_HLINE,0,TimeCurrent(),NX);
        ObjectSet(StringConcatenate("T30",TimeCurrent()), OBJPROP_COLOR, LightBlue);   
        
        }  
whroeder1
13602
whroeder1 2014.12.10 13:40  
Yellowbeard:  I want to be able to draw a series of lines, 30 pips apart some lines don't draw. Also, would like the lines to be dashed.
  1. double TX = ( 0.00030 * NXCnt );
    Then why are you are using a multiple of 3 pips (and assuming a non-JPY pair?) Compute what a pip is properly: TX = 30 * pips2dbl * NXCnt;
  2. int NXCnt;             // What is the value?
       :         
      NXCnt = NXCnt + 1;   // What is the value?
    
    You're putting your lines where?
  3. ObjectCreate(StringConcatenate("T30",TimeCurrent()
    Each time you run you're going to create different named lines in the same place. Since the lines are based off of 1,2,3... I suggest you call them "T30"+n that way you can just move them when the day changes.
  4. ObjectCreate(StringConcatenate("T30",...
    When you create the objects the first time, they won't ever move (create fails.) You need to check your return codes (What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles ) and move the lines (See my Tline)
  5. You might want to consider placing the lines at multiples of your 30 pips instead of the random high.
    double pips30 = 30 * pips2dbl;
    double vDH=iHigh(NULL,1440,0);         // Daily High = 1.23456
    vDH = MathCeil(vDH / pips30) * pips30; // vDH        = 1.23900
                                           // next         1.2360 ...
    
  6. If you want them dashed, set the style
Paul
529
Paul 2014.12.10 16:28  

Thanks WHRoeder,

  I had to make a few changes.  Here's the code that works.

          vDH=iHigh(NULL,1440,0);       // Daily High
          vDL=iLow(NULL,1440,0);        // Daily Low  
         
        NXCnt = NXCnt + 1;   
           
        double TX = ( 0.00050 * NXCnt );
        NX = (vDH - TX);
        
        //  Alert("NX =  ",DoubleToStr(NormalizeDouble(NX,5),5),"   vDH =  ",DoubleToStr(NormalizeDouble(vDH,5),5),"   vDL =  ",DoubleToStr(NormalizeDouble(vDL,5),5),"   NXCnt =  ",NXCnt);
        
        if( NX > vDL )
        {  
        
        ObjectCreate(StringConcatenate("T30",Time[NXCnt]),OBJ_HLINE,0,Time[NXCnt],NX);
        ObjectSet(StringConcatenate("T30",Time[NXCnt]), OBJPROP_STYLE,STYLE_DOT); 
        ObjectSet(StringConcatenate("T30",Time[NXCnt]), OBJPROP_COLOR, Gray);   
        
        }  
/
To add comments, please log in or register