Methods of Recovery after deinit() - got any ideas?

 

I am trying to finish an EA that watches manually placed trades with enough protection built in to prevent stupid errors on use.

Got to the deveopment area of protecting against use of Period Change the F7 key and schedualed computer restarts.

So no magicnumber. Situation to cope with is same symbol on two charts with EA watching two different tickets one EA on each chart.

The only 'device' I can come up with is to put an object on the chart with some info so that when reloading the info
from a file the EA can check for information on which ticket for the EA to watch by matching it with the object saved on the chart.

Any other posibilities?

 
Ickyrus:

I am trying to finish an EA that watches manually placed trades with enough protection built in to prevent stupid errors on use.

Got to the deveopment area of protecting against use of Period Change the F7 key and schedualed computer restarts.

So no magicnumber. Situation to cope with is same symbol on two charts with EA watching two different tickets one EA on each chart.

The only 'device' I can come up with is to put an object on the chart with some info so that when reloading the info
from a file the EA can check for information on which ticket for the EA to watch by matching it with the object saved on the chart.

Any other posibilities?

Why don't use ticket-number.??

 
Ickyrus:

I am trying to finish an EA that watches manually placed trades with enough protection built in to prevent stupid errors on use.

Got to the deveopment area of protecting against use of Period Change the F7 key and schedualed computer restarts.

So no magicnumber. Situation to cope with is same symbol on two charts with EA watching two different tickets one EA on each chart.

The only 'device' I can come up with is to put an object on the chart with some info so that when reloading the info
from a file the EA can check for information on which ticket for the EA to watch by matching it with the object saved on the chart.

Any other posibilities?

I don't think you have explained what you are trying to achieve so it makes it hard to understand what your issue/problem is that you are trying to solve.
 
dineshydv:

Why don't use ticket-number.??


manually placed trades.....

Use an EA to set also magicnumber to place SELL or BUY trade

place a StopLoss and TakeProfit

for MA or other indicators you are using ==> choose not Period() == 0 but the period of the timeframe you do the calculation for setting

 

I have been searching back through the forum using variations on the word recovery and so far there seems to be one solution of editing the .chr file which is described as 'messy'

The EA watches manually placed trades. So the situation that could occur is multiple instances of the same EA on the same Symbol() in diferent charts - Windows does one of its automatic restarts while you are away or VPS does a software update logically you want your trades being 'watched' to continue being watched with the settings you started with.

 

Forget .chr. Your problem is simple.

For the EA trading, use a range of magic numbers, one per TF https://www.mql5.com/en/forum/139132

Since there is no magic number associated with manual trades, so all the EAs should modify them the same way, no problem.

Otherwise all you need is to prevent the same EA from running on same pair (any TF.) See my code for GetTradeContext()/RelTradeContext()

Not compiled, not tested.

int init(){
   active.prefix = WindowExpertName() +"_" + Symbol(),
   active.tf     = active.prefix      +"_" + Period();
   GlobalVariableSet(active.tf, 1.);
}
int deinit(){
   GlobalVariableDel(active.tf);
}
#include <WinUser32.mqh>       
int start(){
    if (GetTradeContext() >= TC_LOCKED){
        double  dValue = GlobalVariableGet(gvn);    
        if (dValue == 0.){  
            Alert("GlobalVariableGet(",gvn,") Failed: ", GetLastError());
            // this will remove expert from chart
            PostMessageA(WindowHandle(Symbol(), Period()), WM_COMMAND, 33050,0);
            // How do I close an Expert programmatically? - MQL4 forum
            // https://forum.mql4.com/26236#264937
        } 
        else{
            for(int iPos=GlobalVariablesTotal(); iPos >=0; iPos--){
               string gvn  = GlobalVariableName(iPos);
               if (StringFind(gvn, active.prefix) != 0) continue; // Not correct
               if (gvn == active.TF)                    continue; // Ignore mine.
                GlobalVariableDel(gvn);     // Tell him to exit, I'm taking over.
            }
            // Do what's needed
        }
        RelTradeContext();
    }
}
Not compiled, not tested.
 
Thanks - Thats one way to solve the problem.
Reason: