You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
..........
ticket=OrderSend(.....);//приказ и запоминаем тикет ордера
if(ticket>0)//открылась
{
//действия с тикетом
}
More accurate would be:
{
//действия с тикетом
}
OrderSend - "Returns the ticket number assigned to the order by the trade server or -1 in case of failure ."
Although even in the tester the first ticket number is 1, not 0.
More accurately, it will be:
{
//действия с тикетом
}
OrderSend - "Returns the ticket number assigned to the order by the trade server or -1 in case of failure ."
Although even in the tester the first ticket number is 1, not 0.
So glad to see the missing Oksana ))
Yes, the tickets start with 1 in the tester and on the DC server, but you will never catch 1 in DC. Your version is not quite working, it is not correct to compare inequality with -1. What if the real account returns 1234567?
{
//действия с тикетом
}
// так верно
So in the tester a ticket cannot be less than one, even more so in the real world
zero is less than one, both conditions are correct, only one for comparison, the other for exclusion.
Although I got used to do so:
int ticketbuy = OrderSend(sy,OP_BUY,ll,MarketInfo(sy,MODE_ASK),Slippage,0,0,Comments,mn,0,BuyColor);
if(ticketbuy<0)
Print(sy," OpenPosition. OrderSend Buy fail #",GetLastError());
else
Print(sy," OpenPosition. OrderSend Buy successfully");
But considering mine, the conditions are all correct, only the logic is different)
{
bool ret;
int error=0;
double price=0.0;
int total=OrdersTotal();
if(!disabled(_Symbol))
{
Print(rezult);
return;
}
for(int i=total-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS))continue;
if(OrderSymbol()!=_Symbol)continue;
if(OrderMagicNumber()!=Magic)continue;
if(OrderType()>1)continue;
if(OrderType()!=type)continue;
int digits=(int)SymbolInfoInteger(OrderSymbol(),SYMBOL_DIGITS);
if(OrderType()==OP_BUY)price=NormalizeDouble(SymbolInfoDouble(OrderSymbol(),SYMBOL_BID),digits);
if(OrderType()==OP_SELL)price=NormalizeDouble(SymbolInfoDouble(OrderSymbol(),SYMBOL_ASK),digits);
if(NormalizeDouble(NormalizePrice(OrderSymbol(),price),digits)!=price)continue;
ret=OrderClose(OrderTicket(),OrderLots(),price,Slippage,clrLawnGreen);
if(!ret)
{
error=GetLastError();
rezult=StringConcatenate(OrderSymbol(),": error close order ",OrderTicket()," ",DoubleToString(OrderLots(),2)," ",TypeToStr(OrderType())," №- ",error," ",ErrorDescription(error));
Print(rezult);
}
else
{
rezult=StringConcatenate(OrderSymbol(),": close order ",OrderTicket()," ",DoubleToString(OrderLots(),2)," ",TypeToStr(OrderType()));
Print(rezult);
}
}
}
i wish you a Happy New Year! Could you please tell me what is wrong with this code?
I advise to change the logic at the root
I.e. it's necessary to keep records of open orders - how many sells and how many baiks are opened
And then based on these considerations we should manage orders - open and close them
I do not know why the EA opens a lot of orders if the condition should not be for opening a position but after opening it opens again.
i can't understand why my EA opens a lot of orders if i don't want it to open a position but it opens again after i open it, i suspect i have something wrong with the loop, i don't really understand the loops
for(int i=OrdersTotal()-1;i>=0;i--)
if(OrderSelect(i,SELECT_BY_POS))
if(OrderMagicNumber()==magic) // if our Magic
{
if(OrderType()==OP_BUY) sdel_b++; // count bai
if(OrderType()==OP_SELL) sdel_s++; // Count sels
if(OrderType()==OP_BUYSTOP) otl_b++; // Count pending bystops
if(OrderType()==OP_SELLSTOP) otl_s++; // Count pending sellstops
}
// now open orders
if(Hour()==00 && Minute()==01 && otl_b==0 && otl_s ==0); // If it is time and there are no pending orders
{
OrderSend (Symbol(),OP_BUYSTOP,lot,Vhod1,20,SL2,TP,NULL,magic,0,clrNONE); // put a pending order
OrderSend (Symbol(),OP_SELLSTOP,lot,Vhod2,20,SL,TP2,NULL,magic,0,clrNONE); //
}
I do not know why the EA opens a lot of orders if the condition should not be for opening a position but after opening it opens again.
I do not understand why my EA opens many orders, if I don't want it to open a position but it opens again after opening. I think I may be wrong with the loop, I don't really understand the loops
for(int i=OrdersTotal()-1;i>=0;i--)
if(OrderSelect(i,SELECT_BY_POS))
if(OrderMagicNumber()==magic) // if our Magic
{
if(OrderType()==OP_BUY) sdel_b++; // count bai
if(OrderType()==OP_SELL) sdel_s++; // Count sels
if(OrderType()==OP_BUYSTOP) otl_b++; // Count pending bystops
if(OrderType()==OP_SELLSTOP) otl_s++; // Count pending sellstops
}
// now open orders
if(Hour()==00 && Minute()==01 && otl_b==0 && otl_s ==0); // If it is time and there are no pending orders
{
OrderSend (Symbol(),OP_BUYSTOP,lot,Vhod1,20,SL2,TP,NULL,magic,0,clrNONE); //take a position
OrderSend (Symbol(),OP_SELLSTOP,lot,Vhod2,20,SL,TP2,NULL,magic,0,clrNONE); //
}
Try this
sdel_s=0;
otl_b=0;
otl_s=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS))
{
if(OrderMagicNumber()==magic) // Если наш Меджик
{
if(OrderType()==OP_BUY) sdel_b++; // Считаем баи
if(OrderType()==OP_SELL) sdel_s++; // Считаем селы
if(OrderType()==OP_BUYSTOP) otl_b++; // Считаем отложенные байстопы
if(OrderType()==OP_SELLSTOP) otl_s++; // Считаем отложенные селлстопы
}
}
}
Try this
sdel_s=0;
otl_b=0;
otl_s=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS))
{
if(OrderMagicNumber()==magic) // Если наш Меджик
{
if(OrderType()==OP_BUY) sdel_b++; // Считаем баи
if(OrderType()==OP_SELL) sdel_s++; // Считаем селы
if(OrderType()==OP_BUYSTOP) otl_b++; // Считаем отложенные байстопы
if(OrderType()==OP_SELLSTOP) otl_s++; // Считаем отложенные селлстопы
}
}
}
Still opens a lot of orders
Greetings. Happy New Year to all!
When I try to optimise an EA after it has been run, the results and the optimisation graph are blank and the log is written in the log:
There were 2passesdone during optimization, 2 results have been discarded as insignificant
unchecking"genetic algorithm" does not help. I understand that the results seem insignificant to the tester, but how can we see what is there? And this is despite the fact that the Expert Advisor does not lose money for the same period (a year) during testing, but it is +/- 20%.