Reverse the transaction. Changed the structure of the Expert Advisor - removed the functions. How to make it close and open on one candle under certain conditions.
if i subtract the date 1970.01.01 02:51 it throws out that invalid time, i just need the number of minutes to get from this time interval, if its for example 25000 minutes in this interval i need this number 25000 ... something like that(
or is it not possible to get this by the μl language?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Good day/night
I am trying to reverse a trade using this primitive method which does not work (the calculation in the Expert Advisor is based on ticks):
if(CalculateCurrentOrders(Symbol())>0 && Close[1]<LowLevel) // determines if there were buy orders && if a candle closed below the lower level
{
CheckForClose(); // close the order
OpenSell(); // open a sell order
return;
}
Please advise where I am going wrong? I would also be grateful for links that would allow me to close this gap.
dzhini:
I am trying to reverse trade in this primitive way, which does not work (the Expert Advisor calculates by ticks):
if(CalculateCurrentOrders(Symbol())> 0 && Close[1]<LowLevel) // it checks if there were buy orders && if a candle closed below the bottom level
How do I determine how many minutes there are between Time1 and Time2?
this is probably the function where you count all orders. this should be Buy
This is a standard function:
int CalculateCurrentOrders(string symbol)}
if >0 then it is a buy order, if <0 then it is a sell order ))))
How do I determine how many minutes are there between Time1 and Time2?
the difference returns the number of seconds.
divide by 60. you get the number of minutes.
extern double TP = 70; //takeprofit
extern double SL = 0; //stoploss
extern double Lot = 0.1;
double HighLevel;
double LowLevel;
int resBuy=0;
int resSell=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
HighLevel=High[1];
LowLevel=Low[1];
return;
}
//+------------------------------------------------------------------+
//| expert function |
//+------------------------------------------------------------------+
void start()
{
if(Bars<100 && IsTradeAllowed()==false) return;
if(resBuy==0 && resSell==0 && CheckBreak()==-1)
{
resSell=OrderSend(Symbol(),OP_SELL,Lot,Bid,2,0,Bid -TP,"",MAGICMA,0,Red);
HighLevel=LowLevel;
LowLevel=Close[1];
return;
}
if(resBuy==0 && resSell==0 && CheckBreak()==-1& CheckBreak()==1)
{
resBuy=OrderSend(Symbol(),OP_BUY,Lot,Ask,2,0,Ask + TP,"",MAGICMA,0,Blue);
LowLevel=HighLevel;
HighLevel=Close[1];
return;
}
if(resBuy!=0 && resSell==0 && Close[1]<LowLevel) //------------------------------------- interested in this part: closing and opening on one bar
{
bool closeBuy=OrderClose(resBuy, Lot, Bid, 2, Blue);
// while(!IsTradeAllowed()) Sleep(100);
resSell=OrderSend(Symbol(),OP_SELL,Lot,Bid,2,0,Bid -TP,"",MAGICMA,0,Red);
HighLevel=LowLevel;
LowLevel=Close[1];
return;
}
if(resSell!=0 && resBuy==0 && Close[1]>HighLevel) //------------------------------------- interested in this part: closing and opening on one bar
{
bool closeSell=OrderClose(resSell, Lot, Ask, 0.0002, Red);
// while(!IsTradeAllowed()) Sleep(100);
resBuy=OrderSend(Symbol(),OP_BUY,Lot,Ask,2,0,Ask + TP,"",MAGICMA,0,Blue);
LowLevel=HighLevel;
HighLevel=Close[1];
return;
}
}
//----------------------------------------------------------------- Check Low&High break (Func)
double CheckBreak()
{
double candle=Open[1]-Close[1];
if(candle>0 && Low[1]<LowLevel) return(-1);
if(candle<0 && High[1]>HighLevel) return(1);
}
difference returns the number of seconds.
divide by 60. it gives the number of minutes.
I just get the date 1971.03.04 12:00, maybe this needs to be converted?
I just get the date, maybe it needs to be converted?
First of all, why are you multiplying by 60?
Second - if you want to display the number of minutes as a time like 00:15,
you don't have to divide or multiply by 60.
First of all, why are you multiplying by 60?
Secondly - if you want to represent the number of minutes on the screen as a time like 00:15,
there's no need to divide or multiply by 60.
Yes, I corrected for division, but the year comes out 1970.01.01 02:51
I don't need it for the screen, I just wanted to find the number of minutes without dates, for that time interval....
even without dividing, it still outputs the date, or should I subtract the date from which the function is based on?
If you just want a number of minutes, you have absolutely no reason to use TimeToStr
Time is a normal int number.
Or alternatively, use TimeToStr only with TIME_MINUTE flag