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

 

Hi all

Please advise, why does scoop buy, but when the conditions are ripe does not close the position

/---- input parameters
extern int PerRSI=8;
extern int MagicNamber=77771;
extern double Lots=1.0;
//+------------------------------------------------------------------+
int start()
{
int
cnt, // order index
ticket, // order identification number
total; // number of orders already opened
double
rsi_0, // Value. rsi_0 current
rsi_1; // Value. rsi_1 1st bar
if (Bars<100)
{
Print("bars less than 100");
return(0);
}
total=OrdersTotal();
if(total<1)
{
rsi_0=iRSI(NULL,0, PerRSI,0,0); // Current bar
rsi_1=iRSI(NULL,0, PerRSI,0,1); // Current bar plus 1

if(rsi_0 < rsi_1 && rsi_0 < 30) // If line has crossed 30
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0, "My RSI", MagicNamber,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice())
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_BUY && OrderSymbol()==Symbol()) // is this an open position? OP_BUY or OP_SELL
{
if(OrderType()==OP_BUY) // long position opened
{
if(rsi_0 > rsi_1 && rsi_0 > 70) // if line has crossed 70
{
OrderClose(OrderTicket(),1,Bid,3,Violet); // close position

return(0); // exit
}}}}}}
 
KoZaNOStra >> :

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0, "My RSI", MagicNamber,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice())
}


What the hell is this? What is OrderSelect() for?


The rest is difficult to understand because the code is laid out without indents and one cannot follow parentheses - I don't want to spoil my vision.

 
How do I decolorise the chart to show the movement of the trailing edge ?
 
anat писал(а) >>

Thank you very much for all your help! And also to condor - y. Now there is another problem. We have, for example, opened 10 buy positions. When we close 1, 2, 3, etc. positions using stop or take, the Expert Advisor starts buying, if there is a signal to buy. But I need ALL orders to be closed first, and then, when there is no one open position, a new trading cycle will start. In other words, we need a counter. First open positions to a given number, and then, when the positions are closed, to zero. I would like to thank in advance.

It is exactly the way it is done now. As long as there is at least one open order, another one will not open. If you want to do otherwise, you have to be more precise. Then you have to choose - whether your orders are opened if there are open positions or not.

 

Here's a question:

Are there any debugging tools in MetaTrader ?

Please share your experiences - how do you debug scripts and EAs?

It's all about digits, parameters, visions of algorithms and so on. How do you catch bugs in the algorithm?

 
Ryan_ryan >> :

Here's a question:

Are there any debugging tools in MetaTrader ?

Please share your experiences - how do you debug scripts and Expert Advisors?

If I need to do debugging, I do it through Print()

But in most cases such a need does not arise.

 

RefreshRates();
if(OrderType()==OP_SELL && OrderMagicNumber()==mnum
bool sellclose = OrderClose(OrderTicket(),OrderLots(),Ask,3,YellowGreen);
if (sellclose)
{
PlaySound("money.wav");
}
else
{
Print("Ошибка : ",Error(GetLastError()));
PlaySound("timeout.wav");
}

Can you please tell me why in this design after closing an order "timeout.wav" sounds first, "no error" equal to the number of orders to be closed (if 2 orders are closed, "no error" will pop up twice, etc.), and then "money.wav" sounds. The funny thing is that this is only for short trades, for long trades everything works fine. Who knows what the trick is and how to fix it?

 
Dimoncheg писал(а) >>

RefreshRates();
if(OrderType()==OP_SELL && OrderMagicNumber()==mnum
bool sellclose = OrderClose(OrderTicket(),OrderLots(),Ask,3,YellowGreen);
if (sellclose)
{
PlaySound("money.wav");
}
else
{
Print("Ошибка : ",Error(GetLastError()));
PlaySound("timeout.wav");
}

Can you please tell me why in this design after closing an order "timeout.wav" sounds first, "no error" equal to the number of orders to be closed (if 2 orders are closed, "no error" will pop up twice, etc.), and then "money.wav" sounds. The funny thing is that this is only for short trades, for long trades everything works fine. Who knows what the trick is and how to fix it?

Isn't bracket after first if closed?

if(OrderType()==OP_SELL && OrderMagicNumber()==mnum

This line somehow falls out.

 
Dimoncheg >> :

RefreshRates();
if(OrderType()==OP_SELL && OrderMagicNumber()==mnum
bool sellclose = OrderClose(OrderTicket(),OrderLots(),Ask,3,YellowGreen);
if (sellclose)
{
PlaySound("money.wav");
}
else
{
Print("Ошибка : ",Error(GetLastError()));
PlaySound("timeout.wav");
}

Can you please tell me why in this design after closing an order "timeout.wav" sounds first, "no error" equal to the number of orders to be closed (if 2 orders are closed, "no error" will pop up twice, etc.), and then "money.wav" sounds. The funny thing is that this is only for short trades, for long trades everything works fine. Who knows what the trick is and how to fix it?


The condition in the first conditional "if" operator affects only the next operator following it (the next line).

The others are executed UNLESS the order is closed. I.e. even if there is no command to close the order, one of the playsounds will work.

The correct way is this:

  RefreshRates();
  if(OrderType()==OP_SELL && OrderMagicNumber()== mnum) 
  {
     bool sellclose = OrderClose(OrderTicket(),OrderLots(),Ask,3,YellowGreen);  
     if ( sellclose) 
        PlaySound("money.wav");
     else 
     {
        Print("Ошибка : ", Error(GetLastError()));
        PlaySound("timeout.wav");  
     }
  }
 
infinum13 >> :

Isn't the bracket closed after the first if ???

if(OrderType()==OP_SELL && OrderMagicNumber()==mnum

This line somehow falls out

If(OrderType()==OP_SELL && OrderMagicNumber()==mnum then falls out, but works the trick on short and long transactions, but the error "No error" with sound "timeout.wav" works only for short trades, for long trades it works fine, there are the same brackets and everything is the same

Reason: