//+----------------------------------------------------------------------------+//| Возвращает номер бара открытия последней позиции или -1. |//| Параметры: |//| sym - наименование инструмента ("" - текущий символ) |//| tf - таймфрейм ( 0 - текущий таймфрейм) |//| op - операция (-1 - любая позиция) |//| mn - MagicNumber (-1 - любой магик) |//+----------------------------------------------------------------------------+intNumberOfBarOpenLastPos(stringsym="", inttf=0, intop=-1, intmn=-1){datetimeoot;
inti, k=OrdersTotal();
if(sym=="")sym=Symbol();
for(i=0; i<k; i++){if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){if(OrderSymbol()==sym){if(OrderType()==OP_BUY || OrderType()==OP_SELL){if(op<0 || OrderType()==op){if(mn<0 || OrderMagicNumber()==mn){if(oot<OrderOpenTime())oot=OrderOpenTime();
}}}}}}return(iBarShift(sym, tf, oot, True));
}
And to make it work, insert the line before the buy/sell :
if(NumberOfBarOpenLastPos(здесь сам всё расставь)>0){//если на текущ. баре не было сделок //хххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххif(Bid - iOpen(NULL,0,0)>=Delta*Point)//Цена выросла на больше или = Delta пунктов//продаем-{ticket=OrderSend(Symbol(),1,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,
"продал",MagicNumber,22222,Red);
if(ticket<0){Print("Ошибка открытия ордера SELL #",GetLastError());return(0);}}//-------------------------------------------------------------------------if(iOpen(NULL,0,0)-Bid >Delta*Point)//цена упала более дельты - покупаем{ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,
"Купил",MagicNumber,11111,Green);
if(ticket<0){Print("Ошибка открытия ордера BUY #",GetLastError());return(0);}}//ххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххххх}
That's how I did it, it compiled fine. There won't be any pitfalls?
//------------------------------
//+----------------------------------------------------------------------------+
//| Возвращает номер бара открытия последней позиции или -1. |
//| Параметры: |
//| sym - наименование инструмента ("" - текущий символ) |
//| tf - таймфрейм ( 0 - текущий таймфрейм) |
//| op - операция (-1 - любая позиция) |
//| mn - MagicNumber (-1 - любой магик) |
//+----------------------------------------------------------------------------+
int NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1) {
datetime oot;
int i, k=OrdersTotal();
if (sym=="") sym=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==sym) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (oot<OrderOpenTime()) oot=OrderOpenTime();
}
}
}
}
}
}
return(iBarShift(sym, tf, oot, True));
}
int start()
{
if (NumberOfBarOpenLastPos()>0)
if(OrdersTotal()!=0) return; //Выполнять только одну сделку.
//---
if (Ask - iOpen(NULL,0,0)>=Delta*Point) //Цена выросла больше Delta пунктов - продаем!!!
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Продал");
}
//-------------------------------------------------------------------------
if (iOpen(NULL,0,0)-Bid >=Delta*Point) //цена упала больше Delta пунктов - покупаем!!!
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"Купил");
}
//----
return(0);
}
And also, will this line in the code be redundant? :
if(OrdersTotal()!=0) return; //Выполнять только одну сделку.
Another mishap. Trying to make the above code work. An error appears in the log with the text: 18:38:23 '153085': order sell 1.00 GBPUSD opening at 2.0006 sl: 2.0019 tp: 2.0003 failed [Invalid S/L or T/P] What is the meaning of this?
salesman77: Again a problem. I am trying the above described code. An error appears in the log with the text: 18:38:23 '153085': order sell 1.00 GBPUSD opening at 2.0006 sl: 2.0019 tp: 2.0003 failed [Invalid S/L or T/P] What is the meaning of this?
1) And what DT do you use for MT4?
2) What is the allowable distance of stoploss and takeprofit in this brokerage house?
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.
Insert a function at the end of the code -
And to make it work, insert the line before the buy/sell :
and see what happens.Still mistakes... mistakes...
//------------------------------ //+----------------------------------------------------------------------------+ //| Возвращает номер бара открытия последней позиции или -1. | //| Параметры: | //| sym - наименование инструмента ("" - текущий символ) | //| tf - таймфрейм ( 0 - текущий таймфрейм) | //| op - операция (-1 - любая позиция) | //| mn - MagicNumber (-1 - любой магик) | //+----------------------------------------------------------------------------+ int NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1) { datetime oot; int i, k=OrdersTotal(); if (sym=="") sym=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==sym) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { if (oot<OrderOpenTime()) oot=OrderOpenTime(); } } } } } } return(iBarShift(sym, tf, oot, True)); } int start() { if (NumberOfBarOpenLastPos()>0) if(OrdersTotal()!=0) return; //Выполнять только одну сделку. //--- if (Ask - iOpen(NULL,0,0)>=Delta*Point) //Цена выросла больше Delta пунктов - продаем!!! { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Продал"); } //------------------------------------------------------------------------- if (iOpen(NULL,0,0)-Bid >=Delta*Point) //цена упала больше Delta пунктов - покупаем!!! { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"Купил"); } //---- return(0); }And also, will this line in the code be redundant? :Trying to make the above code work. An error appears in the log with the text:
18:38:23 '153085': order sell 1.00 GBPUSD opening at 2.0006 sl: 2.0019 tp: 2.0003 failed [Invalid S/L or T/P]
What is the meaning of this?
Again a problem.
I am trying the above described code. An error appears in the log with the text:
18:38:23 '153085': order sell 1.00 GBPUSD opening at 2.0006 sl: 2.0019 tp: 2.0003 failed [Invalid S/L or T/P]
What is the meaning of this?
1) And what DT do you use for MT4?
2) What is the allowable distance of stoploss and takeprofit in this brokerage house?