//±-----------------------------------------------------------------+ // ZZEA.mq4 //…
- User
//±-----------------------------------------------------------------+ //| ZZ_EA.mq4 | //| Copyright © 2023, Gabriele Bassi | //±-----------------------------------------------------------------+ #property strict
// External input parameters for the EA input double TakeProfitPips = 400; // Take profit in pips input double StopLossPips = 150; // Stop loss in pips input double TrailingStopPips = 10; // Trailing stop in pips
// External input parameters for the indicator input int CCI_Period = 12; input int Momentum_Period = 21; input int RSI_Period = 14; input double SAR_Step = 0.01; input double SAR_Maximum = 0.2;
// OnInit is called when the expert is loaded onto a chart int OnInit() { // Initialization code here return INIT_SUCCEEDED; }
// OnTick is called on every new tick void OnTick() { // Get last bar index in the chart (0 is the currently forming bar, 1 is the last fully formed bar) int lastBarIndex = 1;
code// Retrieve the last known values for the indicator signals double arrowUp = iCustom(Symbol(), 0, "ZZZZZ", CCI_Period, Momentum_Period, RSI_Period, SAR_Step, SAR_Maximum, 0, lastBarIndex); double arrowDown = iCustom(Symbol(), 0, "ZZZZZ", CCI_Period, Momentum_Period, RSI_Period, SAR_Step, SAR_Maximum, 1, lastBarIndex); // If there are no current orders, check for a buy or sell signal if(OrdersTotal() == 0) { if(arrowUp != EMPTY_VALUE) { // If an up arrow (buy signal) is present, send a buy order. double sl = NormalizeDouble(Bid - StopLossPips * Point, Digits); double tp = NormalizeDouble(Bid + TakeProfitPips * Point, Digits); int ticket = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 2, sl, tp, "Buy order based on ZZZZZ", 0, 0, clrGreen); if(ticket < 0) { Print("An error occurred while sending a buy order: ", GetLastError()); } } if(arrowDown != EMPTY_VALUE) { // If a down arrow (sell signal) is present, send a sell order. double sl = NormalizeDouble(Ask + StopLossPips * Point, Digits); double tp = NormalizeDouble(Ask - TakeProfitPips * Point, Digits); int ticket = OrderSend(Symbol(), OP_SELL, 0.1, Bid, 2, sl, tp, "Sell order based on ZZZZZ", 0, 0, clrRed); if(ticket < 0) { Print("An error occurred while sending a sell order: ", GetLastError()); } } } else { // Update the trailing stop for existing orders TrailingStopFunc(); } - Assistant
- User
come faccio a Sincronizzazione del Tempo
- Assistant
La sincronizzazione del tempo in MetaTrader 4 (MT4) si riferisce all'allineamento dell'orologio interno della tua piattaforma di trading con l'orologio del server del tuo broker. Di norma, MT4 dovrebbe sincronizzarsi automaticamente con il tempo del server del tuo broker, ma ecco alcuni passaggi che puoi seguire per assicurarti che la sincronizzazione del tempo sia corretta:
- User
il codice sembra giusto? o c'è qualche errore?
- Assistant
- User
i segnali arrivano correttamente (uso anche l'indicatore zzzzz) ma non apre nessuna posizione. il broker permette ea (ne sto usando altri).
- Assistant
- User
potrebbe essere che nel codice non è definito un lotto?
- Assistant
Nel codice che hai condiviso, il volume dell'ordine (quindi la dimensione del lotto) viene effettivamente specificato nell'invocazione di
OrderSend(). Ecco la parte rilevante per gli ordini di acquisto e vendita:mql4int ticket = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 2, sl, tp, "Buy order based on ZZZZZ", 0, 0, clrGreen); // ... int ticket = OrderSend(Symbol(), OP_SELL, 0.1, Bid, 2, sl, tp, "Sell order based on ZZZZZ", 0, 0, clrRed);