An advisor that would follow the rate on a five-minute chart with conditions after launch: - page 13

 
rid:
salesman77:
Again a mishap.
I'm 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?


1) And what MT4 do you use?

2) What is the allowed stoploss and takeprofit distance in this brokerage house?

http://www.forex4you.org/
Before that, yesterday with these parameters t/r and s/l all worked :(((
 
rid:
int start()
I would do this...
It doesn't work that way, the conditions are there - the deals don't work. The log is silent :(
 
Put the whole code here. And check with the DC there - the allowable distance of stops from the price.
 

Contract specifications



Symbol Name 1 lot for micro
(for mini *100)
Margin (margin)
for micro
(for mini *100)
Spread Limit & Stop
levels
gap level

Swap
buy
Swap
sale
EURUSD EUR to USD EUR 1000 EUR 10 2 2 8 0.15 -0.51
GBPUSD GBP/USD GBP 1000 GBP 10
3 3 12 0.80 -1.52
 
And here's the whole code:
//+------------------------------------------------------------------+
//|                                                Expert-000001.mq4 |
//|                                    Copyright © 2008, salesman*** |
//|                                         http://www.forexgrand.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, salesman***"
#property link      "http://www.forexgrand.ru"

//----
extern string _Parameters_b_Lots = "Параметры модуля расчёта лота";
extern int LotsWayChoice  = 0;     // Способ выбора рабочего лота
                                  //  0-фиксированный,
                                  //  1-процент от депозита,
                                  //  2-фракционно-пропорциональный,
                                  //  3-фракционно-фиксированный,
//extern int LotsPercent   = 40;   // Процент от депозита
extern double StopLoss=13;                               // Stop Loss
extern double TakeProfit=3;                              // Take Profit
//extern int Percent=70;
extern double Lots=1;                                  // Объем сделки в %
extern double Slippage =4;                               // Максимальное отклонение от запрошенной цены
extern int MagicNumber=0;                                // Order ID
extern int Delta=15;                                     // Сигнал приказа в пунктах
//extern int TimeForSleep = 0;                           // Время для отдыха после сделки
extern int  ticket;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }

int start()
{
int total=OrdersTotal();
   if(total<1)                           {// если нет открытых позиций
if (NumberOfBarOpenLastPos("", 0,  -1, MagicNumber)>0){
 
//---
 
if (Ask - iOpen(NULL,0,0)>=Delta*Point) //Цена выросла  больше Delta пунктов - продаем!!!
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Продал");
if(ticket<0){Print("Ошибка открытия ордера SELL #",GetLastError());return(0);}
 
 }
//-------------------------------------------------------------------------
 
if (iOpen(NULL,0,0)-Bid  >=Delta*Point) //цена упала больше Delta пунктов - покупаем!!!
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"Купил");
if(ticket<0){Print("Ошибка открытия ордера BUY #",GetLastError());return(0);}
 }
//----
} //if (NumberOfBarOpenLastPos
}//if(OrdersTotal
return(0);
}
//------------------------------
 //+----------------------------------------------------------------------------+
//|  Возвращает номер бара открытия последней позиции или -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));
}

 

There seems to be something wrong with the line

if (NumberOfBarOpenLastPos("", 0,  -1, MagicNumber)>0){

Without this condition, the Expert Advisor works...

Why did you put some parameters there to calculate the lot? You don't need it...

 

//+------------------------------------------------------------------+
//|                                                Expert-000001.mq4 |
//|                                    Copyright © 2008, salesman*** |
//|                                         http://www.forexgrand.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, salesman***"
#property link      "http://www.forexgrand.ru"
 
//----
extern double StopLoss=13;                               // Stop Loss
extern double TakeProfit=3;                              // Take Profit
//extern int Percent=70;
                               
extern double Slippage =4;                               // Максимальное отклонение от запрошенной цены
extern int MagicNumber=111111;                                // Order ID
extern int Delta=15;                                     // Сигнал приказа в пунктах
 
 int  ticket;
//-- Подключаемые модули --
#include  <b-Lots.mqh> 
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
And put the b-lots library itself in the iclude folder

And before each OrderSend function insert

  Lots=GetSizeLot(); 
  ticket=OrderSend(Symbol(... ...

 
rid:
Put the b-lots library itself in the iclude folder

And before each OrderSend

function insert
  Lots=GetSizeLot(); 
  ticket=OrderSend(Symbol(... ...
I did it all but the compiler generates one error:
'Lots' - variable already defined C:\Program Files\MetaTrader - E-Global TFG\experts\expert-001.mq4 (21, 15)
Here is the code:
//+------------------------------------------------------------------+
//|                                                Expert-001.mq4 |
//|                                    Copyright © 2008, salesman*** |
//|                                         http://www.forexgrand.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, salesman***"
#property link      "http://www.forexgrand.ru"
#include  <b-Lots.mqh> 
#include <stdlib.mqh>
//----
//extern string _Parameters_b_Lots = "Параметры модуля расчёта лота";
//extern int LotsWayChoice  = 0;     // Способ выбора рабочего лота
                                  //  0-фиксированный,
                                  //  1-процент от депозита,
                                  //  2-фракционно-пропорциональный,
                                  //  3-фракционно-фиксированный,
//extern int LotsPercent   = 40;   // Процент от депозита
extern double StopLoss=13;                               // Stop Loss
extern double TakeProfit=3;                              // Take Profit
//extern int Percent=70;
extern double Lots=0.9;                                  // Объем сделки в %
extern double Slippage =4;                               // Максимальное отклонение от запрошенной цены
extern int MagicNumber=0;                                // Order ID
extern int Delta=15;                                     // Сигнал приказа в пунктах
//extern int TimeForSleep = 0;                           // Время для отдыха после сделки
extern int  ticket;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }

int start()
{
int total=OrdersTotal();
   if(total<1)                           {// если нет открытых позиций
if (NumberOfBarOpenLastPos("", 0,  -1, MagicNumber)>0){
 
//---
 
if (Ask - iOpen(NULL,0,0)>=Delta*Point) //Цена выросла  больше Delta пунктов - продаем!!!
{
Lots=GetSizeLot(); 
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Продал");
if(ticket<0){Print("Ошибка открытия ордера SELL #",GetLastError());return(0);}
 
 }
//-------------------------------------------------------------------------
 
if (iOpen(NULL,0,0)-Bid  >=Delta*Point) //цена упала больше Delta пунктов - покупаем!!!
{
Lots=GetSizeLot(); 
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"Купил");
if(ticket<0){Print("Ошибка открытия ордера BUY #",GetLastError());return(0);}
 }
//----
} //if (NumberOfBarOpenLastPos
}//if(OrdersTotal
return(0);
}
//------------------------------
 //+----------------------------------------------------------------------------+
//|  Возвращает номер бара открытия последней позиции или -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));
}
 

I told you to leave it in external parameters. The lot calculation parameters will then be set to PROPERTIES (from the library).

//+------------------------------------------------------------------+
//|                                                Expert-001.mq4 |
//|                                    Copyright © 2008, salesman*** |
//|                                         http://www.forexgrand.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, salesman***"
#property link      "http://www.forexgrand.ru"
#include  <b-Lots.mqh> 
#include <stdlib.mqh>
//----
extern double StopLoss=13;                               // Stop Loss
extern double TakeProfit=3;                              // Take Profit
//extern int Percent=70;
 
extern double Slippage =4;                               // Максимальное отклонение от запрошенной цены
extern int MagicNumber=0;                                // Order ID
extern int Delta=15;                                     // Сигнал приказа в пунктах
//extern int TimeForSleep = 0;                           // Время для отдыха после сделки
int  ticket;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
 
int start()
{
int total=OrdersTotal();
   if(total<1)                           {// если нет открытых позиций
//if (NumberOfBarOpenLastPos("", 0,  -1, MagicNumber)>0){
 
//---
 
if (Ask - iOpen(NULL,0,0)>=Delta*Point) //Цена выросла  больше Delta пунктов - продаем!!!
{
Lots=GetSizeLot(); 
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Продал");
if(ticket<0){Print("Ошибка открытия ордера SELL #",GetLastError());return(0);}
 
 }
//-------------------------------------------------------------------------
 
if (iOpen(NULL,0,0)-Bid  >=Delta*Point) //цена упала больше Delta пунктов - покупаем!!!
{
Lots=GetSizeLot(); 
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"Купил");
if(ticket<0){Print("Ошибка открытия ордера BUY #",GetLastError());return(0);}
 }
//----
//} //if (NumberOfBarOpenLastPos
}//if(OrdersTotal
return(0);
}
//------------------------------
/* //+----------------------------------------------------------------------------+
//|  Возвращает номер бара открытия последней позиции или -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));
} */

Check it out. Does it work or not? I ran it once - it works...

And it works too. I still need to understand the function

NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1)
 
I saved the b-lots library, should it also be checked by compilation for errors?
A warning pops up:
Start function not found and cannot be run.
What does it mean?