V 2w is in post 1.
Here are the details For you DIYers.
Remember to F7 at every step if you are new to this, to make sure you have not introduced a fault.
Go to the top of the file and do a search for, "GridTypes". There is an option in the list that is nonsense - Market_Orders. Delete this so the code looks like this:
Code: Select all
enum GridTypes
{
Stop,
Limit,
Both,
};
Go to void SendBuyGrid(string symbol, int type, double price, double lot, int gridSize)
I noticed that a previous fix has gone missing, so this is something for you to check. Scroll down to:
Code: Select all
if (UseNextLevelForTP)//Set the tp at the open price of the next trade
If the next line is:
take = price;
It needs replacing with:
take = NormalizeDouble(price + (DistanceBetweenTrades / factor), digits);
I have added some more info to the order failure alert. Scroll down to the block of code starting with this comment:
Code: Select all
//Each trade in the grid must be sent, so deal with failures
Copy this over the top of the existing block:
Code: Select all
//Each trade in the grid must be sent, so deal with failures
if (!result)
{
int err=GetLastError();
if (err == 132)//Market is closed
return;
if (type == OP_BUYSTOP)
Alert(symbol, " Buy stop failure: Lots ", lot, ": Price ", price, ": Ask ", ask, ": TP ", take, ": SL ", stop);
else
Alert(symbol, " Buy limit failure: Lots ", lot, ": Price ", price, ": Ask ", ask, ": TP ", take, ": SL ", stop);
Sleep(5000);
cc--;
continue;//Do not want price incrementing
}//if (!result)
The next function down is void SendSellGrid(string symbol, int type, double price, double lot, int gridSize).
Again, if there is a "take = price" then it needs replacing with:
take = NormalizeDouble(price - (DistanceBetweenTrades / factor), digits);
Copy this over the top of the existing error reporting block:
Code: Select all
//Each trade in the grid must be sent, so deal with failures
if (!result)
{
int err=GetLastError();
if (err == 132)//Market is closed
return;
if (type == OP_SELLSTOP)
Alert("Sell stop: Lots ", lot, ": Price ", price, ": Bid ", bid, ": TP ", take, ": SL ", stop);
else
Alert("Sell limit: Lots ", lot, ": Price ", price, ": Bid ", bid, ": TP ", take, ": SL ", stop);
Sleep(5000);
cc--;
continue;//Do not want price incrementing
}//if (!result)
Go to void DoPendingOrdersDeletionAndReplacement(string symbol, int signal)
I was looking for other possible causes of the invalid stops thingy reported
http://www.stevehopwoodforex.com/phpBB3 ... 95#p166295 and noticed that only stop order grids were replaced.
Scroll down to this comment:
Code: Select all
//Replace a pending order grid following a return to a trading signal.
This is the start of the code block that replaces pending trades following a return to LONG or SHORT after being FLAT. You will see this a few lines further down: "if (targetNoOfPendingTrades > 0)". You can see that only OP_BUYSTOP orders are sent. Copy this over the top of the existing block:
Code: Select all
if (targetNoOfPendingTrades > 0)
{
//Stop orders
if (TypeOfGrid == Stop || TypeOfGrid == Both)
SendBuyGrid(symbol, OP_BUYSTOP, HighestBuyPrice, Lot, targetNoOfPendingTrades);
//Limit orders
if (TypeOfGrid == Limit || TypeOfGrid == Both)
SendBuyGrid(symbol, OP_BUYLIMIT, LowestBuyPrice, Lot, targetNoOfPendingTrades);
}//if (targetNoOfPendingTrades > 0)
Scroll down to the next "if (targetNoOfPendingTrades > 0)". Here you will see that only OP_SELLSTOP orders are sent. Replace the code block with:
Code: Select all
if (targetNoOfPendingTrades > 0)
{
//Stop orders
if (TypeOfGrid == Stop || TypeOfGrid == Both)
SendSellGrid(symbol, OP_SELLSTOP, LowestSellPrice, Lot, targetNoOfPendingTrades);
//Limit orders
if (TypeOfGrid == Limit || TypeOfGrid == Both)
SendSellGrid(symbol, OP_SELLLIMIT, HighestSellLimitPrice, Lot, targetNoOfPendingTrades);
}//if (targetNoOfPendingTrades > 0)
Shrug your shoulders philosophically if you totally bugger things up, and download the fix from post 1.
