[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 477

 

demlin:
Еще вопрос: какой функцией можно вытащить стоимость одного пункта инструмента?

https://docs.mql4.com/ru/constants/marketinfo

MarketInfo(Symbol(), MODE_TICKVALUE);
 
LazarevDenis:

Please tell me which code should be written in the EA to make the EA trade only once an hour

For example, the EA has triggered, an order is opened (not interested in further), I would like the order not to open on the current bar on an hour timeframe

it all looks alike:

int hh;
int CurrentHour;
CurrentHour=TimeHour(TimeCurrent());
if (CurrentHour!=hh)
{
OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Bid-3*Point,Bid+3*Point);
hh=TimeHour(TimeCurrent());
}

but I have countless orders open

int hh = 0;
must be set before start() and init()
 
Guys, help me find an EA for manual trading in the tester on history. There are several in the codebase, I need one that was controlled by dragging the caption in the lower left corner of the nrafik. Very simple, can't find one. HistTraining and Visualisation Testing. Manual trading is not it. Very easy advisor, you could also set levels where testing stopped.
 
demlin:

Hello all!

Please tell me what this means:

Order buy ...... failed [Trade timeout]

I am specifically interested in what kind of timeout it is.

https://www.mql5.com/ru/forum/112612
This is an expired server response --- whether the deal opened or not. And there is no guarantee that the trade did not open.

So, I have to check if order is opened in a minute and then continue trading.

 

rlx:


needs to be set before start() and init()


int hh = 0;
int init()
{
return(0);
}
int start()
{
//-------------------------------------------------
int countorder;
countorder=OrdersTotal();
if (countorder==0)
{
Alert ("no open orders");
}else
{
Alert ("have open orders");
}
int hh;
int CurrentHour;
CurrentHour=TimeHour(TimeCurrent());
if ((CurrentHour!=h)&&(countorder==0))
{
OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Bid-3*Point,Bid+3*Point);
hh=TimeHour(TimeCurrent());
}
//-------------------------------------------------
return(0);
}

int deinit()
{
return(0);
}

I did as you said, no effect, added count of open orders, now opens orders right after close

I worked around it via OrderCloseTime() - it seems to work now

int countorder;
countorder=OrdersTotal();
if (countorder==0)
{
Alert ("no open orders");
}else
{
Alert ("have open orders");
}
int hh;
int CurrentHour;
int LastOrderCloseTime;
CurrentHour=TimeHour(TimeCurrent());


OrderSelect(HistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
hh=TimeHour(OrderCloseTime());


if ((CurrentHour!=hh)&&(countorder==0))
{
OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Bid-3*Point,Bid+3*Point);
}

 
rlx:

https://www.mql5.com/ru/forum/112612
This is the waiting period for the server to respond --- whether a trade has opened or not. And there is no guarantee that the deal has not opened.

Therefore, as recommended by the developers, check after one minute whether an order has opened and only then proceed.

Thanks for the answers
 
Roger:

I don't want to be a pain in the ass, however.

Explain to me how an order will open if OrderTotal() is zero.

Thank you.


Below is the figure with brackets limiting the block of code that is executed under the condition

if(OrdersTotal()>0&&tral>0&&OrderMagicNumber()==MAGIC&&(OrderType()==OP_SELL||OrderType()==OP_BUY))

OrderSend() operations are not affected by this condition.

 

how to get a bar number, in the "future" :)

iBarShift() works fine to get the bar number from the history, but how would you get the bar number for this code if you move the line to the right - beyond the zero bar?

static string name_vline = "linescr";
//________________________________________________
int init(){
   DrawLine(name_vline,Time[5],Red);
return(0);
}
//________________________________________________
int deinit() {
return(0);
}
//________________________________________________
int start(){
   datetime X;
   X = ObjectGet(name_vline,OBJPROP_TIME1);
   Comment("Координата X = ",iBarShift(NULL,0,X),"\n",
           "Время = ",TimeToStr(X));
return(0);
}
//________________________________________________
void DrawLine(string name, datetime tim, color cl){
   ObjectCreate(name, OBJ_VLINE, 0, tim, Close[0], tim, Close[0]);
   ObjectSet(name, OBJPROP_BACK  , false);
   ObjectSet(name, OBJPROP_COLOR, cl);
   ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);      
   ObjectSet(name, OBJPROP_WIDTH, 0);
}
 
IgorM:

how to get a bar number, in the "future" :)

iBarShift() works fine for getting the bar number from the history, but how can I get the bar number for this code if I shift the line to the right - beyond the zero bar?

You can get an offset relative to Time[0]

shift = MathRound((Time[0] - X) / (Period()*60));
 
rlx:

You can get an offset relative to Time[0]

Thank you! Everything is OK now!

static string name_vline = "linescr";
//________________________________________________
int init(){
   DrawLine(name_vline,Time[5],Red);
return(0);
}
//________________________________________________
int deinit() {
return(0);
}
//________________________________________________
int start(){
   datetime X;
   X = ObjectGet(name_vline,OBJPROP_TIME1);
   if(X<=Time[0])
         Comment("Координата X = ",iBarShift(NULL,0,X),"\n",  "Время = ",TimeToStr(X));
   else
         Comment("Координата X = ",MathRound((Time[0] - X) / (Period()*60)),"\n","Время = ",TimeToStr(X));
return(0);
}
//________________________________________________
void DrawLine(string name, datetime tim, color cl){
   ObjectCreate(name, OBJ_VLINE, 0, tim, Close[0], tim, Close[0]);
   ObjectSet(name, OBJPROP_BACK  , false);
   ObjectSet(name, OBJPROP_COLOR, cl);
   ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);      
   ObjectSet(name, OBJPROP_WIDTH, 0);
}