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

 
and on re-opening the trade - the result is repeated with a constant difference of 1pp. !!!! i.e. whatever the profit of the last trade - the first option is printed by 1 more than the second!
 
lottamer:


yes that's how this point is well known to me...

please write a piece requesting the last week's ticket from the history...and I'll catch the logic from it...



int fLastClosetPoz()
{
int Tot=OrdersHistoryTotal(),Ticket=-1; datetime time=0;
if(Tot>0)
{
for(int i=0;i<OrdersHistoryTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
{
if(OrderSymbol()==Symbol())
{
if(OrderCloseTime()>time)
{
time=OrderCloseTime();Ticket=OrderTicket();
}
}
}
else continue;
}
}
return(Ticket);
}

 
lottamer:

MISTIC!!!

this one

-----------------------------------------------------------------------------


pp_sell=(-(PriceOpenLastClosePos()-PriceCloseLastPos())*100000); // for currencies with EUR dimension


Print (pp_sell);

------------------------------------------------------------------------------------

Prints -10, as it should be, since the last SELL trade has a profit of 10

but if you insert several DIFFICULT TIMES BETWEEN PRINT AND VARIABLE, e.g.

----------------------------------------------------------------------------


pp_sell=(-(PriceOpenLastClosePos()-PriceCloseLastPos())*100000); // for currencies with EUR dimension


if ( Hour()>=10 && Hour()<20)

{

if ( Stoch_1>Stoch_2) return(0);

else {

if (OrdersTotal()==0)

{ PlaySound("ok.wav");

if ( GetTypeLastClosePos()==1) Print (pp_sell);

}

Print("___");

}

}

return(0);

}

------------------------------------------------------------------------------------

it works, but prints -9 !!!!

what's the secret?


In such cases, calculation inaccuracies accumulate and may eventually become significant. You think you insertNOTHING CHANGEING CONDITIONS, in fact you force the computer to make unnecessary calculations and your conditions doNOTHING CHANGEING.

And are you sure thatPriceOpenLastClosePos() and PriceCloseLastPos() are setting values for the same position?

 
rigonich:


int fLastClosetPoz()

{
int Tot=OrdersHistoryTotal(),Ticket=-1; datetime time=0;
if(Tot>0)
{
for(int i=0;i<OrdersHistoryTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
{
if(OrderSymbol()==Symbol())
{
if(OrderCloseTime()>time)
{
time=OrderCloseTime();Ticket=OrderTicket();
}
}
}
else continue;
}
}
return(Ticket);
}


starting with if(OrderCloseTime()>time)... then it's not clear where it's coming from... well, never mind...

It prints a ticket, but only the last one. And what to do with the penultimate? I just can't see how the second ticket can be printed?

first i just write Print LastClosetPoz()

take the 2nd (i) ? OrderSelect(2,SELECT_BY_POS,MODE_HISTORY)....?

Print LastClosetPoz(2) ?? obvious mistake, but would be logical :)))

I try to put other parameters of a closed position( closeprices of a stop position) instead of OrderTicket in the Ticket=OrderTicket(); line - does not work.

 
rigonich:

You are working withnon-normalized values like double. In such cases, the calculation inaccuracies accumulate and may eventually become significant.


Isn't it fat for a computer to accumulate as much as 10% error in 4 lines? :))))))))))) (in large numbers less than 10%)

1) what is there to save if the closed order is fixed and all its parameters "do not float"?

2) The conditions were in no way related to the calculation of the output parameter. They were just a barrier -let go-not let go...

3) And why then does the result not float within the work of one EA, but floats from one to another?

 
lottamer:


starting with if(OrderCloseTime()>time)... then it's not clear where it's coming from...but okay...

It prints a ticket, but only the last one. And what to do with penultimate? i just don't see how to do it with second ticket?

take 2nd (i) ? OrderSelect(2,SELECT_BY_POS,MODE_HISTORY)....?

1. please write a piece with ticket request from history.-your question.

To find the penultimate one, we have to memorize the ticket of the latest one (e.g. in the variable A), then it needs to run the loop one more time and "skip" this order, i.e. e.g. change the line

if(OrderSymbol()==Symbol()) toif(OrderSymbol()==Symbol()&& OrderTicket()!=A), or add a lineif(Ticket()!=A)continue;

And I have already explained that the order index will not always coincide with the one closed in the account, since market and pending orders are taken into account together and the latter ones do not have a closing price, that is why all orders are looped to find the last closed one and the order with the longest closing time is looked through. That is the last closed order might have index 3 and the last but one - 7.

 
rigonich:

1. please write a piece requesting a ticket for the last week of the story...-your question.

In order to find the penultimate one, we should memorize the ticket of the last ticket (for example, in variable A), then we should run the loop one more time and "skip" this order, i.e. change the line

if(OrderSymbol()==Symbol()) toif(OrderSymbol()==Symbol()&& OrderTicket()!=A), or add a lineif(Ticket()!=A)continue;


leading question:

what for(int i=0;i<OrdersHistoryTotal();i++) we need exactly OrdersHistoryTotal() when, for example, I need only 2 trades?

How about this

or(int i=0;i<2;i++) ? (checked - ticket =-1....) nda.....tuman...:)))

 
lottamer:


leading question:

but why do we need the line for(int i=0;i<OrdersHistoryTotal();i++) we need exactly OrdersHistoryTotal() when, for example, I need only 2 trades?

How about this

or(int i=0;i<2;i++) ? (checked - ticket =-1....) nda.....tuman...:)))


I finished the previous comment, see. Also, I wrote you a code looking for the last closed trade on the current instrument.
 
Help me if I decided to write a robot in C/C++, for example. It's not a problem to write one, but how do I connect it with metatrader? How to get quotes and how to send a buy/sell signal back?
 
Desead:
Help me if I decided to write a robot in C/C++, for example. It's not a problem to write one, but how do I connect it with metatrader? How to get quotes and how to send a buy/sell signal back?

I don't know any other languages, but it may be possible to write your code as DLL and then it may be possible to call from MQL programs.