[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

 

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


in this function you probably count all orders.
 

How do I determine how many minutes there are between Time1 and Time2?

datetime Time_1     = D'2011.01.12 13:30';
datetime Time_2     = D'2011.01.05 10:30'; 

минут = Time_1- Time_2
 
sergeev:
this is probably the function where you count all orders. this should be Buy

This is a standard function:

int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}

if(buys>0) return(buys);
else return(-sells);

}

if >0 then it is a buy order, if <0 then it is a sell order ))))

 
Eliza:

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.

 
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.

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);
}
 
sergeev:

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?

extern datetime Time_1     = D'2011.01.12 13:30'; 
extern datetime Time_2     = D'2011.01.05 10:30'; 

bool   Commentari      = true;

int start()
  {

if (Commentari){
 Comment(
         "\n Дата  =  " + TimeToStr((Time_1-Time_2)/60)," минут",
      
         "\n==============================");}
   return(0);
  }
 
Eliza:

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.

 
sergeev:

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?

  • datetime is date and time, an unsigned integer that contains the number of seconds elapsed since 0 hours of January 1, 1970.
  • extern datetime Time_1     = D'2011.01.12 13:30'; 
    extern datetime Time_2     = D'2011.01.05 10:30'; 
    
    datetime me_2     = D'1970.01.01 00:00'; 
    
    bool   Commentari      = true;
    
    int start()
      {
    
    if (Commentari){
     Comment(
             "\n Дата  =  " + TimeToStr(me_2-(Time_1-Time_2))," минут",
          
             "\n==============================");}
       return(0);
      }

  • 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?
 

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