[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 149

 

I have the same problem as above emonh

I inserted a line before the start and nothing changes.

Why ?

if (OrdersTotal()>0)return(0);
 

or rather, even stopped opening positions at all and logged an error 138

 

Thanks for the tip though - I corrected the code a bit and indeed without the code line below, the EA was opening positions on every tick

and after I pasted the code line = EA opened one position exactly as I had planned.

int start()
   {
// начало открытия ордеров 
   if (OrdersTotal()>0)return(0);
 
first_may:

CME is what?

o_o - CME
 
BeerGod:
It has happened before, I think this is the intrigue of DC so that it would be problematic to test anything.
The DC has nothing to do with the quotes downloaded from the historical data server.
 
The DC has nothing to do with the quotes downloaded from the historical data server.

Well, everything is "supposedly" downloaded from a single server... Also, I thought that in the tester the leverage of the current account has no effect... But some brokerage companies have such street magic... May be some brokerage companies can play with quotes too? (Although all of them probably have problems here)...
 
alex12:

Thanks for the tip though - I corrected the code a bit and indeed without the code line below, the EA was opening pips on every tick

and after I pasted the code line = EA opened one position exactly as I had planned.

Well... this is only an apparent correspondence to the planned one. This construction does not take into account the symbol, order type or its magik. I.e., if there is another EA working on the account for another symbol, then this one will not work, because we already have a position. If only this EA works, but there is a Sell position and the Buy position needs to be opened, it will not open it - the position already exists and there are many other possible rules, for example, you have manually opened a position or set a pending order - that is it, the EA has risen...

You need to specifically check: Is there already an open position on such and such a symbol, with such and such a magician, of such and such a type? If not - open.

 
artmedia70:

Well... it's only an apparent match to the planned one. This design does not take into account the symbol, the order type or its magik. This means that if there is another EA working for another symbol in the account, then this one will not work, because there is already a position. If only this EA works, but there is a Sell position and the Buy position needs to be opened, it will not open it - the position already exists and there are many other possible rules, for example, you have manually opened a position or set a pending order - that is it, the EA has risen...

You need to specifically check: Is there already an open position on such and such a symbol, with such and such a magician, of such and such a type? If there is not - open.

Thank you. Yes it's true, because this EA only opens buy positions to continue movement and
only after close of buy position by take. For example if buy position is open and price goes down to
set level, then another buy position is not opened (and should have been opened by TS).
I have prescribed a certain price in the Send order lines - price section, see the code below.
My task is to write the right code in the EA = to open one more buy position after opening buy position,
, if the price goes down to a predefined level - open one more buy position. And so whatever level
the price has not crossed in the code - always open buy position, no matter how many

There are open positions at the moment.

extern double Lot=1;

int g=20; //тейкпрофит

double price[10];   // Заданный уровень 

//-----------------------
 
int init()
  {
  
double price[10];   // объявляем массив из 5 элементов  
           
price[0] = 1.2100; // обращаемся к первому элементу массива и 
                   // присваиваем ему цену. Обратите внимание 
                   // на то, что индекс первого элемента 
                   // начинается с 0. Это важная особенность,
                   // к которой нужно привыкнуть.   
 
price[1] = 1.2200;  // обращаемся ко второму элементу 
price[2] = 1.2300;  // и так далее 
price[3] = 1.2400; 
price[4] = 1.2500;
price[5] = 1.2600; 
price[6] = 1.2700;  
price[7] = 1.2800; 
price[8] = 1.2900;
price[9] = 1.3000;  

   return(0);
  }
//---------------
int start()
   {
// начало открытия ордеров 
   if (OrdersTotal()>0)return(0);
   
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)//проверка наличия откр.поз
   price[0]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2100,10,0,Ask+g*Point,"My order #",11);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[1]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2200,10,0,Ask+g*Point,"My order #",12);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[2]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2300,10,0,Ask+g*Point,"My order #",13);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[3]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2400,10,0,Ask+g*Point,"My order #",14);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[4]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2500,10,0,Ask+g*Point,"My order #",15);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[5]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2600,10,0,Ask+g*Point,"My order #",16);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[6]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2700,10,0,Ask+g*Point,"My order #",17);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[7]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2800,10,0,Ask+g*Point,"My order #",18);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[8]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.2900,10,0,Ask+g*Point,"My order #",19);
   }
   if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   price[9]=Ask;
   {
   OrderSend (Symbol(),OP_BUY,Lot,1.3000,10,0,Ask+g*Point,"My order #",20);
   }
      return(0);
  }
//+------------------------------------------------------------------+
 
Good afternoon. I would like to optimise the code. I have added three buffers to the indicator. Then I have a long search of signals in them. First I search MA1[], then МА2[] and МА3[]. The difference is only one digit of the buffer name used for calculations. Is it possible to loop the code.
 
alex12:
Yes that's right, because this EA only opens bai on the continuation of the move and
only after closing the buy position on the take ....
The opening curly brace { must be placed before price[...]=Ask; (see below). Read again about "if" operator. If there is no parenthesis immediately after if, it handles only one action (you have price[...]=Ask;), if you need several actions, they should be placed in {...} immediately after if.
if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)//проверка наличия откр.поз
   { 
      price[0]=Ask;
      OrderSend (Symbol(),OP_BUY,Lot,1.2100,10,0,Ask+g*Point,"My order #",11);
   }
if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==True)//проверка наличия откр.поз
   {
      price[1]=Ask;
      OrderSend (Symbol(),OP_BUY,Lot,1.2200,10,0,Ask+g*Point,"My order #",12);
   }
Reason: