Indicator Miscellaneous Questions - page 2

 

#Object Order

 

I created 3 Objects and that objects crossover each others.

#1 Horizontal Line, #2 Vertical Line, #3 Trendline

I need to set them z positions.

 

So how can I give them z positions value? 

Thanks. 

 
Marco vd Heijden:

Well you can draw all lines in OnInit() and then draw new whenever the opentime from the last bar changes you will know there was a new bar.

But i am not sure what exactly you are wanting to do.

OK! I will try something. Then I will come back to here.

Thanks.

 

@Marco vd Heijden

Before I start research about that. I really need to ask, is start() function slows down chart (/ MT4 Platforms)?

p.s I put all codes in start() special function, that code's works for Period Lines - H1, H4, D1, W1, MN1.

Have a nice weekend & thanks in advance.

 
Max Enrik: I really need to ask, is start() function slows down chart (/ MT4 Platforms)?
While all indicators are updating, the terminal does nothing else. That is why indicators can not sleep, can not trade, or do web requests.
 
whroeder1:
While all indicators are updating, the terminal does nothing else. That is why indicators can not sleep, can not trade, or do web requests.

Thank you for your comment. (after your comment I decided I will change something all in my indicators - because almost I made all my indicators in start() function.)

I put below code in start() function, so can you help me which way is good for my indicator?

Actually I have not any idea how can I edit below code for stop continuously updating (without all start() codes put in init() function).

//---MN1
int _cnt_MN1 = 11; // 12 lines for a year 24 for two years and etc.
for ( int i_MN = 0; i_MN < _cnt_MN1; i_MN++ )
{
    if ( _Period < PERIOD_MN1 )
    {
        //---time convert
        datetime _tltpMN1      = TimeToString( iTime( Symbol(), PERIOD_MN1, i_MN ), TIME_DATE );
        datetime _time         = iTime( Symbol(), PERIOD_MN1, i_MN );// + PeriodSeconds( PERIOD_MN1  );
        //---name
        string _vlineName_MN = "PERIOD_MN1- " + IntegerToString( i_MN );

        ObjectCreate     ( 0, _vlineName_MN, OBJ_VLINE          , 0, _time, 0     );
        ObjectSetString  ( 0, _vlineName_MN, OBJPROP_TOOLTIP    , _tltpMN1        );
        ObjectSetInteger ( 0, _vlineName_MN, OBJPROP_COLOR      , C'180,160,080'  );
        ObjectSet        (    _vlineName_MN, OBJPROP_BACK       , true            );
        ObjectSet        (    _vlineName_MN, OBJPROP_HIDDEN     , true            );
        ObjectSet        (    _vlineName_MN, OBJPROP_SELECTABLE , false           );
        ObjectSet        (    _vlineName_MN, OBJPROP_STYLE      , STYLE_SOLID     );
    }   //---if Close
}   //---for Close

Thanks!

 

I really need help, please someone answer my question.

Thanks. 

 
Max Enrik: Actually I have not any idea how can I edit below code for stop continuously updating
  1. Adapt new bar code for new month.
    Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
    void OnTick(){
       static datetime BOMcur=0;                dateTime BOMpre     = BOMcur;  
       BOMcur = iTime( _Symbol, PERIOD_MN1, 0); bool     isNewMonth = BOMcur != BOMpre;
       if(isNewMonth){
          DO_UPDATE(); ...
       }

  2. for ( int i_MN = 0; i_MN < _cnt_MN1; i_MN++ ){ ...
       string _vlineName_MN = "PERIOD_MN1- " + IntegerToString( i_MN );
    Do not use shift numbers in object names. Once a new bar starts, all your objects are misnamed and you can't create a new "<prefix>0." You had it right in your original post (using time)
    string   _vlineName_MN1 = _prefix + "PERIOD_MN1 - " + TimeToStr( _timeCvrt_MN1, TIME_DATE )    ;
    Or convert the time to a int to a string.
 

Please put it in an expert in stead of indicator this allows easier use in the future when you want to add your trading strategy.

For the bars issue, store the bar opening time in a datetime variable and simply compare the recorded time with the real time then whenever a new bar arises it will trigger.

Here is an example:

datetime M1,M5,M15,M30,H1,H4,D1,W1,MN1;
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetMillisecondTimer(250);

//--- create some things

   CreateLines(); // Function that creates time lines

//--- load open times
   M1=iTime(Symbol(),PERIOD_M1,0);
   M5=iTime(Symbol(),PERIOD_M5,0);
   M15=iTime(Symbol(),PERIOD_M15,0);
   M30=iTime(Symbol(),PERIOD_M30,0);
   H1=iTime(Symbol(),PERIOD_H1,0);
   H4=iTime(Symbol(),PERIOD_H4,0);
   D1=iTime(Symbol(),PERIOD_D1,0);
   W1=iTime(Symbol(),PERIOD_W1,0);
   MN1=iTime(Symbol(),PERIOD_MN1,0);


//--- set timelines
   ObjectMove(0,"Time-M1",0,M1,0);
   ObjectMove(0,"Time-M5",0,M5,0);
   ObjectMove(0,"Time-M15",0,M15,0);
   ObjectMove(0,"Time-M30",0,M30,0);
   ObjectMove(0,"Time-H1",0,H1,0);
   ObjectMove(0,"Time-H4",0,H4,0);
   ObjectMove(0,"Time-D1",0,D1,0);
   ObjectMove(0,"Time-W1",0,W1,0);
   ObjectMove(0,"Time-MN1",0,MN1,0);



//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   if(M1!=iTime(Symbol(),PERIOD_M1,0))
     {
      M1=iTime(Symbol(),PERIOD_M1,0);  // overwrite old value with new value  
      //Alert("New Bar on M1! ",TimeToString(M1,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-M1",0,M1,0);
     }

   if(M5!=iTime(Symbol(),PERIOD_M5,0))
     {
      M5=iTime(Symbol(),PERIOD_M5,0);
      //Alert("New Bar on M5! ",TimeToString(M5,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-M5",0,M5,0);
     }

   if(M15!=iTime(Symbol(),PERIOD_M15,0))
     {
      M15=iTime(Symbol(),PERIOD_M15,0);
      //Alert("New Bar on M15! ",TimeToString(M15,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-M15",0,M15,0);
     }

   if(M30!=iTime(Symbol(),PERIOD_M30,0))
     {
      M30=iTime(Symbol(),PERIOD_M30,0);
      //Alert("New Bar on M30! ",TimeToString(M30,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-M30",0,M30,0);
     }

   if(H1!=iTime(Symbol(),PERIOD_H1,0))
     {
      H1=iTime(Symbol(),PERIOD_H1,0);
      //Alert("New Bar on H1! ",TimeToString(H1,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-H1",0,H1,0);
     }

   if(H4!=iTime(Symbol(),PERIOD_H4,0))
     {
      H4=iTime(Symbol(),PERIOD_H4,0);
      //Alert("New Bar on H4! ",TimeToString(H4,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-H4",0,H4,0);
     }

   if(D1!=iTime(Symbol(),PERIOD_D1,0))
     {
      D1=iTime(Symbol(),PERIOD_D1,0);
      //Alert("New Bar on D1! ",TimeToString(D1,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-D1",0,D1,0);
     }

   if(W1!=iTime(Symbol(),PERIOD_W1,0))
     {
      W1=iTime(Symbol(),PERIOD_W1,0);
      //Alert("New Bar on W1! ",TimeToString(W1,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-W1",0,W1,0);
     }

   if(MN1!=iTime(Symbol(),PERIOD_MN1,0))
     {
      MN1=iTime(Symbol(),PERIOD_MN1,0);
      //Alert("New Bar on MN1! ",TimeToString(MN1,TIME_SECONDS));
      // do something...
      //ObjectMove(0,"Time-MN1",0,MN1,0);
     }

  }
//+------------------------------------------------------------------+
 
whroeder1:
  1. Adapt new bar code for new month.
    void OnTick(){
       static datetime BOMcur=0;                dateTime BOMpre     = BOMcur;  
       BOMcur = iTime( _Symbol, PERIOD_MN1, 0); bool     isNewMonth = BOMcur != BOMpre;
       if(isNewMonth){
          DO_UPDATE(); ...
       }

  2. for ( int i_MN = 0; i_MN < _cnt_MN1; i_MN++ ){ ...
       string _vlineName_MN = "PERIOD_MN1- " + IntegerToString( i_MN );
    Do not use shift numbers in object names. Once a new bar starts, all your objects are misnamed and you can't create a new "<prefix>0." You had it right in your original post (using time)
    string   _vlineName_MN1 = _prefix + "PERIOD_MN1 - " + TimeToStr( _timeCvrt_MN1, TIME_DATE )    ;
    Or convert the time to a int to a string.

Thanks for your comment.

Since your comment I was started trying to research your comment. (because I never used 'Void OnTick()' function)

So, I read below link then I understand 'OnTick()' function is running for Expert Advisors only.

I already use one Expert Advisor (Trade Panel) in my Chart (I need to use all my indicators and expert advisor in one chart window).

If you meant I could use your code in 'Expert Advisor', actually I won't because I will improve my 'Trade Panel', also I want to write code separately. (It's possible future I will combine that bunch of indicators (that important to me) - but not for now.)

Anyway, Mr William your comment really gave me idea and also teach me something.

(p.s if I am thinking wrong please let me know) 

And once again big thanks!
Event Handling Functions - Functions - Language Basics - MQL4 Reference
Event Handling Functions - Functions - Language Basics - MQL4 Reference
  • docs.mql4.com
Event Handling Functions - Functions - Language Basics - MQL4 Reference
 
Max Enrik(because I never used 'Void OnTick()' function)

Pre-build 600 (February 3, 2014) there was only start(). Now there is OnTick (EAs,) OnCalculate (indicators,) and OnStart (scripts.) I forgot you were talking about an indicator.

Start using the new Event Handling Functions - Functions - Language Basics - MQL4 Reference. See How to do your lookbacks correctly.

Event Handling Functions - Functions - Language Basics - MQL4 Reference
Event Handling Functions - Functions - Language Basics - MQL4 Reference
  • docs.mql4.com
Event Handling Functions - Functions - Language Basics - MQL4 Reference
Reason: