Run script through Expert Advisor - page 3

 
Dadas:


Is there a way to trigger a script in a loop controlled by some ticker, like every 50ms or smth like that?

Not by MT4 ticks?


I will try to answer this myself:

It is not possible, because the start() function is run by the new quotes, which means the broker's ticks.

So, even if you have a loop inside the start() function, it only loops when a new tick comes in.

That is why you can not win against the broker!

Though, when I ran my EA as a Script like this:

int start() {

while(1==1) {

MyEA();

}
}

my computer started lagging, because of that loop.

I tried this on Sunday, so market was closed.

 
Dadas:


So, an EA could run as a script? In a loop?

Only, when in an infinite loop, the computer will eventually crash.

Is there a way to trigger a script in a loop controlled by some ticker, like every 50ms or smth like that?

Not by MT4 ticks?


A script runs once unless you add a finite/infinite loop within it's start() function. If you want to trigger the script with your own generated tick then make it an EA and put it on an offline chart.
 
Dadas:


Though, when I ran my EA as a Script like this:

my computer started lagging, because of that loop.


Your computer needs an upgrade . . . or to be replaced.
 
RaptorUK:

Your computer needs an upgrade . . . or to be replaced.

That is quite true! It is an old one.
 
RaptorUK:

A script runs once unless you add a finite/infinite loop within it's start() function. If you want to trigger the script with your own generated tick then make it an EA and put it on an offline chart.

I can not trade on an offline chart.
 
Dadas:

I can not trade on an offline chart.
Why not ?
 

Dadas 2012.08.12 16:34
Dadas:


Is there a way to trigger a script in a loop controlled by some ticker, like every 50ms or smth like that?

Not by MT4 ticks?


I will try to answer this myself:

It is not possible, because the start() function is run by the new quotes, which means the broker's ticks.

So, even if you have a loop inside the start() function, it only loops when a new tick comes in.

That is why you can not win against the broker!

Though, when I ran my EA as a Script like this:

int start() {

while(1==1) {

MyEA();

}
}

my computer started lagging, because of that loop.

I tried this on Sunday, so market was closed.

Hi Dadas,

Script is executed without a tick, EA is executed with a tick.

When using an infinite loop, add a Sleep () (https://docs.mql4.com/common/Sleep)

Try this code below as a script, turn off internet connection, open task manager and attach the script to the chart. The script will loop infinitely withouth the need for a tick, and without using too much processor usage.

  int n;
  while (IsStopped() == false) // or while (true)
    {
    n++;
    Alert (n);
    
    Sleep (500); // add this !
    }

 
.
 
RaptorUK:
Why not ?


Enlighten me, please!

How can I do realtime live trading on an offline chart?

 
onewithzachy:

Hi Dadas,

Script is executed without a tick, EA is executed with a tick.

When using an infinite loop, add a Sleep () (https://docs.mql4.com/common/Sleep)

Try this code below as a script, turn off internet connection, open task manager and attach the script to the chart. The script will loop infinitely withouth the need for a tick, and without using too much processor usage.


Thanks a lot!

It is so simple, I should have thought of it myself...

Tired, I quess....... Like my old computer - LOL!

Though, you know, I was thinking of smth a little bit different.

I am thinking of how to override the ticking in MT4 live trading!

The point is, that while live trading, the ticks control the EA and thus the broker can as well.

In other words, if I want my EA to close the order under some condition - I want my EA to do just that, definitely, not maybe.

Apart from the requotes (which I can do nothing else about, but change the broker), it happens too often that I see on my chart

that my order should be closing, yet it is just hanging until the next tick, and then it loses.

If I write in my EA:

if(AccountProfit()>0) { CloseAllOrders(); }

then I want it to close @ 1 Pip profit or more. I do not expect it to hang on the 1 Pip and do nothing!

BTW, I am trading with fixed spread of 1 Pip on EURUSD.

So, I do not need the obvious, and Sleep() is also not a solution, other than for offline backward testing.

BTW, any backward testing is not good for anything - it is not realtime testing.

Well, it is good for some observations and chart studying, to learn a lot!

But, in realtime trading you do not know the future, and you will make mistakes - unless you really trust your EA!

Trust it more than what you see on the charts! - That is the hardest part!

So, Guys, please read my posts with understanding!

Reason: