Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 434

 
I am writing an EA and am currently facing this problem. I have 13 calculated variables (price values on the chart are essentially levels). For example, the price is currently between two adjacent levels (support and resistance) and how to determine which ones and return their values?
 

I can't figure out why my orders are not closing and the log shows error 4051 "invalid ticket for OrderClose function".


if (Total>0)

{
for(cnt=0;cnt<Total;cnt++)

{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
{
if (OrderType() == OP_BUY)
{
if(a<b)
{
OrderClose(cnt,1,Bid,3,Red);
return(0);
}
}


else
{
if(a>b)
{
OrderClose(cnt,1,Ask,3,Red);
return(0);
}
}
}
}
}
 
hmpr:

I can't figure out why my orders aren't closing and the log shows error 4051 "invalid ticket for OrderClose function".


for(cnt=Total-1;cnt>=0;cnt--)

IMHO else is unnecessary there, and I don't have to put any returnees...

Oh, and it wouldn't hurt to clearly specify position type for sales too, they can be not only buy and sell.

 
hmpr:

I can't figure out why I don't close orders, and the log shows error 4051 "invalid ticket for OrderClose function".

not

OrderClose(cnt,...)

а

OrderClose(OrderTicket(),...)

 
How can I insert the slope of a moving average into an EA, for example I am interested in the trend if the slope is more than 20 degrees?
 
Profitov:
How can I insert the slope of a moving average into an EA, for example I am interested in the trend if the slope is more than 20 degrees?

By the time a trend is formed on the MA, the market has already started a flat)))
 
Profitov:
How can I insert the slope of a moving average into an EA, for example I am interested in the trend if the slope is more than 20 degrees?

double ObjectGet(string name,13)
 
vadynik:

So it will only give you the opportunity to perform an action in time, not when the tick comes, as I understand it, and I need to put the owl to sleep in the tester after the condition...

To set the start time of sleep and its duration. As long as the sleep condition is fulfilled by time - do nothing (return)
 
Profitov:
And how can I insert into an EA the slope of a moving average e.g. I am interested in the trend if the slope is more than 20 degrees?
The slope of a curve is its first derivative, which is equal to (X0-Xn)/n for a moving average, if the MA is overdrawn. Measured not in degrees, but in pts/bar, or something similar.
 

Can I write variable values to an array in this way?

double A[13] = {R3,M5,R2,M4,R1,M3,P,M2,S1,M1,S2,M0,S3};
Reason: