Un consulente che seguirebbe il tasso su un grafico a cinque minuti con condizioni una volta lanciato: - pagina 13

 
rid:
venditore77:
Di nuovo un contrattempo.
Sto cercando di far funzionare il codice di cui sopra. Un errore appare nel log con il testo:
18:38:23 '153085': ordine vendere 1,00 GBPUSD apertura a 2,0006 sl: 2,0019 tp: 2,0003 fallito [S/L o T/P non valido]
Che cosa significa questo?


1) E quale MT4 usi?

2) Qual è la distanza di stoploss e takeprofit consentita in questa casa di intermediazione?

http://www.forex4you.org/
Prima, ieri con questi parametri t/r e s/l tutto funzionava :((((
 
rid:
int start()
Io farei questo...
Non funziona così, le condizioni ci sono - gli accordi non funzionano. Il registro è silenzioso :(
 
Metti tutto il codice qui. E controllare con il DC lì - la distanza ammissibile di fermate dal prezzo.
 

Specifiche del contratto



Simbolo Nome 1 lotto per micro
(per mini *100)
Margine (margine)
per micro
(per mini *100)
Spread Livelli Limit & Stop
livello di gap

Scambiare
acquistare
Scambio
vendita
EURUSD EUR a USD EUR 1000 EUR 10 2 2 8 0.15 -0.51
GBPUSD GBP/USD GBP 1000 10 GBP
3 3 12 0.80 -1.52
 
Ed ecco l'intero codice:
//+------------------------------------------------------------------+
//|                                                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));
}

 

Sembra che ci sia qualcosa di sbagliato nella linea

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

Senza questa condizione, l'Expert Advisor funziona...

Perché hai messo dei parametri per calcolare il lotto? Non ne hai bisogno...

 

//+------------------------------------------------------------------+
//|                                                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()
E mettere la libreria b-lots stessa nella cartella iclude

E prima di ogni funzione OrderSend inserire

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

 
rid:
Mettere la libreria b-lots stessa nella cartella iclude

E prima di ogni funzione OrderSend

inserire
  Lots=GetSizeLot(); 
  ticket=OrderSend(Symbol(... ...
Ho fatto tutto ma il compilatore genera un errore:
'Lots' - variabile già definita C:\Program Files\MetaTrader - E-Global TFG\experts\expert-001.mq4 (21, 15)
Ecco il codice:
//+------------------------------------------------------------------+
//|                                                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));
}
 

Ti ho detto di lasciarlo nei parametri esterni. I parametri di calcolo del lotto saranno quindi impostati su PROPRIETÀ (dalla libreria).

//+------------------------------------------------------------------+
//|                                                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));
} */

Guarda qui. Funziona o no? L'ho eseguito una volta - funziona...

E funziona anche. Devo ancora capire la funzione

NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1)
 
Ho salvato la libreria b-lots, dovrebbe anche essere controllata dalla compilazione per gli errori?
Appare un avviso:
Funzione di avvio non trovata e non può essere eseguita.
Cosa significa?
Motivazione: