Script example - page 2

 

Period_converter script refreshes my offline H3 chart by PostMessage function.

And what script or expert refreshes your offline H1 chart?

 
brave0heart wrote:
stringo wrote:
What about following lines?
===
18:46:13 period_converter EURUSD,H1: loaded successfully
18:46:38 period_converter EURUSD,H1: 1534 record(s) written
18:47:42 period_converter EURUSD,H1: Chart window detected
===
Period converter must detect a chart opened offline

Test script attached to the offline chart
===
18:48:22 test_script EURUSD,H3: loaded successfully
===
In this case EURUSD,H3
============================
OK. I have an offline H1 chart of the EUR USD loaded. I compiled your script, but it still reads the most current bid/ask. Here is the log.
07:06:58 Compiling 'hist_Test'
07:07:45 hist_Test EURUSDm,H1: loaded successfully
07:07:45 hist_Test EURUSDm,H1: bid = 1.2559 ask = 1.2561
07:07:45 hist_Test EURUSDm,H1: bid = 1.2559 ask = 1.2561

The script has stopped by itself.


This is from Андрей Хатимлянский who graciously provided this.

int init()
  {
   start();   // call start() function
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
  double mBid = 0.00;
  double mAsk = 0.00;
  while (!IsStopped())
   {
   mBid = MarketInfo( Symbol(), MODE_BID );
   mAsk = MarketInfo( Symbol(), MODE_ASK );
 
   double ma = iMA( NULL, 0, ....... );  // insert other things here
   
   Alert(mBid, " ",mAsk);
   Sleep(1000);
   }
   return(0);
  }
 
This is good solution if You do not use your own non-standard timeseries and indicators calculated on such timeseries.
 

How can I add custom indicators in this script to check last bars to verify sell or buy?

Thank in advance!

 
brave0heart:


This is from Андрей Хатимлянский who graciously provided this.


Hello guys,

i just created an EA based on the above code. But when the EA opens a position, a message appears at the Experts tab console, saying that the EA initialized. After that, the EA is dead and nothing else can be executed.

I would appreciate any help

Thank you

 

For what it's worth, I use this in the EA I created for offline Renko charts... :-) 

 

This will allow MT4 to kill the EA if needed, and will also stop the EA if you turn off "Experts Allowed" in your MT4 app.

 

void OnInit() {
   // Perform init stuff here...

   // Since we are running in an offline chart, we must manually call OnTick() and run a forever while() loop inside of that.
   OnTick();

   return;
}

  

void OnTick() {

   while (!IsStopped()) {   

      if (!IsExpertEnabled()) { break; }

      //---- Only go trading on the beginning of a NEW bar/candle.
      if (isNewBar()) { 
         journalString = StringConcatenate(alertPrefix, "New bar! Time: ",Time[0]);
         Print(journalString);  

         checkForTrades();
      }
   }   

   // Sleep for 100ms so we don't kill the CPU
   Sleep(100);

   }  
}

void checkForTrades() {
   // Code for checking if you should place an order or exit an order goes here...

}
 
maj1es2tic:

For what it's worth, I use this in the EA I created for offline Renko charts... :-) 

 

This will allow MT4 to kill the EA if needed, and will also stop the EA if you turn off "Experts Allowed" in your MT4 app.

 

  

Just two points. More than 6 months there has been OnTimer event handler, so no need for loops in OnTick() or OnInit(). The other point is that you can test only a strategy based on a standard OnTick event.

So better to chose such an offline chart that does not require workarrounds.

Reason: