Latest update in post 1, fixing the multiple-trades thingy. It was the usual, a copy/paste/forgot-to-edit bloop.
Coders, to save a re-download go to
void HasSellFilled()
and find this line of code:
string name = Next
BuyLineName;
and change the highlighted bit then recompile
string name = Next
SellLineName;
I have reintroduced the BB0, BB1 etc value displays until we are sure the code is watertight.
I ran a visual backtest, M15 Open prices; this is what pointed me to the bloop. Allowing the test to continue, I noticed that there are occasional double trades at the same level. It looks as though the pending trade line deletion fails from time to time, but I have no idea why.
Here is the void HasBuyFilled() function with additional comments to explain my logic more fully:
Code: Select all
void HasBuyFilled()
{
//This function examines the Bid to see if a pending Buy price has been reached, and sends the trade if so.
//Uses the Bid for buys also, as this is the price we see on the chart
double take, stop, price;
int type;
bool CancelTrade = false;
//Set pending price
string name = NextBuyLineName;
if (name != "")
{
if (ObjectFind(name) > -1) double PendingPrice = ObjectGet(name, OBJPROP_PRICE1);
}//if (name != "")
//Initial trade. If risetoline exists, meaning that the first trade has yet to be sent.
if (ObjectFind(risetoline) > -1)
{
name = risetoline;
PendingPrice = ObjectGet(name, OBJPROP_PRICE1);
}//if (ObjectFind(risetoline) > -1)
RefreshRates();
if (Bid >= PendingPrice && PendingPrice > 0)
{
//Ensure that OpenTrades + 1 is < ((NoOfTrades * 2) -1). If it is == ((NoOfTrades * 2) -1),
//a further trade would leave the grid fully populated with hedged trades achieving nothing but
//paying the crim shed-loads of swap. In this case, close the position.
if (IsBasketStopLossHit(OP_BUY) )
{
CloseAllTrades();
if (ForceTradeClosure) CloseAllTrades();
DeleteRemainingPendingLines();//Remove pending price lines
return;
}//if (IsBasketStopLossHit(OP_BUY) )
//If we are looking for an initial trade, only take it if the previous candle closed below the line
if (name == risetoline)
{
if (iOpen(NULL, BoxTimeFrame, 1) >= PendingPrice) return;
}//if (name == risetoline)
price = Ask;
type = OP_BUY;
bool result = SendSingleTrade(type, TradeComment, SendLot, price, stop, take);
if (result)
{
if (name == risetoline) SetUpBuyGrid();
//Move the pending sell to half-way up the CZ box.
if (ObjectFind(falltoline) > -1 && OpenTrades == 0)
{
double ltarget = ObjectGet(falltoline, OBJPROP_PRICE1);
double extent = (PendingPrice - ltarget) / 2;
price = NormalizeDouble(ltarget + extent, Digits);
ObjectMove(falltoline, 0, Time[0], price);
}//if (ObjectFind(falltoline) > -1)
//Delete the pending trade line
ObjectDelete(name);
}//if (result)
}//if (Bid >= PendingPrice && PendingPrice > 0)
}//End void HasBuyFilled()

Read the effing manual, ok?
Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.
I still suffer from OCCD. Good thing, really.
Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.
To see The Weekly Roundup of stuff you guys might have missed
Click here
My special thanks to Thomas (tomele) for all the incredible work he does here.