Desky. TDesk's trading drone.
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Desky. TDesk's trading drone.
V 3q is in post 1. This contains the same check that I have posted about in the SPB thread, so read about it at http://www.stevehopwoodforex.com/phpBB3 ... 93#p167793

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.
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.
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Desky. TDesk's trading drone.
V 3r is in post 1.
Thomas wrote to me last week about Desky still trying to breech the broker's maximum demo orders sometimes. The fault turned out to be LUC making one of his rare visits for a coffee. I am a bit better at this stuff these days, so LUC has mostly needed to find someone else to bug. Not this time.
I had forgotten to add a max trades allowed by the broker check to the gap-filling function. I have fixed this in 3r.
DIYers, it is not merely a case of adding the check. Taking a buy grid as an example: if filling the gap would exceed the brokers max trades limit, then we need to delete the stop order at the top of the grid. The DIY is not hard - just bitty.
Navigate to: void fillTheGap(string symbol)
The comment at the top of the function briefly describes what it does. Add this underneath:
Ignore the error message if you do an immediate compile; we will fix this further down.
Scroll down/search for this line:
if (ask <= targetPrice)//It is, so set up the trade
The next line of code is: sendTrade = true;
Insert this immediately above sendTrade = true;
Scroll down to/search for: if (bid >= targetPrice)//It is, so set up the trade
Insert this immediately above sendTrade = true;
Scroll down to: bool result = sendSingleTrade(symbol, type, TradeComment, sendLots, price, stop, take);
Remove the 'bool' so the code reads:
result = sendSingleTrade(symbol, type, TradeComment, sendLots, price, stop, take);
Note that the stop order deletion ignores limit orders. This needs some extra code if any of you folks are using limit orders; sing out if so.

Thomas wrote to me last week about Desky still trying to breech the broker's maximum demo orders sometimes. The fault turned out to be LUC making one of his rare visits for a coffee. I am a bit better at this stuff these days, so LUC has mostly needed to find someone else to bug. Not this time.
I had forgotten to add a max trades allowed by the broker check to the gap-filling function. I have fixed this in 3r.
DIYers, it is not merely a case of adding the check. Taking a buy grid as an example: if filling the gap would exceed the brokers max trades limit, then we need to delete the stop order at the top of the grid. The DIY is not hard - just bitty.
Navigate to: void fillTheGap(string symbol)
The comment at the top of the function briefly describes what it does. Add this underneath:
Code: Select all
//Define a variable to tell the order sending routine that the extreme
//stop order needs deleting.
bool deleteNeeded = false;
if (!checkBrokerMaxTradesOnPlatform(1) )
deleteNeeded = true;
bool result = true;
Scroll down/search for this line:
if (ask <= targetPrice)//It is, so set up the trade
The next line of code is: sendTrade = true;
Insert this immediately above sendTrade = true;
Code: Select all
//Does a stop order at the top of the grid need deleting?
if (deleteNeeded)
{
if (betterOrderSelect(highestBuyStopTicketNo, SELECT_BY_TICKET, MODE_TRADES))
{
result = OrderDelete(highestBuyStopTicketNo, clrNONE);
//In case something has gone wrong. Abort the function if so.
if (!result)
return;
}//if (betterOrderSelect(highestBuyStopTicketNo, SELECT_BY_TICKET, MODE_TRADES))
}//if (deleteNeeded)
Insert this immediately above sendTrade = true;
Code: Select all
//Does a stop order at the bottom of the grid need deleting?
if (deleteNeeded)
{
if (betterOrderSelect(lowestSellStopTicketNo, SELECT_BY_TICKET, MODE_TRADES))
{
result = OrderDelete(lowestSellStopTicketNo, clrNONE);
//In case something has gone wrong. Abort the function if so.
if (!result)
return;
}//if (betterOrderSelect(lowestSellStopTicketNo, SELECT_BY_TICKET, MODE_TRADES))
}//if (deleteNeeded)
Remove the 'bool' so the code reads:
result = sendSingleTrade(symbol, type, TradeComment, sendLots, price, stop, take);
Note that the stop order deletion ignores limit orders. This needs some extra code if any of you folks are using limit orders; sing out if so.
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.
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.
-
taipan
- Trader
- Posts: 355
- Joined: Sat Feb 16, 2013 11:27 am
Desky. TDesk's trading drone.
Some errors had been found on Desky v3r as it did not take basket profit as configured @4%. Also it showed that the current value is130.84 where as the profit is 413.13 and the highest value is 144.71 which is also wrong on the chart. See attached image and set file
You do not have the required permissions to view the files attached to this post.
-
wallywonka
- Trader
- Posts: 188
- Joined: Thu May 12, 2016 7:46 am
Desky. TDesk's trading drone.
Hii Taipan, just quickly looking at your screenshot it looks like your running two different setups? The comments and lot size don't match Desky.taipan » Tue Jul 30, 2019 3:10 am wrote:Some errors had been found on Desky v3r as it did not take basket profit as configured @4%. Also it showed that the current value is130.84 where as the profit is 413.13 and the highest value is 144.71 which is also wrong on the chart. See attached image and set file
-
taipan
- Trader
- Posts: 355
- Joined: Sat Feb 16, 2013 11:27 am
Desky. TDesk's trading drone.
The 1st set file was used by accident and amended quickly and reverted back to the intended set file and hence the lot size and comments have differences .wallywonka » Tue Jul 30, 2019 12:25 pm wrote:Hii Taipan, just quickly looking at your screenshot it looks like your running two different setups? The comments and lot size don't match Desky.taipan » Tue Jul 30, 2019 3:10 am wrote:Some errors had been found on Desky v3r as it did not take basket profit as configured @4%. Also it showed that the current value is130.84 where as the profit is 413.13 and the highest value is 144.71 which is also wrong on the chart. See attached image and set file
I know my mistake now and had closed the different comment position. Now the display is set correctly.
Thank you for pointing up the differences due to different comments.
Please dicard this post as the matter is now solved.
-
dndimov
- Posts: 7
- Joined: Thu Nov 30, 2017 8:21 am
Desky. TDesk's trading drone.
Hi, treaders
Many thanks to all for coding this for as . I have one problem with a pending orders from the grid, when i used veto signal for exit, normal ordres is closed but pending orders from grid is stil activ, even i check close all pending order on exit signal to true.
How to correct this ?
10x
Green pips to all
Many thanks to all for coding this for as . I have one problem with a pending orders from the grid, when i used veto signal for exit, normal ordres is closed but pending orders from grid is stil activ, even i check close all pending order on exit signal to true.
How to correct this ?
10x
Green pips to all
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Desky. TDesk's trading drone.
I will check the code to see if I have left anything out.dndimov » Tue Jul 30, 2019 2:36 pm wrote:Hi, treaders
Many thanks to all for coding this for as . I have one problem with a pending orders from the grid, when i used veto signal for exit, normal ordres is closed but pending orders from grid is stil activ, even i check close all pending order on exit signal to true.
How to correct this ?
10x
Green pips to all
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.
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.
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Desky. TDesk's trading drone.
I have checked the code and cannot see anything wrong.

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.
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.
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Desky. TDesk's trading drone.
V 3s is in post 1, in response to a request by orso to add the ability to hedge following an EXIT signal.
The input is: HedgeOnEXITSignal. You will find it underneath the HedgeOnOppositeDirectionSignal input. You cannot have both HedgeOnEXITSignal and closeHedgeOnEXITSignal enabled for obvious reasons, so Desky checks and disables closeHedgeOnEXITSignal if necessary.
DIYers/code checkers: do a search for: extern bool HedgeOnOppositeDirectionSignal. Insert this underneath:
extern bool HedgeOnEXITSignal=false;
Do a search for: secureSetTimer(EventTimerIntervalSeconds);//Explanation at the top of the function
Insert this underneath - in fact anywhere in OnInit() will do:
Do a search for: SM("Recovery is enabled" + NL);
I have replaced the hedge display code that follows with this:
I have added some more conditionals to void shouldWeHedge(string symbol, int pairIndex) to cut out unnecessary steps as well as adding the new code blocks, so replace the entire function with this:

The input is: HedgeOnEXITSignal. You will find it underneath the HedgeOnOppositeDirectionSignal input. You cannot have both HedgeOnEXITSignal and closeHedgeOnEXITSignal enabled for obvious reasons, so Desky checks and disables closeHedgeOnEXITSignal if necessary.
DIYers/code checkers: do a search for: extern bool HedgeOnOppositeDirectionSignal. Insert this underneath:
extern bool HedgeOnEXITSignal=false;
Do a search for: secureSetTimer(EventTimerIntervalSeconds);//Explanation at the top of the function
Insert this underneath - in fact anywhere in OnInit() will do:
Code: Select all
//We cannot close hedge trades on an EXIT signal if hedging on the EXIT signal is enabled
if (HedgeOnEXITSignal)
closeHedgeOnEXITSignal = false;
I have replaced the hedge display code that follows with this:
Code: Select all
if (HedgeOnOppositeDirectionSignal)
SM("Hedging is enabled following an opposite direction signal" + NL);
if (HedgeOnFlatSignal)
SM("Hedging is enabled following a FLAT signal" + NL);
if (HedgeOnEXITSignal)
SM("Hedging is enabled following an EXIT signal" + NL);
Code: Select all
void shouldWeHedge(string symbol, int pairIndex)
{
//calculate and send a hedge trade if necessary
bool sendHedge = false;
int hedgeType = 0;
double hedgeLotSize = 0;
double price = 0;
//Buys
if (buyOpen)
{
//SHORT
if (HedgeOnOppositeDirectionSignal)
if (TDeskSignals[pairIndex] == SHORT)
{
sendHedge = true;
hedgeType = OP_SELL;
hedgeLotSize = normalizeLots(symbol, (totalBuyLots * PercentageToHedge) / 100);
}//if (TDeskSignals[pairIndex] == SHORT)
//FLAT
if (!sendHedge)
if (HedgeOnFlatSignal)
if (TDeskSignals[pairIndex] == FLAT)
{
sendHedge = true;
hedgeType = OP_SELL;
hedgeLotSize = normalizeLots(symbol, (totalBuyLots * PercentageToHedge) / 100);
}//if (TDeskSignals[pairIndex] == FLAT)
//EXIT
if (!sendHedge)
if (HedgeOnEXITSignal)
if (TDeskSignals[pairIndex] == EXIT)
{
sendHedge = true;
hedgeType = OP_SELL;
hedgeLotSize = normalizeLots(symbol, (totalBuyLots * PercentageToHedge) / 100);
}//if (TDeskSignals[pairIndex] == EXIT)
if (sendHedge)
{
price = bid;
hedgeIsSell = true;
hedged = true;
}//if (sendHedge)
}//if (buyOpen)
//Sells
if (sellOpen)
{
//LONG
if (HedgeOnOppositeDirectionSignal)
if (TDeskSignals[pairIndex] == LONG)
{
sendHedge = true;
hedgeType = OP_BUY;
hedgeLotSize = normalizeLots(symbol, (totalSellLots * PercentageToHedge) / 100);
}//if (TDeskSignals[pairIndex] == LONG)
//FLAT
if (!sendHedge)
if (HedgeOnFlatSignal)
if (TDeskSignals[pairIndex] == FLAT)
{
sendHedge = true;
hedgeType = OP_BUY;
hedgeLotSize = normalizeLots(symbol, (totalSellLots * PercentageToHedge) / 100);
}//if (TDeskSignals[pairIndex] == FLAT)
//EXIT
if (!sendHedge)
if (HedgeOnEXITSignal)
if (TDeskSignals[pairIndex] == EXIT)
{
sendHedge = true;
hedgeType = OP_BUY;
hedgeLotSize = normalizeLots(symbol, (totalSellLots * PercentageToHedge) / 100);
}//if (TDeskSignals[pairIndex] == EXIT)
if (sendHedge)
{
price = ask;
hedgeIsBuy = true;
hedged = true;
}//if (sendHedge)
}//if (sellOpen)
if (sendHedge)
{
hedged = false;
bool result = sendSingleTrade(symbol, hedgeType, HedgeTradeComment, hedgeLotSize, price, 0, 0 );
if (result)
{
countOpenTrades(symbol);
}//if (result)
}//if (sendHedge)
}//End void shouldWeHedge(string symbol, int pairIndex)
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.
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.
- SteveHopwood
- Owner
- Posts: 9904
- Joined: Tue Nov 15, 2011 8:43 am
- Location: Misterton - an insignificant village in England. Very pleasant to live in.
Desky. TDesk's trading drone.
There is a teensy update to Desky in post 1. This accommodates the latest version of TDeskSignals.
DIY: go to the top of the file and replace #define minTDSigVersion 2.4 with #define minTDSigVersion 2.5
Go to: int OnInit(). Add this at the top of the function:
FirstTemplateRun=true;

DIY: go to the top of the file and replace #define minTDSigVersion 2.4 with #define minTDSigVersion 2.5
Go to: int OnInit(). Add this at the top of the function:
FirstTemplateRun=true;
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.
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.