Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate oltre. Da nessuna parte senza di te - 6. - pagina 1093
Ti stai perdendo delle opportunità di trading:
- App di trading gratuite
- Oltre 8.000 segnali per il copy trading
- Notizie economiche per esplorare i mercati finanziari
Registrazione
Accedi
Accetti la politica del sito e le condizioni d’uso
Se non hai un account, registrati
Poi c'è un codice di errore nel log del tester e può essere usato per ulteriori indagini.
Nessun errore. Si blocca solo quando entra nella procedura. E c'è anche StartSell, entra normalmente. Questo è un bel casino.
Ho aggiornato le citazioni e funziona. Non è corretto a causa di alcuni buchi, ma almeno non si blocca.
Saluti, potreste dirmi il modo migliore per impedire l'apertura simultanea di più di un certo numero di serie per diversi strumenti (il bot è collegato a diversi grafici di diversi strumenti allo stesso tempo) nelle opzioni binarie?
extern double Lots = 1; // Lots
extern int Exp = 1; // Scadenza
extern int Wait = 0; // Numero di candele di una direzione
extern int Timeout = 1; // intervallo di tempo
extern double Multiplier = 3; // Moltiplicatore
extern int int Slippage = 5; // Slippage
extern int MaxOpenOrders = 1; // Numero massimo di ordini aperti simultaneamente
extern int Magic = 774274; // Magic
biglietto int, Tipo;
doppio prezzo, lotto;
//+------------------------------------------------------------------+
//| Funzione di inizializzazione dell'esperto |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEED);
}
//+------------------------------------------------------------------+
//| Funzione di deinizializzazione esperto |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| funzione tick esperto |
//+------------------------------------------------------------------+
void OnTick()
{
// --------------- Aprire le transazioni ---------------
if (CountTrades() == 0) // Il numero di ordini deve essere uguale a zero
{
se ((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))
// Se l'ultimo trade è perdente, si apre lo stesso, ma con un lotto più grande
{
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
se (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0)
// se il profitto dell'ultimo trade è uguale a zero, lo stesso trade sarà aperto
{
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder(), 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
se (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) > PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) < PriceOpenLastHistOrder(OP_SELL))
|| CountHistTrades() == 0)// Se l'ultimo trade è redditizio, l'ordine viene aperto
{
se (SignalBuy() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
se (SignalSell() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
}
}
}
//+------------------------------------------------------------------+
int CountTrades(int type = -1)
{
int cnt = 0;
for (int i=OrdersTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
cnt++;
}
}
ritorno(cnt);
}
//+------------------------------------------------------------------+
int CountHistTrades(int type = -1)
{
int cnt = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
cnt++;
}
}
ritorno(cnt);
}
//+------------------------------------------------------------------+
bool SignalBuy()
{
per (int i=1; i<=Attesa; i++)
{
se (Close[i] > Open[i]) return(false)
}
se ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))
&& CountHistTrades() > 0) return(true);
se (CountHistTrades() == 0) return(true);
return(false);
}
//+------------------------------------------------------------------+
bool SignalSell()
{
per (int i=1; i<=Attesa; i++)
{
se (Close[i] < Open[i]) return(false)
}
se ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))
&& CountHistTrades() > 0) return(true);
se (CountHistTrades() == 0) return(true);
return(false);
}
//+------------------------------------------------------------------+
datetime TimeLastHistOrder(int type = -1)
{
datetime lasttime = 0;
datetime opentime = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
se (OrderCloseTime() > lasttime)
{
lasttime = OrderCloseTime();
opentime = OrderOpenTime();
}
}
}
}
ritorno(opentime);
}
//+------------------------------------------------------------------+
int TypeLastHistOrder()
{
datetime time = 0;
int type = -1;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
se (OrderCloseTime() > time)
{
time = OrderCloseTime();
tipo = OrderType();
}
}
}
}
ritorno(tipo);
}
//+------------------------------------------------------------------+
double LotsLastHistOrder(int type = -1)
{
datetime time = 0;
doppio lotti = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
se (OrderOpenTime() > time)
{
time = OrderOpenTime();
tempo = OrderLots();
}
}
}
}
return(lots);
}
//+------------------------------------------------------------------+
doppio PriceCloseLastHistOrder(int type = -1)
{
datetime time = 0;
doppio prezzo = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
se (OrderCloseTime() > time)
{
time = OrderCloseTime();
prezzo = OrderClosePrice();
}
}
}
}
}
}
//+------------------------------------------------------------------+
doppio PriceOpenLastHistOrder(int type = -1)
{
datetime time = 0;
doppio prezzo = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
se (OrderCloseTime() > time)
{
time = OrderCloseTime();
prezzo = OrderOpenPrice();
}
}
}
}
}
}
//+------------------------------------------------------------------+
Semplicemente eliminate la condizione OrderSymbol() == Symbol() dalla funzione CountTrades e aggiungete OrderType() == OP_BUY || OrderType() == OP_SELL, no?
E cambiare la condizione if (SignalBuy() && CountTrades() < MaxOpenOrders) in OnTick prima di OrderSend... Lo stesso per Vendere.if (OrderMagicNumber() == Magic && (OrderType() == OrderType() == OP_BUY || OrderType() == OP_SELL))
L'ho cambiato correttamente?
Saluti, potreste dirmi il modo migliore per impedire l'apertura simultanea di più di un certo numero di serie per diversi strumenti (il bot è collegato a diversi grafici di diversi strumenti allo stesso tempo) nelle opzioni binarie?
extern double Lots = 1; // Lots
extern int Exp = 1; // Scadenza
extern int Wait = 0; // Numero di candele di una direzione
extern int Timeout = 1; // intervallo di tempo
extern double Multiplier = 3; // Moltiplicatore
extern int int Slippage = 5; // Slippage
extern int MaxOpenOrders = 1; // Numero massimo di ordini aperti simultaneamente
extern int Magic = 774274; // Magic
biglietto int, Tipo;
doppio prezzo, lotto;
//+------------------------------------------------------------------+
//| Funzione di inizializzazione dell'esperto |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEED);
}
//+------------------------------------------------------------------+
//| Funzione di deinizializzazione dell'esperto |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| funzione tick esperto |
//+------------------------------------------------------------------+
void OnTick()
{
// --------------- Aprire le transazioni ---------------
if (CountTrades() == 0) // Il numero di ordini deve essere uguale a zero
{
se ((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))
// Se l'ultimo trade è perdente, si apre lo stesso, ma con un lotto più grande
{
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
se (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0)
// se il profitto dell'ultimo trade è uguale a zero, lo stesso trade sarà aperto
{
Type = TypeLastHistOrder();
if (Type == OP_BUY) Price = Ask;
if (Type == OP_SELL) Price = Bid;
Lot = NormalizeDouble(LotsLastHistOrder(), 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
se (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) > PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) < PriceOpenLastHistOrder(OP_SELL))
|| CountHistTrades() == 0)// Se l'ultimo trade è redditizio, l'ordine viene aperto
{
se (SignalBuy() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
se (SignalSell() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
}
}
}
//+------------------------------------------------------------------+
int CountTrades(int type = -1)
{
int cnt = 0;
for (int i=OrdersTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
cnt++;
}
}
ritorno(cnt);
}
//+------------------------------------------------------------------+
int CountHistTrades(int type = -1)
{
int cnt = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
cnt++;
}
}
ritorno(cnt);
}
//+------------------------------------------------------------------+
bool SignalBuy()
{
per (int i=1; i<=Attesa; i++)
{
se (Close[i] > Open[i]) return(false)
}
se ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))
&& CountHistTrades() > 0) return(true);
se (CountHistTrades() == 0) return(true);
return(false);
}
//+------------------------------------------------------------------+
bool SignalSell()
{
per (int i=1; i<=Attesa; i++)
{
se (Close[i] < Open[i]) return(false)
}
se ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))
&& CountHistTrades() > 0) return(true);
se (CountHistTrades() == 0) return(true);
return(false);
}
//+------------------------------------------------------------------+
datetime TimeLastHistOrder(int type = -1)
{
datetime lasttime = 0;
datetime opentime = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
se (OrderCloseTime() > lasttime)
{
lasttime = OrderCloseTime();
opentime = OrderOpenTime();
}
}
}
}
ritorno(opentime);
}
//+------------------------------------------------------------------+
int TypeLastHistOrder()
{
datetime time = 0;
int type = -1;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
se (OrderCloseTime() > time)
{
time = OrderCloseTime();
tipo = OrderType();
}
}
}
}
ritorno(tipo);
}
//+------------------------------------------------------------------+
double LotsLastHistOrder(int type = -1)
{
datetime time = 0;
doppio lotti = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
se (OrderOpenTime() > time)
{
time = OrderOpenTime();
tempo = OrderLots();
}
}
}
}
return(lots);
}
//+------------------------------------------------------------------+
doppio PriceCloseLastHistOrder(int type = -1)
{
datetime time = 0;
doppio prezzo = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
se (OrderCloseTime() > time)
{
time = OrderCloseTime();
prezzo = OrderClosePrice();
}
}
}
}
}
}
//+------------------------------------------------------------------+
doppio PriceOpenLastHistOrder(int type = -1)
{
datetime time = 0;
doppio prezzo = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
se (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
se (OrderCloseTime() > time)
{
time = OrderCloseTime();
prezzo = OrderOpenPrice();
}
}
}
}
}
}
//+------------------------------------------------------------------+
L'ora può essere impostata direttamente nel formato datetime, non c'è bisogno di sprecare il tempo della macchina per la conversione, funziona così:
extern datetime StartTime = D'07:00';
In questo formato di tempo, quando si avvia l'EA, si ottiene la data di compilazione, mentre noi vogliamo che la data di compilazione sia oggi.
Come correggerlo?
Questo formato orario dà la data di compilazione dell'EA all'avvio dell'EA, ma io vorrei avere la data di oggi.
Come risolvere il problema?
Si cambia il parametro in quello desiderato all'avvio, allo stesso modo degli altri parametri utente.
E per qualche motivo mi mostra la data corrente al momento dell'esecuzione dello script.
Per favore, ditemi, qual è lo scopo di usare MagicNumber, cosa dà in questa strategia? IMHO, puoi anche buttare via le funzioni OnInit OnDeinit qui