EA DeInits upon change of TimeFrame on chart

Back to topics list To post a new topic, please log in or register
avatar
63
Route206 2015.06.04 19:42
 

I have a simple EA that takes and closes positions based on a grid.

When running, i cannot change the timeframe of the Chart it runs on (e.g. from 5m, to 15m) withouth the EA DiInit-ing and re-Init-ing.

Since my EA is completely independant of the timeframe (not an indicator of any sort) I'm probably overlooking something stupid.

can someone enlighten me?

thanks! 

avatar
Moderator
3427
GumRai 2015.06.04 20:02 #
 
So, what is the problem?
avatar
63
Route206 2015.06.04 20:07 #
 

Sorry if that wasn't clear: it closes and re-opens all positions as per De-Init en Init.

that a chunk of spread and commission gone to waste :-(

I'd like the EA to continue to run on the chart regardless of changing the time frame... 

avatar
13009
WHRoeder 2015.06.04 20:54 #
 
Route206:

i cannot change the timeframe of the Chart it runs on (e.g. from 5m, to 15m) withouth the EA DiInit-ing and re-Init-ing.

it closes and re-opens all positions as per De-Init en Init. that a chunk of spread and commission gone to waste :-(

I'd like the EA to continue to run on the chart regardless of changing the time frame... 

  1. That is what it does. Deal with it.
  2. Don't close trades and there is nothing wasted..
  3. Code your EA to do that. You know why the deinit/init happened UninitializeReason - MQL4 Documentation
  4. EA's must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a orderSelect loop to recovery, or persistent storage (GV/file) of ticket numbers required.

avatar
63
Route206 2015.06.05 08:53 #
 

Thanks - from my amount of posts here you can safely assume i'm a newbie, so i need some time to digest your response.
To be clear though: If you say '"Don't close trades and nothing is wasted" then that is exactly what i'm trying to accomplish here!
My EA is recovering fine, even when it shouldn't have collapsed to begin with  (upon change of chart timeframe..)

avatar
126
Demos 2015.06.05 11:39 #
 
Well, https://docs.mql4.com/runtime/running you can see all about your questions (at around the middle part of that page with the bold letters)
avatar
63
Route206 2015.06.25 09:42 #
 

OK - i've come to accept that changing timeframe on a chart with an Active EA, will cause it to DeInit() and Init() again. That said, is there no way i can get like a pop-up warning "This Chart has Active EA, are you sure?, y/n" kind of thing? 

Sorry to nag on this one, but, clumsy me, it continues happen inadvertently and it is really, really annoying.

I'm ok if i'm the dumbest one here, but would really appreciate some pointers.. Pop up would solve it for me..

avatar
145
aakcaagac 2015.06.25 09:52 #
 

When running, i cannot change the timeframe of the Chart it runs on (e.g. from 5m, to 15m) withouth the EA DiInit-ing and re-Init-ing.

can someone enlighten me?

Actually I can help in case you have the source code of your Indicator. There is a way to test for timeframe changes and once the test for timeframe changes is true, you can return from the DeInit() method without actually de-initing. I know this, because I ran into a similar issue not long ago. Please have a look here:

[1] Performance issue on timeframe changes

If you scroll down at the close bottom, you find two source codes attached. Please take the boost_2.mp4 and copy out the if (...) statement at the top of the DeInit(); method and paste it into your own source.

        if (UninitializeReason() == REASON_CHARTCHANGE) {
                return;
        }

Now you can change timeframe without actually DeInit'ing. Normal remove of the Indicator or closing terminal of course de'inits.

Oh! And you most likely need to add the same in the OnInit(); method at the top because on each DeInit(); follows a new OnInit(); 

avatar
63
Route206 2015.06.25 16:06 #
 
great - i'll try that! Thanks so much.
avatar
313
JD4 2015.06.27 07:32 #
 
It is the default operation of the EA system (unless as has been stated the EA is specifically designed) for it to stop operation and restart again when the time frame is changed.  Not sure if this was intended to help prevent losses to traders or whatever reason as it seems some systems were put in place for what someone thought was a good reason at the time.
Back to topics list  

To add comments, please log in or register