-
-
Save felixdv/e75c3400d3b224e9e5f8a62013f3ee95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+------------------------------------------------------------------+ | |
//| ForexWall-E.mq4 | | |
//| Smart Forex Learning | | |
//| https://smartforexlearning.com | | |
//+------------------------------------------------------------------+ | |
#property copyright "Smart Forex Learning" | |
#property link "https://smartforexlearning.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() | |
{ | |
if (OrdersTotal() > 0) { | |
TrailStops(); | |
return; | |
} | |
double lots = 0.01; | |
int stopLoss = 500; | |
int takeProfit = 500; | |
double ema = iMA(NULL, 0, 300, 0, MODE_EMA, PRICE_CLOSE, 0); | |
if (Ask + 500 * Point < ema) { | |
if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "my forex wall-e order", 12345, 0, Green)) { | |
Print("Buy order succeeded!"); | |
} | |
} | |
if (Bid - 500 * Point > ema) { | |
if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "my forex wall-e order", 12345, 0, Red)) { | |
Print("Sell order succeeded!"); | |
} | |
} | |
} | |
//+------------------------------------------------------------------+ | |
//+------------------------------------------------------------------+ | |
//| Trailing stop function | | |
//+------------------------------------------------------------------+ | |
void TrailStops() | |
{ | |
int trailingStop = 300; | |
for (int i = 0; i < OrdersTotal(); i++) { | |
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { | |
continue; | |
} | |
if (OrderSymbol() != Symbol()) { | |
continue; | |
} | |
if (OrderType() == OP_BUY) { | |
if (Bid - OrderOpenPrice() > trailingStop * Point && OrderStopLoss() < Bid - trailingStop * Point) { | |
if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - trailingStop * Point, OrderTakeProfit(), 0, Green)) { | |
Print("OrderModify error ",GetLastError()); | |
} | |
return; | |
} | |
} else if (OrderType() == OP_SELL) { | |
if (OrderOpenPrice() - Ask > trailingStop * Point && OrderStopLoss() > Ask + trailingStop * Point) { | |
if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + trailingStop * Point, OrderTakeProfit(), 0, Green)) { | |
Print("OrderModify error ",GetLastError()); | |
} | |
return; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment