//±-----------------------------------------------------------------+ // 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
riscrivi li codice dell'EA in modo completo
- Assistant