modifica a mqlcmillion EA
modifica a mqlcmillion EA
Ciao a tutti, vorrei che il mio ea dopo essere lanciato e aver incassato debba essere io a rilanciarlo, mi hanno detto che ci vorrebbe una linea interrupt, sarebbe questa //------------------------------------ ?? alla fine é gia presente una cosi.
Re: modificare ea
No non si tratta sicuramente di quella.
Ciò che chiedi può essere più o meno difficile, dipende dalle logiche dell'expert advisor. E' necessario che tu alleghi il sorgente del tuo ea per capire almeno se la cosa è fattibile.
Ciò che chiedi può essere più o meno difficile, dipende dalle logiche dell'expert advisor. E' necessario che tu alleghi il sorgente del tuo ea per capire almeno se la cosa è fattibile.
Re: modificare ea
https://www.mql5.com/en/code/download/1 ... artini.mq4 . ciao Carlo vorrei si chiudesse dopo che va in profitto senza riaprire un altra griglia. e fattibile?
Re: modifica a mqlcmillion EA
Occorre impostare una variabile globale booleana. Dopo la chiusura in profitto questa variabile deve essere impostata su True e se questa vale True l'EA deve uscire dalla Start. Tutto qui!attilio54 ha scritto:Ciao a tutti, vorrei che il mio ea dopo essere lanciato e aver incassato debba essere io a rilanciarlo, mi hanno detto che ci vorrebbe una linea interrupt, sarebbe questa //------------------------------------ ?? alla fine é gia presente una cosi.
Re: modifica a mqlcmillion EA
mille grazie , l'ultima parte si presenta cosi, credo debba cancellare "return 1"? e immettere bool error=true e nella riga seguente true=stop e poi nella riga dopo la parentesi graffa ??
OT = OrderType();
if (OT>1 && (tip==0 || OT==tip)) error=OrderDelete(OrderTicket());
}
}
}
if (error) break;
n++;
if (n>10) break;
Sleep(1000);
}
return(1);
}
//--------------------------------------------------------------------
OT = OrderType();
if (OT>1 && (tip==0 || OT==tip)) error=OrderDelete(OrderTicket());
}
}
}
if (error) break;
n++;
if (n>10) break;
Sleep(1000);
}
return(1);
}
//--------------------------------------------------------------------
Re: modifica a mqlcmillion EA
Apri il codice e nell'area generale inserisci la seguente riga:attilio54 ha scritto:mille grazie , l'ultima parte si presenta cosi, credo debba cancellare "return 1"? e immettere bool error=true e nella riga seguente true=stop e poi nella riga dopo la parentesi graffa ??
OT = OrderType();
if (OT>1 && (tip==0 || OT==tip)) error=OrderDelete(OrderTicket());
}
}
}
if (error) break;
n++;
if (n>10) break;
Sleep(1000);
}
return(1);
}
//--------------------------------------------------------------------
bool bStop;
Inutile assegnargli un valore in quanto variabile numerica ad inizializzazione automatica sul valore di default che è ZERO, ovvero False.
Vai nel codice dove si chiudono le operazioni in profitto e dopo le chiusure (all'interno della funzione) inserisci questa riga di codice:
bStop = True;
Ora vai nella funzione start e nelle prime righe inserisci quest'altra:
if(bStop==True)return;
Re: modifica a mqlcmillion EA
Codice: Seleziona tutto
extern int Step = 10;
extern double ProfitClose = 1.0,
lot = 0.01;
extern int slippage = 3, //The maximum permissible deviation of the price for market orders (orders to buy or sell).
magic = 0; //The magic number order. Can be used as a user-defined identifier.
bool bstop;
---------------------------bool CloseAllOrders(int tip)
{
bool error=true;
int err,nn,OT,OMN;
while(true)
{
for (int j = OrdersTotal()-1; j >= 0; j--)
{
if (OrderSelect(j, SELECT_BY_POS))
{
OMN = OrderMagicNumber();
if (OrderSymbol() == Symbol() && OMN == magic)
{
OT = OrderType();
if (OT != tip) continue;
if (OT==OP_BUY)
{
error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,Blue);
if (error) Comment("Close order N ",OrderTicket()," Profit ",OrderProfit(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
if (OT==OP_SELL)
{
error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,Red);
if (error) Comment("Close order N ",OrderTicket()," Profit ",OrderProfit(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
if (!error)
{
err = GetLastError();
if (err<2) continue;
if (err==129)
{ Comment("Wrong price ",TimeToStr(TimeCurrent(),TIME_SECONDS));
RefreshRates();
continue;
}
if (err==146)
{
if (IsTradeContextBusy()) Sleep(2000);
continue;
}
Comment("Error ",err," close order N ",OrderTicket(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
}
}
}
int n=0;
for (j = 0; j < OrdersTotal(); j++)
{
if (OrderSelect(j, SELECT_BY_POS))
{
OMN = OrderMagicNumber();
if (OrderSymbol() == Symbol() && OMN == magic)
{
OT = OrderType();
if (OT != tip) continue;
if (OT==OP_BUY || OT==OP_SELL) n++;
}
}
}
if (n==0) break;
nn++;
if (nn>10) {Alert(Symbol()," Failed to close all trades, there are still ",n);return(0);}
Sleep(1000);
RefreshRates();
bStop = True;
}
return(1);---------------
}
--------------------------------------------------------------------------------------------------------------------
int start()
{
double OOP,Price,Lot,Profit,MaxLot;
int OT,n,oo,Order;
for (int i=0; i<OrdersTotal(); i++)
if(bStop==True)return;
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
OT = OrderType();
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
if (OT==OP_BUY)
{
Price = OOP;
Lot = OrderLots();
Profit+=OrderProfit()+OrderSwap()+OrderCommission();
if (MaxLot<Lot) {MaxLot=Lot; Order= 1;}
n++;
}
if (OT==OP_SELL)
{
Price = OOP;
Lot = OrderLots();
Profit+=OrderProfit()+OrderSwap()+OrderCommission();
if (MaxLot<Lot) {MaxLot=Lot; Order=-1;}
n++;
}
if (OT>1) oo++;
}
}
}
Comment("Profit ",DoubleToStr(Profit,2));
if (Profit>ProfitClose)
{
CloseAllOrders(OP_BUY);
CloseAllOrders(OP_SELL);
}
if (Order==1 && Bid+n*Step*Point<Price)
{
if(OrderSend(Symbol(),OP_SELL,Lot*2,NormalizeDouble(Bid,Digits),slippage,0,0,"",magic,0,Red)!=-1) return;
}
if (Order==-1 && Ask-n*Step*Point>Price)
{
if(OrderSend(Symbol(),OP_BUY,Lot*2,NormalizeDouble(Ask,Digits),slippage,0,0,"",magic,0,Blue)!=-1) return;
}
if (n==0 && oo==0)
{
OrderSend(Symbol(),OP_SELLSTOP,lot,NormalizeDouble(Bid-10*Point,Digits),slippage,0,0,"",magic,0,Red);
OrderSend(Symbol(),OP_BUYSTOP ,lot,NormalizeDouble(Ask+10*Point,Digits),slippage,0,0,"",magic,0,Blue);
}
if (n!=0) DeleteAll(0);
return(0);
}
------------------------------------------------------------------------------------------------------------------------
Re: modifica a mqlcmillion EA
Ti ho evidenziato solo un errore di posizionamento riga. Per il resto ...attilio54 ha scritto:extern int Step = 10;
extern double ProfitClose = 1.0,
lot = 0.01;
extern int slippage = 3, //The maximum permissible deviation of the price for market orders (orders to buy or sell).
magic = 0; //The magic number order. Can be used as a user-defined identifier.
bool bstop;
---------------------------bool CloseAllOrders(int tip)
{
bool error=true;
int err,nn,OT,OMN;
while(true)
{
for (int j = OrdersTotal()-1; j >= 0; j--)
{
if (OrderSelect(j, SELECT_BY_POS))
{
OMN = OrderMagicNumber();
if (OrderSymbol() == Symbol() && OMN == magic)
{
OT = OrderType();
if (OT != tip) continue;
if (OT==OP_BUY)
{
error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,Blue);
if (error) Comment("Close order N ",OrderTicket()," Profit ",OrderProfit(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
if (OT==OP_SELL)
{
error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,Red);
if (error) Comment("Close order N ",OrderTicket()," Profit ",OrderProfit(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
if (!error)
{
err = GetLastError();
if (err<2) continue;
if (err==129)
{ Comment("Wrong price ",TimeToStr(TimeCurrent(),TIME_SECONDS));
RefreshRates();
continue;
}
if (err==146)
{
if (IsTradeContextBusy()) Sleep(2000);
continue;
}
Comment("Error ",err," close order N ",OrderTicket(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
}
}
}
int n=0;
for (j = 0; j < OrdersTotal(); j++)
{
if (OrderSelect(j, SELECT_BY_POS))
{
OMN = OrderMagicNumber();
if (OrderSymbol() == Symbol() && OMN == magic)
{
OT = OrderType();
if (OT != tip) continue;
if (OT==OP_BUY || OT==OP_SELL) n++;
}
}
}
if (n==0) break;
nn++;
if (nn>10) {Alert(Symbol()," Failed to close all trades, there are still ",n);return(0);}
Sleep(1000);
RefreshRates();
bStop = True;
}
return(1);---------------
}
--------------------------------------------------------------------------------------------------------------------
int start()
{
double OOP,Price,Lot,Profit,MaxLot;
int OT,n,oo,Order;
if(bStop==True)return; //Questa riga era messa dopo quella di inizio ciclo for. Invece deve essere qui!
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
OT = OrderType();
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
if (OT==OP_BUY)
{
Price = OOP;
Lot = OrderLots();
Profit+=OrderProfit()+OrderSwap()+OrderCommission();
if (MaxLot<Lot) {MaxLot=Lot; Order= 1;}
n++;
}
if (OT==OP_SELL)
{
Price = OOP;
Lot = OrderLots();
Profit+=OrderProfit()+OrderSwap()+OrderCommission();
if (MaxLot<Lot) {MaxLot=Lot; Order=-1;}
n++;
}
if (OT>1) oo++;
}
}
}
Comment("Profit ",DoubleToStr(Profit,2));
if (Profit>ProfitClose)
{
CloseAllOrders(OP_BUY);
CloseAllOrders(OP_SELL);
}
if (Order==1 && Bid+n*Step*Point<Price)
{
if(OrderSend(Symbol(),OP_SELL,Lot*2,NormalizeDouble(Bid,Digits),slippage,0,0,"",magic,0,Red)!=-1) return;
}
if (Order==-1 && Ask-n*Step*Point>Price)
{
if(OrderSend(Symbol(),OP_BUY,Lot*2,NormalizeDouble(Ask,Digits),slippage,0,0,"",magic,0,Blue)!=-1) return;
}
if (n==0 && oo==0)
{
OrderSend(Symbol(),OP_SELLSTOP,lot,NormalizeDouble(Bid-10*Point,Digits),slippage,0,0,"",magic,0,Red);
OrderSend(Symbol(),OP_BUYSTOP ,lot,NormalizeDouble(Ask+10*Point,Digits),slippage,0,0,"",magic,0,Blue);
}
if (n!=0) DeleteAll(0);
return(0);
}
------------------------------------------------------------------------------------------------------------------------
buona settimana a tutti. Dainesi che dici avanti un altro?
Re: modifica a mqlcmillion EA
Codice: Seleziona tutto
//| Copyright © 2011, Skype: mqlcmillion |
//| http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Skype: mqlcmillion "
#property link "http://cmillion.narod.ru"
//--------------------------------------------------------------------
extern int Step = 10;
extern double ProfitClose = 1.0,
lot = 0.01;
extern int slippage = 3, //The maximum permissible deviation of the price for market orders (orders to buy or sell).
magic = 0; //The magic number order. Can be used as a user-defined identifier.
bool bstop;
//--------------------------------------------------------------------
int init()
{
Comment("-----start--- ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
}
//--------------------------------------------------------------------
int start()
{
double OOP,Price,Lot,Profit,MaxLot;
int OT,n,oo,Order;
if(bStop==True)return;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
OT = OrderType();
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
if (OT==OP_BUY)
{
Price = OOP;
Lot = OrderLots();
Profit+=OrderProfit()+OrderSwap()+OrderCommission();
if (MaxLot<Lot) {MaxLot=Lot; Order= 1;}
n++;
}
if (OT==OP_SELL)
{
Price = OOP;
Lot = OrderLots();
Profit+=OrderProfit()+OrderSwap()+OrderCommission();
if (MaxLot<Lot) {MaxLot=Lot; Order=-1;}
n++;
}
if (OT>1) oo++;
}
}
}
Comment("Profit ",DoubleToStr(Profit,2));
if (Profit>ProfitClose)
{
CloseAllOrders(OP_BUY);
CloseAllOrders(OP_SELL);
}
if (Order==1 && Bid+n*Step*Point<Price)
{
if(OrderSend(Symbol(),OP_SELL,Lot*2,NormalizeDouble(Bid,Digits),slippage,0,0,"",magic,0,Red)!=-1) return;
}
if (Order==-1 && Ask-n*Step*Point>Price)
{
if(OrderSend(Symbol(),OP_BUY,Lot*2,NormalizeDouble(Ask,Digits),slippage,0,0,"",magic,0,Blue)!=-1) return;
}
if (n==0 && oo==0)
{
OrderSend(Symbol(),OP_SELLSTOP,lot,NormalizeDouble(Bid-10*Point,Digits),slippage,0,0,"",magic,0,Red);
OrderSend(Symbol(),OP_BUYSTOP ,lot,NormalizeDouble(Ask+10*Point,Digits),slippage,0,0,"",magic,0,Blue);
}
if (n!=0) DeleteAll(0);
return(0);
}
//-----------------------------------------------------------------
bool CloseAllOrders(int tip)
{
bool error=true;
int err,nn,OT,OMN;
while(true)
{
for (int j = OrdersTotal()-1; j >= 0; j--)
{
if (OrderSelect(j, SELECT_BY_POS))
{
OMN = OrderMagicNumber();
if (OrderSymbol() == Symbol() && OMN == magic)
{
OT = OrderType();
if (OT != tip) continue;
if (OT==OP_BUY)
{
error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,Blue);
if (error) Comment("Close order N ",OrderTicket()," Profit ",OrderProfit(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
if (OT==OP_SELL)
{
error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,Red);
if (error) Comment("Close order N ",OrderTicket()," Profit ",OrderProfit(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
if (!error)
{
err = GetLastError();
if (err<2) continue;
if (err==129)
{ Comment("Wrong price ",TimeToStr(TimeCurrent(),TIME_SECONDS));
RefreshRates();
continue;
}
if (err==146)
{
if (IsTradeContextBusy()) Sleep(2000);
continue;
}
Comment("Error ",err," close order N ",OrderTicket(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
}
}
}
int n=0;
for (j = 0; j < OrdersTotal(); j++)
{
if (OrderSelect(j, SELECT_BY_POS))
{
OMN = OrderMagicNumber();
if (OrderSymbol() == Symbol() && OMN == magic)
{
OT = OrderType();
if (OT != tip) continue;
if (OT==OP_BUY || OT==OP_SELL) n++;
}
}
}
if (n==0) break;
nn++;
if (nn>10) {Alert(Symbol()," Failed to close all trades, there are still ",n);return(0);}
Sleep(1000);
RefreshRates();
bStop = True;
}
return(1);
}
//--------------------------------------------------------------------
bool DeleteAll(int tip)
{
bool error;
int err,n,OMN,OT;
while(true)
{
error=true;
for (int j = OrdersTotal()-1; j >= 0; j--)
{
if (OrderSelect(j, SELECT_BY_POS))
{
OMN = OrderMagicNumber();
if (OrderSymbol() == Symbol() && OMN == magic)
{
OT = OrderType();
if (OT>1 && (tip==0 || OT==tip)) error=OrderDelete(OrderTicket());
}
}
}
if (error) break;
n++;
if (n>10) break;
Sleep(1000);
}
return(1);
}
//-------------------------------------------------------
Re: modifica a mqlcmillion EA
E certo! Nelle dichiarazioni l'hai scritta bstop mentre quando la usi la scrivi bStop. MQL è case sensitive, le maiuscole fanno differenza.
Chi c’è in linea
Visitano il forum: Nessuno e 0 ospiti