Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 370

 
Ekburg:


Install the latest build to the terminal, it's easier to write code in it, less likely to make mistakes, I advise!)

Corrected the part that was sent first, without the last part of the brackets, which are not clear why...


this is my exit from the EA, if all conditions are fulfilled then exit from the EA

i.e.

fail=true;

and then

if(fail) return(0);

 
SpikeOne:


it's me exiting the EA, if all conditions are met then the EA is exited

i.e.

fail=true;

and then

if(fail) return(0);


This is understandable, but in the code that was sent at the beginning, there are a lot of unnecessary brackets before the output function.)

The one I sent helped?!

 
if ( AccountProfit()+ AccountBalance()>=740)
{
for(int zx=OrdersTotal(); zx+1>=0; zx--)
{
if(OrderSelect(zx,SELECT_BY_POS,MODE_TRADES)==true)
OrderDelete(OrderTicket());
}
while (OrdersTotal()>0)
{
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS),3,CLR_NONE);
if(OrderType()==OP_SELL) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),3,CLR_NONE);
if (OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
OrderDelete(OrderTicket());
if(result!=TRUE)
{
er=GetLastError();
Print("LastError = ",er, ",Symbol());
}
else er=0;
}
}
fail=true;
}

if(fail) return(0);

If you insert my code in the EA https://www.mql5.com/ru/code before the place

if(or_bu==risk && tick_b==0) open(0)

if(or_sl==risk && tick_s==0) open(1);

then EA starts to trade differently, although in my code it should enter only after typing 740, initially my balance is 700 in the tester.

The values for the tests can be set as follows:

extern bool test=false; //turn objects off at test

extern int prof=2; // profit level

extern int int chag=1.7; // step between orders

extern int risk=0; //risk level

extern double lot = 0.01; // initial lot

extern double k_lot=2; // volume increment

extern double lot_max=100;

bool result;

bool fail=false;

The problem is that it trades differently, I can't figure out the date I took for the test in 2013. 11. 08. и 2013. 11 .09.

 
SpikeOne:

then the EA starts to trade differently, although in my code it should only enter after dialing 740, initially my balance is 700 in the tester.


if ( AccountProfit()+ AccountBalance()>=740)
   {
   for(int zx=OrdersTotal(); zx+1>=0; zx--)
      {
      if(OrderSelect(zx,SELECT_BY_POS,MODE_TRADES)==true)
      OrderDelete(OrderTicket());
      }
   while (OrdersTotal()>0)
      {
      if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
         {
         if(OrderType()==OP_BUY) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS)),3,CLR_NONE);
         if(OrderType()==OP_SELL) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),3,CLR_NONE);
         if (OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
         OrderDelete(OrderTicket());
         if(result!=TRUE)
            {
            er=GetLastError();
            Print("LastError = ",er, " ",Symbol());
            }
         else er=0;
         }
      else Print( "Error when order select ", GetLastError());
      }
   if(OrdersTotal()==0) fail=true;
   }
if(fail=true) return(0);

Try to compile my code, let me know the result, then we'll think about it...

if it enters this code earlier than needed, then the problem is in the initial operator, let's see what's wrong

 
Ekburg:

Try to compile my code, let me know the result, then we'll think about it...

If it enters this code earlier than needed, then the problem is in the start operator, let's see what's wrong there


Yeah, I compiled it, but the problem persists.... It feels like it's entering the code earlier than it should.
 
SpikeOne:

yes compiled, but the problem remains.... yes it feels like it goes into the code earlier, though it shouldn't.

AccountProfitReturns the profit value for the current account in the base currency.

That's the problem I think, you want to know the profit in quid and it returns in euros, for example

Try replacing the entire calculation of the first code statement with this:

AccountEquityReturns the amount of equity for the current account. The equity calculation depends on the trade server settings.

and eventually compile this operator:

if(AccountEquity()>=740)
   {
   ...
   }
 
Ekburg:

AccountProfitReturns the profit value for the current account in the base currency.

That's the problem I think, you want to know the profit in quid and it returns in euros, for example

Try replacing the entire calculation of the first code statement with this:

AccountEquityReturns the amount of equity for the current account. The equity calculation depends on the trade server settings.

and eventually compile this operator:


The problem seems to be different, if I insert into an EA that does not work correctly, code that works correctly, then after compilation the EA does not work correctly, it feels like when you open a page in the browser, and it gives you the cache every time.

Even if you create a new EA and insert a working code there, it works crookedly for some reason.

 
SpikeOne:


...if I insert code that works incorrectly into an EA that works correctly, then after compilation the EA does not work correctly...


I can't help then) you need to go through the whole EA.
 
Ekburg:

I can't help then) I need to go through the whole EA.


I seem to have found a bug=) the initial data where the step between orders is set to int and I put 1.7, I changed it to double and it worked fine=)

 
SpikeOne:


I seem to have found a bug=) in the initial data where the step between orders is set to int and I put 1.7, I changed it to double and it worked fine=)


Well hello)))) when you find a mistake, you realise that everything was easier than you thought)
Reason: