Domande dai principianti MQL4 MT4 MetaTrader 4 - pagina 255

 
Mihail Matkovskij #:

Come si calcola il tp?

Specifico nella variabile double tp=50;

 
Roman Epifanov #:

Specifico nella variabile double tp=50;

double takeProfit;
takeProfit = NormalizeDouble(Bid - tp * Point(), Digits()); // TP для Sell
 
Mihail Matkovskij #:

ora scrive

2021.12.04 13:56:09.509 TestGenerator: unmatched data error (il valore alto 1.13110 al 2021.12.03 23:45 non è raggiunto dal timeframe più basso, il prezzo alto 1.13104 non corrisponde)


//+------------------------------------------------------------------+
//|                                                         repa.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int i;
   double lot_sum;
   bool trend;
   double ema;
   double sl=50.0,tp=50.0;
   tp = NormalizeDouble(Bid - tp * Point(), Digits()); // TP для Sell
   double lot=0.01;
   while (i<OrdersTotal())
   {
   OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   lot_sum=lot_sum + OrderLots(); // сумма лотов открытых позиций
   
   
   }
   
   ema=iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0); //взяли значение средней
   if (Close[0]<ema)trend=true ;else if(Close[0]>ema)trend=false; //определили тренд
   
   if (Close[1]<Open[1]) {OrderSend(Symbol(),OP_SELL,lot,Bid,2,Ask+sl,tp,"Candle sell, Close[0]<MA");};
   
   
  }
//+------------------------------------------------------------------+
 
Mihail Matkovskij #:

Mettilo per un minuto... funziona...

ma il livello di stop è diverso -

1 2021.09.16 05:59 vendere 1 0.01 1.18190 51.18192 1.18140 0.00 10000.00


 
Roman Epifanov #:

ora scrive

2021.12.04 13:56:09.509 TestGenerator: unmatched data error (il valore alto 1.13110 al 2021.12.03 23:45 non è raggiunto dal timeframe più basso, il prezzo alto 1.13104 non corrisponde)


void OnTick()
  {
//---
   int i;
   double lot_sum;
   bool trend;
   double ema;
   double sl=50.0,tp=50.0;
   double stopLoss, takeProfit, openPrice;
   double lot=0.01;
   while (i<OrdersTotal())
   {
     OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     lot_sum=lot_sum + OrderLots(); // сумма лотов открытых позиций
   
   }
   
   ema=iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,0); //взяли значение средней

   if (Close[0]<ema)
     trend=true ;
   else if(Close[0]>ema)
     trend=false; //определили тренд
    
   takeProfit = NormalizeDouble(Bid - tp * Point(), Digits()); // TP для Sell
   stopLoss = NormalizeDouble(Bid + sl * Point(), Digits()); // SL для Sell
   openPrice = NormalizeDouble(Bid, Digits());

   if (Close[1]<Open[1]) {
     OrderSend(Symbol(), OP_SELL, lot, openPrice, 2, stopLoss, takeProfit, "Candle sell, Close[0]<MA");
   }
   
  }

Tutte le regole sono online, quindi controlla tu stesso.

 
Mihail Matkovskij #:

Le regole sono tutte online, quindi controllate voi stessi.

Grazie!

 

Buona sera signori, potreste per favore consigliarmi perché il consulente dà un errore quando apre il secondo ordine?


Il testo del consigliere stesso



//+----------------------Параметры-----------------------------------+

input int TakeProfit = 100; // Profitto in pip

input int StopLoss = 50; // perdita in pip

input double Lot = 0.01; // lotto iniziale

input double Multilot = 1.95; // moltiplicatore per il lotto iniziale

input int Slippage =30; // Slippage

input int MagicNumber = 333 ; // Numero unico


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

//| Funzione di inizializzazione dell'esperto |

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

doppio tp=0;

doppio sl=0;

int OnInit()

{

tp=NormalizeDouble(TakeProfit*Point(),Digits());

sl=NormalizeDouble(StopLoss*Point(),Digits());

return(INIT_SUCCEED);

}


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

//| Funzione tick esperto |

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

void OnTick()

{

//il ciclo controlla gli ordini aperti quando l'Expert Advisor è attivato e li calcola.

int buy=0; //numero di ordini BUY

int sell=0; //numero di ordini SELL


for(int i = OrdiniTotali()-1; i>=0; i--)

if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES))

se(OrderSymbol()==Symbol())

if(OrderMagicNumber()== MagicNumber)

{

if(OrderType()==OP_BUY)

comprare++;

if(OrderType()==OP_SELL)

vendere++;

}


//il ciclo ottiene i dati dell'ultimo ordine chiuso quando l'EA è attivato

int type=-1; //il tipo di un ordine chiuso

int history_close_orders=0; //numero di ordini chiusi

double lot=0; //Lotto dell'ultimo ordine chiuso

double profit=0; //Profitto al quale è stato chiuso l'ultimo ordine

datetime time=0; //Ora di chiusura dell'ultimo ordine


for(int i = OrdersHistoryTotal()-1; i>=0; i--)

if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY))

se(OrderSymbol()==Symbol())

if(OrderMagicNumber()== MagicNumber)

se(OrderCloseTime()>time)

{

history_close_orders++;

time = OrderCloseTime();//il tempo di chiusura dell'ultimo ordine

lot= OrderLots();//Lot dell'ultimo ordine chiuso

type=OrderType();// Tipo dell'ultimo ordine chiuso

profit=OrderProfit()*OrderSwap()*OrderCommission();//Profitto dell'ultimo ordine chiuso

}

//calcolare il lotto con cui l'EA lavorerà

double Lots_Work=0;// lotto di lavoro


if(history_close_orders==0 || profit>0)// se non ci sono ordini chiusi o l'ultimo ordine ha chiuso sul profit

Lots_Work=Lot;// il lotto di lavoro è uguale al lotto iniziale


if(history_close_orders>0 && profit<0) // se l'ultimo ordine ha chiuso in rosso

Lots_Work=1;// il lotto di lavoro sarà uguale al lotto dell'ultimo ordine moltiplicato per il moltiplicatore


//aprire il primo ordine di acquisto

if(buy==0 || profitto>0)

{

int ticket=OrderSend(Symbol(),OP_BUY,Lots_Work,Ask,Slippage,0,0, "Expert Advisor Test fair",MagicNumber,0,clrGreen);

se(biglietto<0)

Print("OrderSend failed with error #",GetLastError());

else

Print("OrderSend completato con successo");

}


// Apertura del secondo e dei successivi ordini di acquisto

if(buy==0 && type==OP_BUY && profit<0)

{

int ticket=OrderSend(Symbol(),OP_BUY,Lots_Work,Ask,Slippage,0,0, "EA Test fair",MagicNumber,0,clrGreen);

se(biglietto<0)

Print("OrderSend failed with error #",GetLastError());

else

Print("OrderSend completato con successo");

}


// Apertura del primo ordine di vendita

se(vendere==0 || profitto>0)

{

int ticket=OrderSend(Symbol(),OP_SELL,Lots_Work,Bid,Slippage,0,0, "EA Test fair",MagicNumber,0,clrRed);

se(biglietto<0)

Print("OrderSend failed with error #",GetLastError());

else

Print("OrderSend completato con successo");

}

// Apertura del secondo e dei successivi ordini di acquisto

if(sell==0 && (type==OP_SELL && profit<0))

{

int ticket=OrderSend(Symbol(),OP_SELL,Lots_Work,Bid,Slippage,0,0, "Expert Advisor Test fair",MagicNumber,0,clrRed);

se(biglietto<0)

Print("OrderSend failed with error #",GetLastError());

else

Print("OrderSend completato con successo");

}


//--Modificare l'ordine aggiungendo Take Profit e Stop Loss

for(int i = OrdiniTotali()-1; i>=0; i--)

if(OrderSelect(i, SELECT_BY_POS))

se(OrderSymbol()==Symbol())

if(OrderMagicNumber()== MagicNumber)

{

if(OrderType()==OP_BUY)

{

if(OrderStopLoss()==0 || OrderTakeProfit()==0)

if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-sl,Digits(),NormalizeDouble(OrderOpenPrice()+tp,Digits(),0,clrGreen))

Stampa("OrderModify OK!");

else

Print("OrderModify BUY failed #", GetLastError());

}

if(OrderType()==OP_SELL)

{

if(OrderStopLoss()==0 || OrderTakeProfit()==0)

if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+sl,Digits(),NormalizeDouble(OrderOpenPrice()-tp,Digits(),0,clrRed))

Stampa("OrderModify OK!");

else

Print("OrderModify SELL failed #", GetLastError());

}

}


}

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


 
Il mio vecchio portatile con processore i3 aveva ancora installato WinXP 32 bit, MT5 non supportato. Recentemente ho aumentato la memoria a 6GB, voglio installare un sistema operativo a 64 bit che faccia funzionare MT4 e MT5. Qual è preferibile - Win7 o Win8.1?
 
atztek #:
Il mio vecchio portatile con processore i3 aveva ancora installato WinXP 32 bit, MT5 non supportato. Recentemente ho aumentato la memoria a 6GB, voglio installare un sistema operativo a 64 bit che faccia funzionare MT4 e MT5. Qual è preferibile - Win7 o Win8.1?

10

 
Andrey Sokolov #:

10

Questa versione è installata su un nuovo portatile, annoiato dai continui aggiornamenti. Inoltre, la gente scrive che otto gira meglio di dieci sui vecchi portatili. Vorrei lasciare WinXP sul mio vecchio portatile, ma MT5 non funziona su di esso, inoltre 3Gb di memoria non è sufficiente per XP. Tuttavia, se la scelta è tra 7 e 8.1, cosa è meglio per eseguire ottimizzazioni su MT4/5?
Motivazione: