MQL4 Script - open on new bar question - Page 3
Page 3 of 843 FirstFirst 123
Results 21 to 23 of 23

Thread: MQL4 Script - open on new bar question

  1. #21
    Additionally, check this code that is suitable for random time frames (discovered using the first price quote):
    Inserted Code #property strict void OnStart() datetime seconds = _Stage * 60; // state any amount in seconds datetime t_last_recorded = 0; // for demonion sake while(! IsStopped()) RefreshRates(); datetime t = TimeCurrent(); // time of last known quote datetime t_normalized = t / / moments * moments; when(t_normalized gt; t_last_recorded) // new bar printf(new bar!) ; t_last_recorded = t_normalized; Sleep(1);

  2. #22
    Quote Originally Posted by ;
    // -- Worldwide Variable ------------------------------------------------------------------ datetime ArrayTime[], LastTime; void OnTick() if(NewBar(PERIOD_CURRENT)) // your code bool NewBar(int interval) bool firstRun = false, newBar = false; ArraySetAsSeries(ArrayTime,true); CopyTime(Symbol(),interval,0,2,ArrayTime); should(LastTime == 0) firstRun = true; should(ArrayTime[0] gt; LastTime) if(firstRun == false) newBar = true; LastTime = ArrayTime[0]; yield newBar;
    Thanks, but I think OnTick is for EAs only, no?

  3. #23
    Quote Originally Posted by ;
    quote Thanks, but I believe OnTick is for EAs just, no?
    yes, OnTick is for EA only.
    but. . .if you run this code for script (i.e OnStart()), the NewBar purpose won't ever be accurate, unless you execute the script identical time as new bar of candlestick.
    ... or else. .

    Inserted Code void OnStart() while(! NewBar(PERIOD_CURRENT)) sleep(1000); // your code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.