Come codificare? - pagina 145

 

Ciao Roger09,

Grazie ancora per il tuo aiuto. Il mio obiettivo è quello di utilizzare uno script per spostare il mio stop loss al break even più x pips in un trade di acquisto o al break even meno x pips in un trade di vendita. Ho impostato un tasto di scelta rapida per lo script in modo da poter bloccare rapidamente un po' di profitto quando il trade si muove a mio favore. So che alcuni ES hanno questa funzione, ma preferisco usare uno script in modo da poterlo fare manualmente.

 

Progrmming un stop buy e stop sell

Salve,

Ho un EA con CCI.

Il mio programma mette un acquisto quando la barra precedente è sopra CCI>100, ma voglio comprare 5 pips più in alto l'ultima barra.

Voglio lo stesso con lo stop sell ordre (5 pips sotto l'ultimo minimo)

Ecco il mio EA, potete aiutarmi

Grazie

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

//| Questo MQL è generato da Expert Advisor Builder

//| Expert Advisor Builder per MetaTrader 4 ||

//| |

/+------------------- NON RIMUOVERE QUESTA INTESTAZIONE --------------------+

#define SIGNAL_NONE 0

#define SIGNAL_BUY 1

#define SIGNAL_SELL 2

#define SIGNAL_CLOSEBUY 3

#define SIGNAL_CLOSESELL 4

#proprietà copyright "Expert Advisor Builder"

#proprietà link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 0;

extern bool SignalMail = False;

extern bool EachTickMode = False;;

extern double Lots = 1.0;

extern int Slippage = 30;

extern bool UseStopLoss = True;

extern int StopLoss = 200;

extern bool UseTakeProfit = True;

extern int TakeProfit = 600;

extern bool UseTrailingStop = True; extern int TrailingStop = True;

extern int TrailingStop = 250;

int BarCount;

int Current;

bool TickCheck = Falso;

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

//| funzione di inizializzazione esperto |

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

int init() {

BarCount = Bars;

se (EachTickMode) Current = 0; altrimenti Current = 1;

return(0);

}

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

//| funzione di deinizializzazione esperto |

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

int deinit() {

return(0);

}

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

//| funzione di avvio esperto |

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

int start() {

int Ordine = SIGNAL_NONE;

int Total, Ticket;

doppio StopLossLevel, TakeProfitLevel;

if (EachTickMode && Bars != BarCount) TickCheck = False;

Totale = OrdiniTotali();

Ordine = SIGNAL_NONE;

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

//| Variabile Inizio |

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

double Var1 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 0);

double Var2 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 1);

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 100;

double Buy3_1 = Var2 ;

double Buy3_2 = 100;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Vendere2_1 = Var1 ;

double Sell2_2 = - 100;

double Sell3_1 = Var2 ;

double Sell3_2 = - 100;

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

//| Fine della variabile

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

//Controlla la posizione

bool IsTrade = Falso;

for (int i = 0; i < Totale; i ++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {

IsTrade = True;

if(OrderType() == OP_BUY) {

//Chiudere

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

//| Segnale Inizio(Esci Compra) |

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

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

//| Segnale Fine(Esci dall'Acquisto) |

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

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");

if (!EachTickMode) BarCount = Bars;

IsTrade = Falso;

continuare;

}

//Trailing stop

if(UseTrailingStop && TrailingStop > 0) {

if(Bid - OrderOpenPrice() > Punto * TrailingStop) {

if(OrderStopLoss() < Bid - Point * TrailingStop) {

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);

if (!EachTickMode) BarCount = Bars;

continua;

}

}

}

} else {

//Chiudi

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

//| Segnale Inizio(Esci Vendi) |

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

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

//| Segnale Fine(Esci Vendi) |

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

if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");

if (!EachTickMode) BarCount = Bars;

IsTrade = Falso;

continuare;

}

//Trailing stop

if(UseTrailingStop && TrailingStop > 0) {

if((OrderOpenPrice() - Ask) > (Punto * TrailingStop)) {

if((OrderStopLoss() > (Ask + Punto * TrailingStop)) || (OrderStopLoss() == 0)) {

OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);

if (!EachTickMode) BarCount = Bars;

continuare;

}

}

}

}

}

}

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

//| Signal Begin(Entry) |

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

se (Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2 && Buy3_1 <= Buy3_2) Ordine = SIGNAL_BUY;

se (Sell1_1 < Sell1_2 && Sell2_1 Sell3_2) Ordine = SIGNAL_SELL;

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

//| Fine del segnale |

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

//Compra

if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

if(!IsTrade) {

//Controlla il margine libero

if (AccountFreeMargin() < (1000 * Lotti)) {

Print("Non abbiamo soldi. Margine libero = ", ContoFreeMargin());

return(0);

}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; altrimenti StopLossLevel = 0,0;

if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; altrimenti TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

se(Biglietto > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("Ordine BUY aperto : ", OrderOpenPrice());

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");

} else {

Print("Errore nell'apertura dell'ordine BUY: ", GetLastError());

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

//Vendere

if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

if(!IsTrade) {

//Controlla il margine libero

if (AccountFreeMargin() < (1000 * Lotti)) {

Print("Non abbiamo soldi. Margine libero = ", ContoFreeMargin());

return(0);

}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; altrimenti StopLossLevel = 0,0;

if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; altrimenti TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);

se(Biglietto > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("Ordine SELL aperto : ", OrderOpenPrice());

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");

} else {

Print("Errore nell'apertura dell'ordine SELL: ", GetLastError());

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

if (!EachTickMode) BarCount = Bars;

return(0);

}

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

 
tk748:
Ciao Roger09, grazie ancora per il tuo aiuto. Il mio obiettivo è quello di utilizzare uno script per spostare il mio stop loss al break even più x pips in un trade di acquisto o al break even meno x pips in un trade di vendita. Ho impostato un tasto di scelta rapida per lo script in modo da poter bloccare rapidamente un po' di profitto quando il trade si muove a mio favore. So che alcuni ES hanno questa funzione ma preferisco usare uno script in modo da poterlo fare manualmente.

Se hai bisogno di impostare il tuo stop solo una volta, usa questo codice EA

extern int pips=10;//

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

//||funzione di avvio del programma script |

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

int start()

{

//----

int ot = OrdiniTotali();

for (int i=0; i<ot; i++)

{

int o = OrderSelect(i, SELECT_BY_POS);

if (OrderSymbol() == Symbol()&&OrderType() <2)

{

doppio sl = 0;

se (OrderType() == OP_BUY&& OrderStopLoss() =pips*Point)

sl = OrderOpenPrice() +pips*Point;

se (OrderType() == OP_SELL && (OrderStopLoss() > OrderOpenPrice()||OrderStopLoss()==0)

&&OrderOpenPrice()-Ask>=pips*Point)

sl = OrderOpenPrice() -pips*Point;

if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0))

Stampa("Errore_Modifica - ",GetLastError());

}

}

//----

return(0);

}

 
cgassfr67:
Ciao,

Ho un EA con CCI.

Il mio programma mette un acquisto quando la barra precedente è sopra CCI>100, ma voglio comprare 5 pip più in alto dell'ultima barra.

Voglio lo stesso con lo stop sell ordre (5 pips sotto l'ultimo minimo)

Ecco il mio EA, potete aiutarmi

Grazie

Sostituire

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 100;

double Buy3_1 = Var2 ;

double Buy3_2 = 100;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 100;

double Sell3_1 = Var2 ;

double Sell3_2 = - 100;[/CODE]

To

[CODE]

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 105;

double Buy3_1 = Var2 ;

double Buy3_2 = 105;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 105;

double Sell3_1 = Var2 ;

double Sell3_2 = - 105;
 
Roger09:
Sostituisci
double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 100;

double Buy3_1 = Var2 ;

double Buy3_2 = 100;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 100;

double Sell3_1 = Var2 ;

double Sell3_2 = - 100;[/CODE]

To

[CODE]

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 105;

double Buy3_1 = Var2 ;

double Buy3_2 = 105;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 105;

double Sell3_1 = Var2 ;

double Sell3_2 = - 105;

Sì, ma con questo codice, entrerò all'apertura della prossima barra, e sarei sicuro che la prossima barra aumenterà, quindi un must buy con 5 pip sopra l'ultimo massimo

 

commercio in cima all'ora

Ciao- Sto cercando di invocare il mio EA basato sull'ora del giorno. forse 5am e 5pm, o ogni 30 minuti, ecc.

come posso farlo?

Grazie mille per qualsiasi aiuto.

Kevin

 

Forse questo ti aiuta:

if((TimeHour(TimeLocal( ) )!=5&&TimeMinute(TimeLocal( )!=0)||(TimeHour(TimeLocal( )=17

&&TimeMinute(TimeLocal( ) )!=0))return();

Mettilo all'inizio di start().

 

Qualcuno potrebbe per favore dare un'occhiata a questo e farmi sapere perché non funziona.

Sto cercando di usarlo come commento.

doppio AvgWin()

{

double CountTrades = 0;

doppio CountPips = 0;

for(int Ticket=0;Ticket<OrdersHistoryTotal();Ticket++)

{

OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY);

if(MyAccount==AccountNumber() && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)

{

//------>>>>

if(OrderType()==OP_BUY && OrderClosePrice()>=OrderOpenPrice())

CountTrades++;

{

if(OrderProfit() >= 0)

CountPips++;

}

if(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice())

CountTrades++;

{

se(OrderProfit() >= 0)

CountPips++;

}

}

}

if(CountPips < 0)

return(MathRound(CountPips/CountTrades)*10);

altrimenti

Print("Real Time AvgWin not Available");

return(mAvgWin);

}

 

Prima di tutto sostituire

SELECT_BY_TICKET a SELECT_BY_POS

In secondo luogo, CountPips sempre più di 0.

 
Roger09:
Prima di tutto sostituire

Da SELECT_BY_TICKET a SELECT_BY_POS

Secondo, CountPips sempre più di 0.

Questo va bene

int AvgWin()

{

int CountTrades = 0;

int CountPips = 0;

for(int Ticket=0;Ticket<OrdersHistoryTotal();Ticket++)

{

OrderSelect(Ticket,SELECT_BY_POS,MODE_HISTORY);

if(MyAccount==AccountNumber() && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)

{

//------>>>>

if(OrderType()==OP_BUY && OrderClosePrice()>=OrderOpenPrice())

CountTrades++;

{

se(OrderProfit() >= 0)

CountPips++;

}

if(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice())

CountTrades++;

{

se(OrderProfit() >= 0)

CountPips++;

}

}

}

if(CountPips > 0)

return(MathRound(CountPips/CountTrades)*10);

altrimenti

Print("Real Time AvgWin not Available");

return(mAvgWin);

}