Can't get global basket closure
I tried all I possibly could even started to look into the code but I simply can't have awesome v1m close at my basketcashtakeprofit value.
I even tried looking into the relevant part of the code to see if I'm missing some conditions for a global basket closure but not being a coder I couldn't find anything that would help me understand what I'm missing.
here my relevant set file settings
Trade1AsBasket=true
Trade1BasketCashTarget=10
Trade1BasketCashPercentageTarget=0.0
AllTradesBelongToBasket=true
BasketCashTakeProfit=4.0
BasketCashPercentageTarget=0
I tried both
Trade1AsBasket=true and Trade1AsBasket=false
The relevant code as far as I could understand it
Code: Select all
bool HaveWeReachedGlobalBasketTP()
{
//Close all trades on the platform if a full basket tp is hit.
double BasketProfitTarget = BasketCashTakeProfit;
//Calculate the dynamic tp
if (!CloseEnough(BasketCashPercentageTarget, 0) )
BasketProfitTarget = (AccountBalance() * BasketCashPercentageTarget) / 100;
if (EntirePositionCashUpl >= BasketProfitTarget)
return (true);
//Not reached the target
return(false);
}//bool HaveWeReachedGlobalBasketTP()
//Have we reached a whole platform basket target?
if (AllTradesBelongToBasket)
{
if (HaveWeReachedGlobalBasketTP() )
{
Alert("Global profit target reached. All trades should have closed.");
NuclearOption();
//All trades must be closed, so keep banging away until they are.
if (ForceTradeClosure)
{
while (ForceTradeClosure)
{
NuclearOption();
if (ForceTradeClosure)
Sleep(5000);//5 seconds
}//while (ForceTradeClosure)
}//if (ForceTradeClosure)
}//if (HaveWeReachedGlobalBasketTP() )
}//if (AllTradesBelongToBasket)
//All trades on the platform belong to the same basket
EntirePositionCashUpl = 0;
int type;//Saves the OrderType() for consulatation later in the function
if (OrdersTotal() == 0) return;
//Iterating backwards through the orders list caters more easily for closed trades than iterating forwards
for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
{
bool TradeWasClosed = false;//See 'check for possible trade closure'
//Ensure the trade is still open
if (!OrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;
EntirePositionCashUpl+= OrderProfit() + OrderSwap() + OrderCommission();
//Ensure the EA 'owns' this trade
if (OrderSymbol() != symbol) continue;
if (OrderMagicNumber() != magic) continue;
//The time of the most recent trade
if (OrderOpenTime() > LatestTradeTime)
{
LatestTradeTime = OrderOpenTime();
LatestTradeTicketNo = OrderTicket();
}//if (OrderOpenTime() > LatestTradeTime)
//The time of the earliest trade
if (OrderOpenTime() < EarliestTradeTime)
{
EarliestTradeTime = OrderOpenTime();
EarliestTradeTicketNo = OrderTicket();
}//if (OrderOpenTime() < EarliestTradeTime)
//All conditions passed, so carry on
type = OrderType();//Store the order type
//Store the latest trade sent. Most of my EA's only need this final ticket number as either they are single trade
//bots or the last trade in the sequence is the important one. Adapt this code for your own use.
DisplayUserFeedback();
}//End void OnTimer()
I would like to close all positions NuclearOption when the combined open positions is > than 4 (BasketCashTakeProfit=4.0)
I'm using TradeReport to track the profit and can witness it goes way pass my BasketCashTakeProfit value without awesome closing all positions.
What is wrong with me? Any help greatly appreciated.
Thanks 1D
Side note, this set file generated +600 demo € net profit since 1st September!!
You do not have the required permissions to view the files attached to this post.