I am learning MQL and attempting to write a trade manager EA… What I will eventually have it doing is a stop loss, breakeven, and trailing stop. But, for starters… it’s just the stop loss for now! For some reason I'm getting a warning when I compile it… (Function "StopLoss" is not referenced and will be removed from exp-file) I'm not sure what this even means!!!
I am hoping that someone can take a look at this and tell me what I'm doing wrong… it simply doesn’t work!
Thanks to everyone for taking the time to help!
I am hoping that someone can take a look at this and tell me what I'm doing wrong… it simply doesn’t work!
Thanks to everyone for taking the time to help!
Inserted Code
#include <WinUser32.mqh> #include <stdlib.mqh> extern bool StopLoss = true; extern int StopLossPips = 150; int cnt=0; //loop counter double bid, ask; // For storing the Bid\Ask double point, digits; // Saves the Point and Digits of an order //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- // Stop if there is nothing to do if (OrdersTotal()==0) { Comment("No trades to manage!"); return(0); } MonitorTrades(); // StopLoss, BreakEven, & TrailingStop //---- return(0); } //+------------------------------------------------------------------+ void MonitorTrades() { bool ManageTrade; // tell the program when there is a trade to manage for (cnt=0;cnt<OrdersTotal();cnt++) { OrderSelect(cnt, SELECT_BY_POS); if (OrderSymbol()==Symbol()) // Continue if order is correct symbol { // Set up bid and ask so the program can use them to calculate SL, BE, & TS bid = MarketInfo(OrderSymbol(), MODE_BID); ask = MarketInfo(OrderSymbol(), MODE_ASK); point = MarketInfo(OrderSymbol(), MODE_POINT); digits = MarketInfo(OrderSymbol(), MODE_DIGITS); } } // Close For loop } // end of MonitorTrades // ---------------------------------------------- // ** StopLoss ** // ---------------------------------------------- void StopLoss() // Create StopLoss { int ticket; if( (StopLoss == true) && (StopLossPips > 0) ) { if( OrderType() == OP_BUY ) { if( StopLoss == 0) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid-(Point*StopLossPips), OrderTakeProfit(), 0, CLR_NONE); Print("StopLoss: StopLoss=", Bid-(StopLossPips*Point), " ticket=", OrderTicket()); return(0); } } if( OrderType() == OP_SELL ) { if( StopLoss == 0) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(StopLossPips*Point),OrderTakeProfit(), 0, CLR_NONE); Print("StopLoss: StopLoss=", Ask+(StopLossPips*Point), " ticket=", OrderTicket()); return(0); } } } } // End StopLoss // ---------------------------------------------- // ** BreakEven ** // ---------------------------------------------- // End BreakEven // ---------------------------------------------- // ** TrailingStop ** // ---------------------------------------------- // End TrailingStop