[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 42

 
sting-igor:
Do DoCs have a limit on the number of trades?

Some have not only a limit on the number of deals, but even a limit on the number of requests.

They are such inventors! :-))

 
Good afternoon!
Last time I asked a question about opening orders, now I have a question about closing them.)
Below is a piece of code with functions that open orders and close them.
When my Expert Advisor is working, I get a "peculiarity" like this: For example, 10 different orders are opened and 2 of them are closed in the process,

The rest of them stay open till the end of the test though a conditional closing of one order should take place when another one is opened.

........................
magick=MathRand(); 
     
     if(NewBar())
 {     

  //---- Условие SELL
if(MAarrUP1[j]>0.35 && MAarrUP2[j]>1.8)
     {
 closeDnOrd();OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,0,magick,0,Blue);
     } 
  
  //---- Условие BUY
    if(MAarrDN1[j]<-0.35 && MAarrDN2[j]<-1.8)
    {
closeUpOrd();OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,0,magick,0,Red);
     }
}
............
//--------------------------------------------------------- Функции

//----- Функция закрытия селл

void closeUpOrd()
  {
  for(int i=0;i<=OrdersTotal();i++)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=magick || OrderSymbol()!=Symbol()) continue;

  if(OrderType()==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
      } 
    }

//---- Функция закрытия бая

void closeDnOrd()
  {
  for(int i=0;i<=OrdersTotal();i++)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=magick || OrderSymbol()!=Symbol()) continue;

 if(OrderType()==OP_BUY)
{
 OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
}
      } 
  }

Another question about errors 4051 and 134 when using OrderClose(), what do they mean? I copied info from the log.

02:54:37 2010.10.17 23:16  Ti&Pi_Speeder_Exp AUDUSD,M1: invalid ticket for OrderModify function
02:54:37 2010.10.17 23:16  Ti&Pi_Speeder_Exp AUDUSD,M1: OrderModify error 4051


02:54:37 2010.10.17 23:22  Ti&Pi_Speeder_Exp AUDUSD,M1: OrderSend error 134

 
Vinin:

The last option seems to have worked more or less well. Although it is possible to simplify the calculations
Tell me why you have the iMAOnArray function in a separate loop?
 

Please advise! How can I close two pending orders with same magic, but with different lot.


int start()

{
double MyLastBullOpenPrice=0;
for(int Cnt=0;Cnt<OrdersTotal();Cnt++)
{
OrderSelect(Cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==12345 && OrderType()==OP_BUY)
{
MyLastBullOpenPrice=OrderOpenPrice();
double Cena=OrderOpenPrice()+5*Point;
double Totalcena= Bid;

if (Totalcena>Cena)
{
if (OrdersTotal()>0)
{ for (int i=OrdersTotal()-1; i>=0; i--)
{ if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{ if(OrderMagicNumber()==12345)

{ if(OrderDelete(OrderTicket())==true)
{
Print("Error = ",GetLastError()); return(0);
}
} } } }
}
}

return(MyLastBullOpenPrice);
}

 
Fox_RM:
Good afternoon!
Last time I asked a question about opening orders, now I have a question about closing them.)
Below is a piece of code with functions that open orders and close them.
When my Expert Advisor is working, I get a "peculiarity" like this: For example, 10 different orders are opened and 2 of them are closed in the process,

The rest of them stay open till the end of the test though a conditional closing of one order should take place when another one is opened.

Another question about errors 4051 and 134 when using OrderClose(), what do they mean? I copied info from the log.

134 - no money, 4051 - bad parameters passed to the function.

As for the point - check that the variable magick is assigned only once, preferably in function init(), otherwise, every order will have its own magick and the result will be something like you describe.

 

Please help me to add (or write) a character substitution function for a string through arrays.

Have two arrays of characters:

string symbols1[] = {"a", "b", "c", "d"};
string symbols2[] = {"1", "2", "3", "4"};


Tried to write a function that would replace the text badc with 2143, based on the arrays, turned out like this:

string ReplaceSymbolsInStr(string text){
string textMod[] ={""};
string symbols1[] = {"a","b","c","d"};
string symbols2[] = {"1","2","3","4"};
int textLen = StringLen(text);
for (int i1=0; i1<textLen; i1++)
{
string OneSymbol = StringSubstr(text,i1,1);

for (int i2=0; i2<ArraySize(symbols1); i2++)
{
if (symbols1[i2]==OneSymbol) int PosSymbolIn1array=i2;
}
return(-1);

string OneSymbolMod = symbols2[PosSymbolIn1array];
int NewArraySize = ArraySize(textMod)+1;
ArrayResize(textMod,NewArraySize);
textMod[i1]=OneSymbolMod;
string textNew;
textNew=StringConcatenate(textMod[1],textMod[2]...);//собрать массив в строку вообще не могу :(
return (textNew);
}
}

I know it's wrong and I can't assemble the array into a string at all. Please help.

 
Zhunko:

Some have not only a limit on the number of deals, but even a limit on the number of requests.

They are such inventors! :-))

is there any block against them meddling in your affairs?
 
Lians:

Please help me to add (or write) a character substitution function in a string through arrays.

Have two arrays of characters:

string symbols1[] = {"a", "b", "c", "d"};
string symbols2[] = {"1", "2", "3", "4"}


Tried to write a function that would replace the text badc with 2143, based on the arrays, turned out like this:

string ReplaceSymbolsInStr(string text){
string textMod[] ={""};
string symbols1[] = {"a","b","c","d"};
string symbols2[] = {"1","2","3","4"};
int textLen = StringLen(text);
for (int i1=0; i1<textLen; i1++)
{
string OneSymbol = StringSubstr(text,i1,1);

for (int i2=0; i2<ArraySize(symbols1); i2++)
{
if (symbols1[i2]==OneSymbol) int PosSymbolIn1array=i2;
}
return(-1);

string OneSymbolMod = symbols2[PosSymbolIn1array];
int NewArraySize = ArraySize(textMod)+1;
ArrayResize(textMod,NewArraySize);
textMod[i1]=OneSymbolMod;
string textNew;
textNew=StringConcatenate(textMod[1],textMod[2]...);//собрать массив в строку вообще не могу :(
return (textNew);
}
}

I know it's wrong and I can't assemble the array into a string at all. Please help.

You're supposed to have found the index of the character in the replacement array, so why create another array?

Try adding it to a plain text variable in the first loop:

string ReplaceSymbolsInStr(string text)

{


string symbols1[] = {"a", "b", "c", "d"};

string symbols2[] = {"1", "2", "3", "4"};

string textNew="";

int textLen = StringLen(text);

for (int i1=0; i1<textLen; i1++)
{
string OneSymbol = StringSubstr(text,i1,1);

for (int i2=0; i2<ArraySize(symbols1); i2++)

{
if (symbols1[i2]==OneSymbol) {textNew = textNew + symbols2[ i2 ]; i2=ArraySize(symbols1) ; }

}

}

return (textNew);

}

 


Or it's even easier like this:

string ReplaceSymbolsInStr(string text)

{


string symbols1[4] = {"a", "b", "c", "d"}; // array size by the number of symbols in it

string textNew="";

for (int i1=0; i1< StringLen(text) ; i1++)

{
string OneSymbol = StringSubstr(text,i1,1);

for (int i2=0; i2<ArraySize(symbols1); i2++)

{
if (symbols1[i2]==OneSymbol )

{

textNew = textNew + (i2+1); // the number of the symbol itself is added to the returned text

i2=ArraySize(symbols1) ; // completed the search loop

}

}

}

return (textNew);

}

 

Good day !

Could you please advise (or give an example link), how to send data in csv format automatically to e-mail?

Thank you.