//+------------------------------------------------------------------+ //| HiddenSLandTP.mq4 | //| Copyright 2017, M Wilson. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, M Wilson." #property link "https://www.mql5.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Class for storing trade data | //+------------------------------------------------------------------+ class C_Trade { private: bool DeleteLine(const string strName="HL_HSLTP_",bool boolReportError=True); bool CreateHorizontalLine(const string name="HLine",double price=0,const color clr=clrRed,const ENUM_LINE_STYLE style=STYLE_SOLID,const int width=1,const bool back=false,const bool selection=true,const bool hidden=false,const long z_order=0); public: //Trade Variables int m_intTicket; int m_intMagicNumber; string m_strSymbol; int m_intType; datetime m_dtOpenTime; double m_dblOpenPrice; double m_dblStopLoss; double m_dblTakeProfit; double m_dblHiddenStopLoss; double m_dblHiddenTakeProfit; bool m_boolHasBeenClosed; int m_intSelectAttempts; //Constructor/Desctructor C_Trade(){m_boolHasBeenClosed=False;m_intSelectAttempts=0;}; ~C_Trade(){}; //Public Functions bool InitiateFromSelectedTrade(); //Populate class from selected trade data. bool BreachHiddenStopLossOrTakeProfit(); //Look for breaches of the hidden stoploss or takeprofit. void PlotSLandTP(); //Draw stoploss and takeprofit as horizontal lines. }; //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Initiate Trade from Selected Trade | //+------------------------------------------------------------------+ bool C_Trade::InitiateFromSelectedTrade() { //Order Select on an active trade must have been called before this function is run //It populates the trade using the details of the selected trade. //Only works on live buy/sell orders if(!(OrderType()==OP_BUY || OrderType()==OP_SELL)) return False; //Replicate the selected trade. this.m_intTicket=OrderTicket(); this.m_intMagicNumber=OrderMagicNumber(); this.m_strSymbol=OrderSymbol(); this.m_intType=OrderType(); this.m_dtOpenTime=OrderOpenTime(); this.m_dblOpenPrice=OrderOpenPrice(); this.m_dblStopLoss=OrderStopLoss(); this.m_dblTakeProfit=OrderTakeProfit(); //By default, set the hidden stoploss and takeprofit to the current stoploss and takeprofit. //They need to be changed later on. this.m_dblHiddenStopLoss=this.m_dblStopLoss; this.m_dblHiddenTakeProfit=this.m_dblHiddenTakeProfit; return True; } //+------------------------------------------------------------------+ //| Check for breach of hidden stoploss or takeprofit | //+------------------------------------------------------------------+ bool C_Trade::BreachHiddenStopLossOrTakeProfit() { bool boolRet=False; RefreshRates(); if(this.m_intType==OP_BUY) { //Test buy trade to see if the bid has passed the hidden stoploss or takeprofit double dblBid=MarketInfo(this.m_strSymbol,MODE_BID); if(dblBid>this.m_dblHiddenTakeProfit || dblBid