Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate oltre. Da nessuna parte senza di te - 6. - pagina 1095

 
alvlaf:
Questo codice è scritto in MQL5?

per (int i=0; i<SymbolCount; i++)

{

if (CountTrades() == 0) // Il numero di ordini deve essere zero

{

se (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY)) ||

(TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))&& MaxOpenOrders > OrdersTotal())

// Se l'ultimo trade è in perdita, verrà aperto lo stesso trade, ma con un lotto più grande

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = LastAsk;

if (Type == OP_SELL) Price = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbols[i], Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

se (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0 && MaxOpenOrders > OrdersTotal())

// se il profitto dell'ultimo trade è uguale a zero, lo stesso trade sarà aperto

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = LastAsk;

if (Type == OP_SELL) Price = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbols[i], 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(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

se (SignalSell(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_SELL, Lots, Bid, Slippage, 0, 0, 0, IntegerToString(Exp), Magic)

}

}

}

}

Codice in OnTick dopo le parole e così via. Scritto in MQL4, avete bisogno di MQL5?

Per ogni OrderSend, la condizione MaxOpenOrders non dovrebbe essere maggiore di OrdersTotal().

Codice della procedura (rimosso OrderSymbol()==Symbol() e inserito iClose()/iOpen() invece di Close/Open), non ho controllato la correttezza del codice:

//+------------------------------------------------------------------+

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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

ritorno(cnt);

}

//+------------------------------------------------------------------+

bool SignalBuy(stringa Sym)

{

per (int i=1; i<=Attesa; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Specificare qui il timeframe richiesto

doppio O = iOpen(Sym, PERIOD_M5, i);

se(C > O) return(false);

}

se ((iBarShift(Sym, 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

se (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SignalSell(stringa Sym)

{

per (int i=1; i<=Attesa; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Specificare qui il timeframe richiesto

doppio O = iOpen(Sym, PERIOD_M5, i);

se(C < O) return(false);

}

se ((iBarShift(Sym, 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 (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))

{

se (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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

se (OrderCloseTime() > time)

{

time = OrderCloseTime();

prezzo = OrderClosePrice();

}

}

}

}

ritorno(prezzo);

}

//+------------------------------------------------------------------+

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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

se (OrderCloseTime() > time)

{

time = OrderCloseTime();

prezzo = OrderOpenPrice();

}

}

}

}

ritorno(prezzo);

}

 
alvlaf:

extern int Exp = 1;

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);

Questo codice funziona per voi? La data deve essere qui, e maggiore della data corrente di 10 minuti (cioè TimeCurrent() + 600 minimo).

 
A13ksandr:

per (int i=0; i<SymbolCount; i++)

{

if (CountTrades() == 0) // Il numero di ordini deve essere zero

{

se (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY)) ||

(TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))&& MaxOpenOrders > OrdersTotal())

// Se l'ultimo trade è in perdita, verrà aperto lo stesso trade, ma con un lotto più grande

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = LastAsk;

if (Type == OP_SELL) Price = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbols[i], Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

se (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0 && MaxOpenOrders > OrdersTotal())

// se il profitto dell'ultimo trade è uguale a zero, lo stesso trade sarà aperto

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = LastAsk;

if (Type == OP_SELL) Price = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbols[i], 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(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

se (SignalSell(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_SELL, Lots, Bid, Slippage, 0, 0, 0, IntegerToString(Exp), Magic)

}

}

}

}

Codice in OnTick dopo le parole e così via. Scritto in MQL4, avete bisogno di MQL5?

Per ogni OrderSend, la condizione MaxOpenOrders non dovrebbe essere maggiore di OrdersTotal().

Codice della procedura (rimosso OrderSymbol()==Symbol() e inserito iClose()/iOpen() invece di Close/Open), non ho controllato la correttezza del codice:

//+------------------------------------------------------------------+

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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

ritorno(cnt);

}

//+------------------------------------------------------------------+

bool SignalBuy(stringa Sym)

{

per (int i=1; i<=Attesa; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Specificare qui il timeframe richiesto

doppio O = iOpen(Sym, PERIOD_M5, i);

se(C > O) return(false);

}

se ((iBarShift(Sym, 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

se (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SignalSell(stringa Sym)

{

per (int i=1; i<=Attesa; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Specificare qui il timeframe richiesto

doppio O = iOpen(Sym, PERIOD_M5, i);

se(C < O) return(false);

}

se ((iBarShift(Sym, 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 (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))

{

se (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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

se (OrderCloseTime() > time)

{

time = OrderCloseTime();

prezzo = OrderClosePrice();

}

}

}

}

ritorno(prezzo);

}

//+------------------------------------------------------------------+

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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

se (OrderCloseTime() > time)

{

time = OrderCloseTime();

prezzo = OrderOpenPrice();

}

}

}

}

ritorno(prezzo);

}

Dà un paio di errori, non è riuscito a risolverli. Cosa c'è di sbagliato qui?

//+------------------------------------------------------------------+
//| BB1.mq4 |
//| Copyright 2016, MetaQuotes Software Corp.
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp.
#proprietà link "https://www.mql5.com"
#proprietà versione "1.00"
#proprietà rigorosa

extern double Lots = 1; // Lots
extern int Exp = 1; // Scadenza
extern int Wait = 2; // Numero di candele di una direzione
extern int Timeout = 1; // intervallo di tempo
extern double Multiplier = 3; // Moltiplicatore
extern int Slippage = 5; // Slippage
extern int Magic = 774274; // Magic
extern int MaxOpenOrders = 1; // Numero massimo di ordini

int ticket, Type, SymbolCount;
doppio prezzo, lotto;

input string TradeSymbols = "EURUSD_OP, GBPUSD_OP, AUDUSD_OP, NZDUSD_OP, USDCAD_OP, USDCHF_OP, GBPCAD_OP, AUDNZD_OP, CHFJPY_OP, GBPCHF_OP"; // simboli per il trading

string Symbols[50]; // 50 è il numero massimo possibile di simboli


//--------------------------------------------------

int OnInit()

{

se (IsTesting() || !ExtractSymbols())

{

SymbolCount = 1;

Simboli[0] = Simbolo();

}

return(INIT_SUCCEED);

}

//--------------------------------------------------

bool ExtractSymbols()

{

ushort Comma = StringGetCharacter(",", 0);

SymbolCount = StringSplit(TradeSymbols, Comma, Symbols);

per (int i = 0; i < SymbolCount; i++)

{

StringToUpper(Symbols[i]);

Symbols[i] = StringTrimRight(Symbols[i]); // protezione dagli spazi accidentali

Symbols[i] = StringTrimLeft(Symbols[i]);

}

se (SymbolCount > 0) return(true);

return(false);

}

//--------------------------------------------------

void OnTick()

{

per (int i=0; i<SymbolCount; i++)

{

if (CountTrades() == 0) // Il numero di ordini deve essere zero

{

se (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY)) ||

(TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL)) && MaxOpenOrders > OrdersTotal())

// Se l'ultimo trade è in perdita, verrà aperto lo stesso trade, ma con un lotto più grande

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = LastAsk;

if (Type == OP_SELL) Price = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbols[i], Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

se (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0 && MaxOpenOrders > OrdersTotal())

// se il profitto dell'ultimo trade è uguale a zero, lo stesso trade sarà aperto

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = LastAsk;

if (Type == OP_SELL) Price = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbols[i], 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(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

se (SignalSell(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_SELL, Lots, Bid, Slippage, 0, 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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

ritorno(cnt);

}

//+------------------------------------------------------------------+

bool SignalBuy(stringa Sym)

{

per (int i=1; i<=Attesa; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Specificare qui il timeframe richiesto

doppio O = iOpen(Sym, PERIOD_M5, i);

se (C > O) return(false);

}

se ((iBarShift(Sym, 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

se (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SignalSell(stringa Sym)

{

per (int i=1; i<=Attesa; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Specificare qui il timeframe richiesto

doppio O = iOpen(Sym, PERIOD_M5, i);

se (C < O) return(false);

}

se ((iBarShift(Sym, 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 (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))

{

se (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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

se (OrderCloseTime() > time)

{

time = OrderCloseTime();

prezzo = OrderClosePrice();

}

}

}

}

ritorno(prezzo);

}

//+------------------------------------------------------------------+

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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

se (OrderCloseTime() > time)

{

time = OrderCloseTime();

prezzo = OrderOpenPrice();

}

}

}

}

ritorno(prezzo);

}

 
Ragazzi, aiuto. Faccio trading sulla piattaforma MT4 di Stforex. Quando apro gli ordini, non mostra il livello di entrata sul grafico (nessuna linea tratteggiata), e quindi non è conveniente mettere uno stop-loss. Forse chi sa cosa c'è di sbagliato e come risolverlo?
 
gloomy159:
Ragazzi, aiuto. Sto facendo trading sulla piattaforma MT4 di Stforex. Quando apro un ordine, non mi mostra il livello di entrata sul grafico (nessuna linea tratteggiata), e quindi non è conveniente mettere uno stop-loss. Forse chi sa cosa c'è di sbagliato e come risolverlo?

http://prntscr.com/chfa36

Impostazioni - Grafici - Mostra i livelli di trading

 

Ragazzi, quale funzione potrebbe restituire l'errore 65?

ERRARE_CONTO_INVALIDO65 Numero di conto errato
 
testerMT4:

http://prntscr.com/chfa36

Impostazioni - Grafici - Mostra i livelli di trading

Questa funzione è stata inizialmente abilitata, ma ancora non mostra i livelli sul grafico
 
gloomy159:
Questa funzione è stata originariamente attivata, ma i livelli non vengono ancora visualizzati sul grafico
Nelle impostazioni del colore, controlla se il colore è assegnato ai volumi e non corrisponde al colore dello sfondo.
 
alvlaf:

Commette un paio di errori, non riesce a fare le cose per bene. Cosa c'è di sbagliato qui?


Hai dimenticato di aggiungere una parentesi di chiusura nelle variabili OnTick e LastAsk e LastBid. Ecco il codice che compila senza errori, non ho controllato la sua funzionalità:

//+------------------------------------------------------------------+

//| BB1.mq4 |

//| Copyright 2016, MetaQuotes Software Corp.

//| https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2016, MetaQuotes Software Corp."

#proprietà link "https://www.mql5.com"

#proprietà versione "1.00"

#proprietà rigorosa


extern double Lots = 1; // Lots

extern int Exp = 1; // Scadenza

extern int Wait = 2; // Numero di candele di una direzione

extern int Timeout = 1; // intervallo di tempo

extern double Multiplier = 3; // Moltiplicatore

extern int Slippage = 5; // Slippage

extern int Magic = 774274; // Magic

extern int MaxOpenOrders = 1; // Numero massimo di ordini


int ticket, Type, SymbolCount;

doppio prezzo, lotto;

input string TradeSymbols = "EURUSD_OP, GBPUSD_OP, AUDUSD_OP, NZDUSD_OP, USDCAD_OP, USDCHF_OP, GBPCAD_OP, AUDNZD_OP, CHFJPY_OP, GBPCHF_OP"; // simboli per il trading

string Symbols[50]; // 50 è il numero massimo possibile di simboli

//--------------------------------------------------

int OnInit()

{

se (IsTesting() || !ExtractSymbols())

{

SymbolCount = 1;

Simboli[0] = Simbolo();

}

return(INIT_SUCCEED);

}

//--------------------------------------------------

bool ExtractSymbols()

{

ushort Comma = StringGetCharacter(",", 0);

SymbolCount = StringSplit(TradeSymbols, Comma, Symbols);

per (int i = 0; i < SymbolCount; i++)

{

StringToUpper(Symbols[i]);

Symbols[i] = StringTrimRight(Symbols[i]); // protezione dagli spazi accidentali

Symbols[i] = StringTrimLeft(Symbols[i]);

}

se (SymbolCount > 0) return(true);

return(false);

}

//--------------------------------------------------

void OnTick()

{

per (int i=0; i<SymbolCount; i++)

{

double LastAsk = SymbolInfoDouble(Symbols[i], SYMBOL_ASK);

double LastBid = SymbolInfoDouble(Symbols[i], SYMBOL_BID);

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)) && MaxOpenOrders > OrdersTotal())

// Se l'ultimo trade è in perdita, verrà aperto lo stesso trade, ma con un lotto più grande

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = LastAsk;

if (Type == OP_SELL) Price = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbols[i], Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

se (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0 && MaxOpenOrders > OrdersTotal())

// se il profitto dell'ultimo trade è uguale a zero, lo stesso trade sarà aperto

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = LastAsk;

if (Type == OP_SELL) Price = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbols[i], 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(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

se (SignalSell(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_SELL, Lots, Bid, Slippage, 0, 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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

ritorno(cnt);

}

//+------------------------------------------------------------------+

bool SignalBuy(stringa Sym)

{

per (int i=1; i<=Attesa; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Specificare qui il timeframe richiesto

doppio O = iOpen(Sym, PERIOD_M5, i);

se (C > O) return(false);

}

se ((iBarShift(Sym, 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

se (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SignalSell(stringa Sym)

{

per (int i=1; i<=Attesa; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Specificare qui il timeframe richiesto

doppio O = iOpen(Sym, PERIOD_M5, i);

se (C < O) return(false);

}

se ((iBarShift(Sym, 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 (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))

{

se (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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

se (OrderCloseTime() > time)

{

time = OrderCloseTime();

prezzo = OrderClosePrice();

}

}

}

}

ritorno(prezzo);

}

//+------------------------------------------------------------------+

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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

se (OrderCloseTime() > time)

{

time = OrderCloseTime();

prezzo = OrderOpenPrice();

}

}

}

}

ritorno(prezzo);

}

 

Ciao!

Come potete determinare se una posizione ha chiuso su TP? Non credo che OrderClosePrice()==OrderTakeProfit() sia corretto da usare.

Motivazione: