Convert Expert Advisor to Script

 

Hello,

I want to attach my Expert Advisor to 7 Minute chart(offline chart updated every tick), but EA won't work on that chart. I have heard that Script does not has that restriction, but unfortunately is executed only ones. My question is how to convert EA( for example Moving Average Expert Advisor) to script and trade like EA in offline updated chart?

 
You heard wrong. Put the EA on the offline chart. Replace all references to Period(), Symbol() including NULL, 0
 

Hi,

you mean that Expert Advisor could be attached and make trades on offline chart if references from standard time frames are cleared to NULL, 0 ?

 

Other way around.

OrderSend("EURUSDM2"... or OrderSend(Symbol()... won't work because there is no real chart with that name. Like wise MarketInfo(Symbol(), MODE_MINLOT) will not work. All references to Symbol() must be replaced with the real symbol.

Calls to Period() must be looked at.

Calls to indicators must be NULL,0 so they work on the current chart.

 

Hello WHRoeder,

I do not use indicator - just global variable and Open, High, Low and Close from CURRENT OFFLINE CHART. I do not understand. Can you please set a simple example with Order Send function for buying order?

Thank you.

 
Grigor:
I do not understand.
What part of
All references to Symbol() must be replaced with the real symbol.
is unclear?
 

As far as I know, using Symbol() for OrderSend is ok for offline charts, since Symbol() function does not consider timeframe, just currency pair. Perhaps there are other causes.

You may put the code of init() and start() of the EA on the start() function of a script, though it's not always convenient to do so (forget about deinit()). You may place all the code under an infinite loop, just remember to put some delay so your script won't cause your terminal to crash.

 
Sample:
  int ticket;
  if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
    {
     ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green);
     if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
    }
For example how in this code if EA is attached to EURUSD M7 chart "All references to Symbol() must be replaced with the real symbol." This I don't understand. Thank you.
 

Like this . . .

int ticket;
  if(iRSI("EURUSD", 0 ,14,PRICE_CLOSE,0)<25)
    {
     ticket=OrderSend("EURUSD",OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green);
     if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
    }

. . . not sure what you do with the 0 in the iRSI call which means "this TF" . . M7 isn't a regular TF so not sure how you will sort that . . .

 
Thank you. I need EA to work on offline chart updated every tick. So looking for an every possible option.
 
Grigor:
Thank you. I need EA to work on offline chart updated every tick. So looking for an every possible option.


I know it's kind of late, but sorry guys about my last post. I thought Grigor was referring to Renko charts.

Reason: