stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Desky. TDesk's trading drone.
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5545
Page 31 of 50
Author:  SteveHopwood [ Wed Jun 19, 2019 11:56 am ]
Post subject:  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

:xm: :rocket:
Author:  SteveHopwood [ Sat Jul 20, 2019 1:50 pm ]
Post subject:  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:

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;      
 
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;

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)
Scroll down to/search for: if (bid >= targetPrice)//It is, so set up the trade
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)
         
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.

:xm: :rocket:
Author:  taipan [ Tue Jul 30, 2019 3:10 am ]
Post subject:  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
TDesk Desky TradingPartner EA - 30072019.set
TDesk_Trading_partner_v3r_chart_image_1.png
Author:  wallywonka [ Tue Jul 30, 2019 4:25 am ]
Post subject:  Desky. TDesk's trading drone.

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
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.
Author:  taipan [ Tue Jul 30, 2019 5:21 am ]
Post subject:  Desky. TDesk's trading drone.

wallywonka » Tue Jul 30, 2019 12:25 pm wrote:
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
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.
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 .

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.
Author:  dndimov [ Tue Jul 30, 2019 2:36 pm ]
Post subject:  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 :)
Author:  SteveHopwood [ Tue Jul 30, 2019 2:46 pm ]
Post subject:  Desky. TDesk's trading drone.

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 :)
I will check the code to see if I have left anything out.

:xm: :rocket:
Author:  SteveHopwood [ Thu Aug 01, 2019 12:21 pm ]
Post subject:  Desky. TDesk's trading drone.

I have checked the code and cannot see anything wrong.

:xm: :rocket:
Author:  SteveHopwood [ Mon Aug 05, 2019 12:26 pm ]
Post subject:  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:

Code: Select all

   //We cannot close hedge trades on an EXIT signal if hedging on the EXIT signal is enabled
   if (HedgeOnEXITSignal)
      closeHedgeOnEXITSignal = false;
Do a search for: SM("Recovery is enabled" + NL);
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);
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:

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)
:xm: :rocket:
Author:  SteveHopwood [ Sun Aug 11, 2019 9:45 am ]
Post subject:  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;

:xm: :rocket:
All times are UTC Page 31 of 50