[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 69

 
Please, someone look at my previous post (on page 67). I can't find the error - pending orders are not being set.
 
nemo811:
Please, someone look at my previous post (on page 67). I can't find the error - pending orders are not being set.

There is no mistake. You should be more careful.

#property copyright "Copyright © 2010, Хлыстов Владимир"
#property link "cmillion@narod.ru"
#property show_inputs
//--------------------------------------------------------------------
extern int stoploss = 0; //уровень выставления SL, если 0, то SL не выставляется
extern int takeprofit = 0; //уровень выставления TP, если 0, то TP не выставляется
extern int Magic = 123456; //уникальный номер ордера
extern bool BUY = false; //открыть ордер BUY
extern bool SELL = false; //открыть ордер SELL
extern bool BUYSTOP = false; //открыть ордер BUYSTOP
extern bool SELLSTOP = false; //открыть ордер SELLSTOP
extern double Lot = 0.1; //объем ордера
extern int slippage = 3; //Максимально допустимое отклонение цены для рыночных ордеров
//--------------------------------------------------------------------
double SL,TP;
//--------------------------------------------------------------------
int start()
{
if (BUY)
{
if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0; 
OPENORDER ("Buy");
}
if (SELL)
{ 
if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Bid + stoploss*Point,Digits); else SL=0; 
OPENORDER ("Sell");
}
if (BUYSTOP)
{
if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0; 
OPENORDER ("Buy Stop");
}
if (SELLSTOP)
{ 
if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Bid + stoploss*Point,Digits); else SL=0; 
OPENORDER ("Sell Stop");
}
return(0);
}
//--------------------------------------------------------------------
void OPENORDER(string ord)
{
int error,err;
while (true)
{ error=true;
if (ord=="Buy" ) error=OrderSend(Symbol(),OP_BUY, Lot,NormalizeDouble(Ask,Digits),slippage,SL,TP,"BUY",Magic,0,Blue);
if (ord=="Sell") error=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,SL,TP,"SELL",Magic,0,Red);
if (ord=="BuyStop" ) error=OrderSend(Symbol(),OP_BUYSTOP, Lot,NormalizeDouble(Ask,Digits),SL,TP,"BUYSTOP",Magic,0,Blue);
if (ord=="SellStop") error=OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Bid,Digits),SL,TP,"SELLSTOP",Magic,0,Red);
if (error==-1) //неудачная покупка OK
{ 
ShowERROR();
err++;Sleep(2000);RefreshRates();
}
if (error || err >10) return;
}
return;
} 
//--------------------------------------------------------------------
void ShowERROR()
{
int err=GetLastError();
switch ( err )
{ 
case 1: return;
case 2: Alert("Нет связи с торговым сервером ",Symbol());return;
case 3: Alert("Error неправильные параметры ",Symbol());return;
case 130: Alert("Error близкие стопы Ticket ",Symbol());return;
case 134: Alert("Недостаточно денег ",Symbol());return;
case 146: Alert("Error Подсистема торговли занята ",Symbol());return;
case 129: Alert("Error Неправильная цена ",Symbol());return;
case 131: Alert("Error Неправильный объем ",Symbol());return;
case 4200:Alert("Error Объект уже существует ",Symbol());return;
default: Alert("Error ",err," ",Symbol());return;
}
}
//--------------------------------------------------------------------
 
gince:

There is no mistake. You need to be more careful


No, no, no, no. You're looking at the wrong post. There is another one just below :)). The version you have checked does not specify the level from the current price (only the current price) at which the pendulum should be set. Thank you for your feedback.
 
nemo811:

No, no, no. You have looked at a wrong post. There is another one just below :)). The version you have checked does not show the level from the current price (it only shows the current price), at which the pendentive should be set. Thank you for your feedback.

Something with the OPENORDER() function call or the function itself.

It works like this

if (BUYSTOP)

{

if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;

if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0;

int error=OrderSend(Symbol(),OP_BUYSTOP, Lot,NormalizeDouble(Ask + DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);

}

 
gince:

Something with the OPENORDER() function call or the function itself.

It works like this

if (BUYSTOP)

{

if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;

if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0;

int error=OrderSend(Symbol(),OP_BUYSTOP, Lot,NormalizeDouble(Ask + DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);

}


Aaaaaaaaaaah!!! Computer gods!!! I've been over it ten times! Why isn't it working?! The main thing is the market opens. The pending ones are written on exactly the same principle. What's it missing? :)))))))
 

Please advise how to insert TrailingStopFrCnSAR_v2 into Expert Advisor, which is described in the tutorial?

How do I disable order tracking, so that it works when another EA puts a pending order or opens an order?

 

Urrrrrrra!!!!!!!! Found the bug!

If anyone's interested, here's a working version:

#property copyright "Copyright © 2010, Khlystov Vladimir"
#p

roperty link "cmillion@narod.ru"
#property show_inputs
//--------------------------------------------------------------------
extern int stoploss = 0; //level of SL exposition, if 0, SL is not exposed
extern int int takeprofit = 0; //t TP level, if 0, TP is not exhibited
extern int int Magic = 123456; //number of an order
extern bool BUY = false; //open BUY order
extern bool SELL = false; //open SELL order
extern bool BUYSTOP = false; //open BUYSTOP order
extern bool SELLSTOP = false; //open SELLSTOP order
extern double Lot = 0.1; // order volume
extern int slippage = 3; //maximal allowed price deviation for market orders
extern int DistanceSet = 20; //Market distance
//--------------------------------------------------------------------
double SL,TP;
//--------------------------------------------------------------------
int start()
{
if (BUY)
{
if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0;
OPENORDER ("Buy");
}
if (SELL)
{
if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Bid + stoploss*Point,Digits); else SL=0;
OPENORDER ("Sell");
}
if (BUYSTOP)
{
if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0;
OPENORDER ("Buy Stop");
}
if (SELLSTOP)
{
if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Bid + stoploss*Point,Digits); else SL=0;
OPENORDER ("Sell Stop");
}
return(0);
}
//--------------------------------------------------------------------
void OPENORDER(string ord)
{
int error,err;
while (true)
{ error=true;
if (ord=="Buy" ) error=OrderSend(Symbol(),OP_BUY, Lot,NormalizeDouble(Ask,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Sell") error=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,SL,TP,",Magic,0);
if (ord=="Buy Stop" ) error=OrderSend(Symbol(),OP_BUYSTOP, Lot,NormalizeDouble(Ask + DistanceSet*Point,Digits),slippage,SL,TP,"",Magic,0);
if (ord=="Sell Stop") error=OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Bid - DistanceSet*Point,Digits),slippage,SL,TP,",Magic,0);
if (error==-1) //failure
{
ShowERROR();
err++;Sleep(2000);RefreshRates();
}
if (error || err >10) return;
}
return;
}
//--------------------------------------------------------------------
void ShowERROR()
{
int err=GetLastError();
switch ( err )
{
case 1: return;
case 2: Alert("No connection to the trade server ",Symbol());return;
case 3: Alert("Error incorrect parameters ",Symbol());return;
case 130: Alert("Error close Ticket stops ",Symbol());return;
case 134: Alert("Not enough money ",Symbol());return;
case 146: Alert("Error Trade Subsystem is busy ",Symbol());return;
case 129: Alert("Error Wrong price ",Symbol());return;
case 131: Alert("Error Incorrect volume ",Symbol());return;
case 4200:Alert("Error Object already exists ",Symbol());return;
default: Alert("Error ",err," ",Symbol());return;
}
}
//--------------------------------------------------------------------

Thanks so much to everyone who took part in the discussion!!! Nowhere without you! :)))))

 
nemo811:

Urrrrrrra!!!!!!!! Found the mistake!


Huge thanks to everyone who took part in the discussion!!! Nowhere without you! :)))))

you still have an error in your code.

Remember: stops and takes in pending orders are not counted from the current price, but from the opening price of the order.

 

HELP! Please tell me, if I close part of a position (eg order for 1 lot, and close 0.5 lots) OrderClose ticket should change? My tester says it does... How to avoid it? Below is a piece of closing code...

1 2011.01.31 06:57 sell 1 2.55 1.36177 0.00000 0.00000 0.00 10000.00
2 2011.01.31 08:10 close 1 0.51 1.36039 0.00000 0.00000 70.38 10070.38
3 2011.01.31 08:10 sell 2 2.04 1.36177 0.00000 0.00000 0.0000 10070.38
4 2011.01.31 08:10 close 2 0.40 1.36038 0.00000 0.00000 55.60 10125.98
5 2011.01.31 08:10 sell 3 1.64 1.36177 0.00000 0.00000 0.00000 10125.98

Another question: I want to split my order into 4 parts and close each of them when Cls_S==true triggered. I tried to use counter... Doesn't work...

Can anyone give me an idea?

Thanks in advance!!!!

if (Tip==1 && ((Cls_S0==true&&TotClS==0)||(Cls_S1==true&&TotClS==1)
||(Cls_S2==true&&TotClS==2)||(Cls_S3==true&&TotClS==3)) // A Sell order is open.
{ // and there is a criterion to close it
Alert("Attempting to close 0.2 Lot Sell ",Ticket,". Waiting for reply...");
RefreshRates(); // Refresh data
Ans=OrderClose(Ticket,LotCt,Ask,5);

if (Ans==true) // It worked :)
{
TotClS++;
Alert ("Closed 0.2 Lot Sell ",Ticket);
break; // Exit from closed loop
}
if (Fun_Error(GetLastError())==1) // Error handling
continue; // Retry
return; // Exit from start()
}
break; // Exit while

 
gince:
I made a temporary drawing of flag[] buffer - it's empty, but why? Where is my error?
I don't know. Sergeev knows, he said it seems to be right. I would also like to see how to write it correctly.
I've just corrected it a bit, so that it shows something.
- I put the indicator in a separate window, then you can put it back

- array macd[] was hanging in the air, made it an indicator, increased accuracy
- fixed your complex condition to open, put a simple one for adjustment
- changed the condition for the flag, so at least it works.

Then you can gradually introduce conditions, you will immediately see where the bug is.

Files:
Reason: