How to prevent the user from changing the symbol and/or account in the current chart? - page 2

 
Alain Verleyen:

Why ?

You should improve your code. You already have all what is needed to monitor a change of symbol/timeframe/account and act accordingly. I don't want Metaquotes to impose new restrictions, they already take enough decisions in place of traders/programmers.

Marco vd Heijden:

the answer is clear too.

but it is possible to get to a workable solution by improving your code.

i.e they can still switch symbol and time frame, but it will not affect your EA; you are approaching it from the wrong end.

trying to change the program to meet your needs, it should be the way around, change your code.

Big fat NO

I´ll explain you in detail why you are both wrong and why this improvement is definitely necessary for some reasons.

Example #1: I have an EA, lets call it the Dow Jones Trader. This EA draws an interactive line which starts at the future opening time at 0:00 European time and ends at stock market open 15:30 or wherever the user wants. To this line is a trade-signal connected. Now the user changes the chart, just like that, i. E. to the DAX. The DAX has not even a price at 0.00, because the future opens at 08:00. So where shall I draw this line with your guys logic in the meanwhile? Of course I still can trade this line invisible, but it makes no sense at all because the benefit of this EA is visual trading with lines like that. It´s nonsense to keep all the information on hold, because 50% of the EA - which is the visual part - simply cannot work anymore due to restrictions of the new symbol. As you see, we don´t talk about an EA, we talk about semi-automated trading, which is a big difference, because the EA needs the user and the user needs the chart to make decisions and to tell the EA again what to do. 

And this is only one example.

Example #2: I created indicators which are connected to one specific symbol and they work pure visual with specific times of this symbol. Those indicators make 0% sense with other symbols and the only reason is: Termination. Same with all EAs that are connected to a specific symbol, it makes no sense to display anything else than that what the EA trades. 

Example #3: The final killer - you even cannot continue trading anything when the user changes the account, no matter what you code or not. 

And to prevent this reactive, destructive behavior, there is no other way than preventing the user from changing the symbol AND the account upfront, as long this EA is active, to give the user a fair chance to terminate all such EAs before he´s definitely going to lose money.

You guys try to explain me that treating the symptoms of an illness is way better than preventing getting sick. Right? This strategy may work for the pharma industry very well, yes, but surely nowhere else ;)

 
Alain Verleyen:

If you need help please explain your problem with some details.

Thank you, that´s nice.
 

Doerk:

because 50% of the EA - which is the visual part - simply cannot work anymore due to restrictions of the new symbol.

You guys try to explain me that treating the symptoms of an illness is way better than preventing getting sick. Right? This strategy may work for the pharma industry very well, yes, but surely nowhere else ;)

yeah well you didn't mention that in the first place.

EA's to me are automated systems that can be left alone.

Sure you can twist your explanation around to be able to say big fat no,

but the truth of the matter is that a real good EA will be able to recover from most if not all unexpected situations.

And that boils down to a Quality issue, especially when it comes to user intervention.

People f*** things up and we coders need to deal with that.


oh and this improvement is certainly not necessary.

i am constantly treating the symptoms, get used to it.

 

This does not prevent the deinit

but you save the state at deinit and restore at init time

#property strict

static string firstSymbol = NULL;
static ENUM_TIMEFRAMES theTF = NULL;
static long chartid;
static bool restore = false;

int OnInit()
  {
   if (firstSymbol==NULL)
   {
      firstSymbol = Symbol();
      theTF =ChartPeriod();
      chartid = ChartID();
   }
   else 
      if (!restore)
         RestoreState();
      else {
         restore=false;
      }
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
      if (reason==3)
         SaveState();
  }

void SaveState()
{
   Print("SaveState for "+firstSymbol); // save any infomation to a file
}

void RestoreState()
{
   // restore any infomation from a file
   Print("RestoreState "+(string)chartid+" to "+firstSymbol+" not "+Symbol());
   restore = true;
   ChartSetSymbolPeriod(chartid,firstSymbol,theTF);
}

Regards, Uwe

 

One thing afterwards:

All this makes no sense and the reason is very simple: When the user changes the symbol, the EA simply will not receive any ticks for the symbol it is dealing with. And when it trades Forex and the user switches to a stock-symbol at night, the EA is dead.

So you can "improve" what you want, this is a serious problem and there is no good workaround. Of course one could use OnTimer() instead of OnTick(), but this leads the existence of OnTick() totally ad absurdum and btw. - OnTimer() does not work in the strategy tester and would furthermore burn down the CPU if you set the timer that tight that you don´t miss a single tick. 

Doerk 

 

I always use OnTimer().

And i always check to see if strategy tester is running or not.

This is perfectly do able and there are several good work a rounds.

also i usually handle all available symbols in one ea so there is no need to switch symbol, and if it happens it makes no difference in the performance of the ea it is completely de coupled from time frame or chart symbols.

Reason: