The default inputs reflect my demo trading on a $10,000 account on the biggies + GJ. I have some lovely trades at the mo.
DIYers:
Comment out line 1942.
Copy this over the top of bool LookForTradeClosure(int ticket).
Code: Select all
bool LookForTradeClosure(int ticket)
{
//Close the trade if the close conditions are met.
//Called from within CountOpenTrades(). Returns true if a close is needed and succeeds, so that COT can increment cc,
//else returns false
if (!BetterOrderSelect(ticket, SELECT_BY_TICKET) ) return(true);
if (BetterOrderSelect(ticket, SELECT_BY_TICKET) && OrderCloseTime() > 0) return(true);
bool CloseThisTrade = false;
string LineName = TpPrefix + DoubleToStr(ticket, 0);
//Work with the lines on the chart that represent the hidden tp/sl
double take = ObjectGet(LineName, OBJPROP_PRICE1);
if (CloseEnough(take, 0) ) take = OrderTakeProfit();
LineName = SlPrefix + DoubleToStr(ticket, 0);
double stop = ObjectGet(LineName, OBJPROP_PRICE1);
if (CloseEnough(stop, 0) ) stop = OrderStopLoss();
///////////////////////////////////////////////////////////////////////////////////////////////////////////
if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)
{
//TP
if (Bid >= take && !CloseEnough(take, 0) && !CloseEnough(take, OrderTakeProfit()) ) CloseThisTrade = true;
//SL
if (Bid <= stop && !CloseEnough(stop, 0) && !CloseEnough(stop, OrderStopLoss())) CloseThisTrade = true;
//Close trade on opposite direction signal
if (BuyCloseSignal)
CloseThisTrade = true;
//Delete pendings on a new signal.
//You may need to make changes here.
if (!CloseThisTrade)
if (SellSignal)
if (DeletePendingsOnNewSignal)
if (MarketTradesTotal == 0)
CloseThisTrade = true;
//Change of SS colour and/or opposite direction FB
//Higher time frame
if (!CloseThisTrade)
if (UseSsHigherTimeFrameControl)
{
if (SsCloseTradesOnHtfColourChange)
if(SsHtfColour != blue)
CloseThisTrade = true;
//Opposite FB signal
if (!CloseThisTrade)
if (SsCloseTradesOnHtfColourChange)
if (!OnlyCloseWhenSuperSlopeAgrees || SsHtfColour == red)
if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
CloseThisTrade = true;
}//if (UseSsHigherTimeFrameControl)
//Medium time frame
if (!CloseThisTrade)
if (UseSsMediumTimeFrameControl)
{
if (SsCloseTradesOnMtfColourChange)
if(SsMtfColour != blue)
CloseThisTrade = true;
//Opposite FB signal
if (!CloseThisTrade)
if (SsCloseTradesOnMtfColourChange)
if (!OnlyCloseWhenSuperSlopeAgrees || SsMtfColour == red)
if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
CloseThisTrade = true;
}//if (UseSsMediumTimeFrameControl)
//Trading time frame
if (!CloseThisTrade)
if (UseSsTradingTimeFrameControl)
{
if (SsCloseTradesOnColourChange)
if(SsColour != blue)
CloseThisTrade = true;
//Opposite FB signal
if (!CloseThisTrade)
if (SsCloseTradesOnColourChange)
if (!OnlyCloseWhenSuperSlopeAgrees || SsColour == red)
if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
CloseThisTrade = true;
}//if (UseSsTradingTimeFrameControl)
//Opposite FB with no slope
if (!CloseThisTrade)
if (CloseOnOppositeFB)
{
if (!UseSsHigherTimeFrameControl)
if (!UseSsMediumTimeFrameControl)
if (!UseSsTradingTimeFrameControl)
if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
CloseThisTrade = true;
}//if (CloseOnOppositeFB)
}//if (OrderType() == OP_BUY)
///////////////////////////////////////////////////////////////////////////////////////////////////////////
if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT)
{
//TP
if (Bid <= take && !CloseEnough(take, 0) && !CloseEnough(take, OrderTakeProfit()) ) CloseThisTrade = true;
//SL
if (Bid >= stop && !CloseEnough(stop, 0) && !CloseEnough(stop, OrderStopLoss())) CloseThisTrade = true;
//Close trade on opposite direction signal
if (SellCloseSignal)
CloseThisTrade = true;
//Change of SS colour and/or opposite direction FB
//Higher time frame
if (!CloseThisTrade)
if (UseSsHigherTimeFrameControl)
{
if (SsCloseTradesOnHtfColourChange)
if(SsHtfColour != blue)
CloseThisTrade = true;
//Opposite FB signal
if (!CloseThisTrade)
if (SsCloseTradesOnHtfColourChange)
if (!OnlyCloseWhenSuperSlopeAgrees || SsHtfColour == blue)
if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
CloseThisTrade = true;
}//if (UseSsHigherTimeFrameControl)
//Medium time frame
if (!CloseThisTrade)
if (UseSsMediumTimeFrameControl)
{
if (SsCloseTradesOnMtfColourChange)
if(SsMtfColour != blue)
CloseThisTrade = true;
//Opposite FB signal
if (!CloseThisTrade)
if (SsCloseTradesOnMtfColourChange)
if (!OnlyCloseWhenSuperSlopeAgrees || SsMtfColour == blue)
if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
CloseThisTrade = true;
}//if (UseSsMediumTimeFrameControl)
//Trading time frame
if (!CloseThisTrade)
if (UseSsTradingTimeFrameControl)
{
if (SsCloseTradesOnColourChange)
if(SsColour != blue)
CloseThisTrade = true;
//Opposite FB signal
if (!CloseThisTrade)
if (SsCloseTradesOnColourChange)
if (!OnlyCloseWhenSuperSlopeAgrees || SsColour == blue)
if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
CloseThisTrade = true;
}//if (UseSsTradingTimeFrameControl)
//Opposite FB with no slope
if (!CloseThisTrade)
if (CloseOnOppositeFB)
{
if (!UseSsHigherTimeFrameControl)
if (!UseSsMediumTimeFrameControl)
if (!UseSsTradingTimeFrameControl)
if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
CloseThisTrade = true;
}//if (CloseOnOppositeFB)
}//if (OrderType() == OP_SELL)
///////////////////////////////////////////////////////////////////////////////////////////////////////////
if (CloseThisTrade)
{
bool result = false;
if (OrderType() < 2)//Market orders
result = CloseOrder(ticket);
else
result = OrderDelete(ticket, clrNONE);
//Actions when trade close succeeds
if (result)
{
DeletePendingPriceLines();
TicketNo = -1;//TicketNo is the most recently trade opened, so this might need editing in a multi-trade EA
OpenTrades--;//Rather than OpenTrades = 0 to cater for multi-trade EA's
return(true);//Makes CountOpenTrades increment cc to avoid missing out ccounting a trade
}//if (result)
//Actions when trade close fails
if (!result)
{
return(false);//Do not increment cc
}//if (!result)
}//if (CloseThisTrade)
//Got this far, so no trade closure
return(false);//Do not increment cc
}//End bool LookForTradeClosure()