[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 628

 
IgorM:

for statement without a parameter? - the second is that there are global variables for the EA - not for the terminal, they are described at the very beginning of the code before all functions, including the start() function, as you have written - at every tick the start() function is called, you flagchange = false; and then you try to compare this flag with the previous state, but its state will always be false

If you are just starting to try your hand - take any ready-made Expert Advisor from Kodobase and change the conditions for entering the market to your own - it will be faster.


Vinin
What is the purpose of the loop?

You mean that the start() function is executed at every tick? Then the loop is really unnecessary.

 

MarkTrade:

So the start() function is executed at every tick? Then a loop is really unnecessary.

https://book.mql4.com/ru/programm/special
 

Interesting how the girls dance... Standing in unison and singing...

Tested and tested, added/changed functions/conditions/data based on the results, got more or less good results in terms of profitability and drawdown... without optimisation. Reloaded the whole story and it started to plummet, no - Plum, not even - Big Plum...

If before I reloaded quotes' history(I had a preloaded EURUSD history before testing, I reloaded it just in case - I had errors in modeling quality since 2010 for some reason...)... Before reloading the history the Expert Advisor successfully, well almost successfully withstood different back-and-forth tests, successfully traded on three-year history, but after reloading quotes started to have drawdowns two or three times a month and did not work for more than two-three months after the test started ... I didn`t change any conditions, only the history...

It turns out that on the server history is being rewritten? As for centuries in the Soviet Union?

What's the point of it all, then?

 
artmedia70:

The girls dance interestingly... stood up together and sang...

Tried and tested, added/created functions/conditions/data, got more or less good results in terms of profitability and drawdown... without optimisation. I reloaded the entire history and it started to go down, no, it was a BIG BLEEP, not even a BIG BLEEP...

If before reloading quotes history(before testing I had all EURUSD history preloaded, just to be safe I reloaded it, but for some reason I had errors in modeling quality since 2010)... Before reloading the history the Expert Advisor successfully, well almost successfully withstood different back-and-forth tests, successfully traded on three-year history, but after reloading quotes started to have drawdowns two or three times a month and did not work for more than two-three months after the test started ... I haven't changed any conditions, only the history...

It turns out that on the server history is rewritten? As time immemorial in the USSR?

And then the point of all this?

If your MT is still not disconnected from the server then it's time to do it (and do not connect it unnecessarily again) - every time you start tester or optimization, MT gets a spread (etc.) from the server. So, when the spread is 1 pip, everything will be super-awesome, but if at another time it increases to 4-5 - the Expert Advisor will probably start to lose money. Naturally, it is better to optimize at worst conditions, because they are more likely to occur in real trading.

 

Here's a bit of a rework.

глобальные переменные (в самом начале, под #property link )
bool flagchange = false;
bool PrevFlag = false;
bool flag = false; 

int start()
  {
   //---вход в позицию
   //int    spread=MarketInfo("EURUSD",MODE_SPREAD);
   int Slippage = 3;
   int i = 0;
   double lt = getLots() ; // минимальный лот
   RefreshRates();
   int total = OrdersTotal();   
   int ticket = -1;
      flag = GetEma();
        if (PrevFlag != flag) // проверим, сигнал ема изменился?
         {flagchange = true;      // изменился!
         PrevFlag = flag;}
        else flagchange = false;
        if (flagchange == True)
         {       
           int Total=OrdersTotal(); // есть открытые позиции?
           if(Total>0)
            {
              for(i=Total-1; i>=0; i--) 
              {
                if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true) 
                  {
                    if(OrderType()==OP_BUY || OrderType()==OP_SELL) // Только Buy и Sell
                     {
                       if(OrderType()==OP_BUY) 
                         bool Result=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,CLR_NONE);
                       else
                         Result=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,CLR_NONE);
                     if(Result!=true) 
                        {          
                          Print("LastError = ",GetLastError()); 
                         }              
                      }
                   }
                else 
                   if (flag ==true) OrderSend(Symbol(),OP_BUY,lt,Ask,Slippage,Bid - sl * Point,0,"Buy",888,0,Blue);
                   else OrderSend(Symbol(),OP_SELL,lt,Bid,Slippage,Ask + sl * Point,0,"Seel",888,0,Red);
              }
           }                                            
        }
     
   return(0);
  }
      //////////////////////////////////////////////////////
  bool GetEma() {
  //----Получим значение EMA1
      int ma1= iMA(Symbol(),PERIOD_H1,ema1,0,1,6,0);
  //----Получим значение EMA2   
      int ma2= iMA("",PERIOD_H1,ema2,0,1,6,0); 
      if (ma1>ma2) return (True);
      else return (False);}
   /////////////////////////////////////////////////////  
         // посчитаем разтер лота
   double getLots() 
        {
                double minlot = MarketInfo(Symbol(), MODE_MINLOT);
                 int round = MathAbs(MathLog(minlot) / MathLog(10.0)) + 0.5;
                 double lot = minlot;
//---- select lot size
                 lot = NormalizeDouble(AccountFreeMargin() * Risk / 1000.0, round);
                 if (AccountFreeMargin() < lot * MarketInfo(Symbol(), MODE_MARGINREQUIRED)) 
                        {
                                lot = NormalizeDouble(AccountFreeMargin() / MarketInfo(Symbol(), MODE_MARGINREQUIRED), round);
                        }
                 if(lot < minlot) lot = minlot;
                 double maxlot = MarketInfo(Symbol(), MODE_MAXLOT);
                 if(lot > maxlot) lot = maxlot;
//---- return lot size
   return(lot);
        }

Still doesn't trade :(

 
chief2000:

If your MT is still not disconnected from the server it is time to do so (and no longer connect it unnecessarily) - every time you run a tester or optimise the MT receives a spread (etc.) from the server. So, when the spread is 1 pip, everything will be super-awesome, but if at another time it increases to 4-5 - the Expert Advisor will probably start to lose money. Naturally, it is better to optimize at worst conditions, because they are more likely to occur in real trading.

It's all clear and long understood... But it's Saturday... Can the spread change today? No... It's probably minimal now, i.e. the best conditions... No... Even with any spread, the EA was trading well... before the history reset.
 
artmedia70:
It's all clear and long understood... But it's Saturday... Can the spread change today? No... It's probably minimal now, i.e. the best conditions... No... Even with any spread, the EA was trading well... before the history reset.
Well, if you look at the trading progress on the chart, what has changed?
 
Techno:
Well, if you look at the trading progress on the chart, what has changed?
Equity drawdown has increased many times... It turns out that there are more conditions to open positions. He actually opens more positions...
 
MarkTrade:

Here's a bit of a rework.

Still not trading :(

There must be an error somewhere in the conditions / logic
because MetaEditor does not have a debugger, so I do this:

add at the end of the code

Comment( "flag= ", flag, " PrevFlag=", PrevFlag, ......);

return(0);

}

and in the visualization mode in the tester at low speed see what changes and what doesn't

 
artmedia70:
Equity drawdown has increased many times over... It turns out that the conditions for opening positions have increased. He actually opens more positions...
I don't mean the test chart, but the quote chart, roughly, what are the changes in openings, closings?