[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 1121
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
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