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

Desky. TDesk's trading drone.
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5545
Page 22 of 50
Author:  SteveHopwood [ Fri Feb 15, 2019 6:21 pm ]
Post subject:  Desky. TDesk's trading drone.

Don't worry about this folks. Tutank contacted me about it so I looked at the code. It was bollocks - a Steve Classic. Blind chance allowed the routine to appear to work from time to time.

I shall be releasing an update over the weekend. If you want a quick DIY, do a search for "//Stop/limit orders sent when SendPendingTrades is enabled" and copy this over the top of the code:

Code: Select all

   //Stop/limit orders sent when SendPendingTrades is enabled
   if (SendPendingTrades)
      if (DeletePendingOrderWhenSignalChanges)
         if (PendingTradesTotal > 0)
         {
            //Long pendings
            if (BuyStopOpen || BuyLimitOpen)
               if (signal != LONG)
               {
                  DeletePendingOrders(symbol);
                  CountOpenTrades(symbol);         
               }//if (signal != LONG)
               
            //Short pendings
            if (SellStopOpen || SellLimitOpen)
               if (signal != SHORT)
               {
                  DeletePendingOrders(symbol);
                  CountOpenTrades(symbol);         
               }//if (signal != SHORT)
               
         }//if (PendingTradesTotal > 0)
:xm: :rocket:
Author:  SteveHopwood [ Sat Feb 16, 2019 4:08 pm ]
Post subject:  Desky. TDesk's trading drone.

V 2u is in post 1. A number of bloops emerged last week so I have been gradually fixing them. The pending order removal thingy should be resolved now.

I have added a new feature to grid trading. This is the option to use the order open price of the next trade in the grid as the take profit of the one being sent to the server. The input is UseNextLevelForTP. I have added this to SPB Latest as well.

I am posting this today for the DIYers. Code phobics might want to wait until a bit later tomorrow, just in case I think of something else.

DIYers, this will not be so simple this time. Probably the only way you can find the changes is by going to a site such as https://www.diffchecker.com/ and comparing the new file with the old. This could be a time to spare yourself some effort and just download 2u.

:xm: :rocket:
Author:  SteveHopwood [ Sun Feb 17, 2019 5:29 pm ]
Post subject:  Desky. TDesk's trading drone.

I have a present for Gertje. I have extended Peaky so that users can 'flip' the signal generated by the peak hilo. From the updated Peaky user guide:
  • There will be users who will want to trade long from the lower part of the chart even though the short cycle has not completed yet and there is no new peal low. They will also want to trade short from the top of the chart even though there is no new peak high. These two inputs allow this:
    • AllowSignalFlip: this causes Peaky to 'flip' the signal it displays and sends to TDesk:
      • short signal from the top two sixths of the chart even though there is no new peak high. Peaky will be displaying a long signal without the flip.
      • long signal from the bottom two sixths of the chart even though there is no new peak low. Peaky will be displaying a short signal without the flip.
    • NoSignalInMiddleOfChart: this tells Peaky to send TDesk a flat signal if the market is in the middle two sixths of the chart.
Download the latest from either the SPB thread or from Peaky's first home at http://www.stevehopwoodforex.com/phpBB3 ... 46#p161246

:xm: :rocket:
Author:  ppaulius1 [ Mon Feb 18, 2019 6:23 pm ]
Post subject:  Desky. TDesk's trading drone.

SteveHopwood wrote:V 2u is in post 1. A number of bloops emerged last week so I have been gradually fixing them. The pending order removal thingy should be resolved now.

I have added a new feature to grid trading. This is the option to use the order open price of the next trade in the grid as the take profit of the one being sent to the server. The input is UseNextLevelForTP. I have added this to SPB Latest as well.

I am posting this today for the DIYers. Code phobics might want to wait until a bit later tomorrow, just in case I think of something else.

DIYers, this will not be so simple this time. Probably the only way you can find the changes is by going to a site such as https://www.diffchecker.com/ and comparing the new file with the old. This could be a time to spare yourself some effort and just download 2u.

:xm: :rocket:
Thank you very much for a new version, Steve. I tested it and seems mentioned bug has been solved.

Cheers,
Paulius
Author:  SteveHopwood [ Mon Feb 18, 2019 9:14 pm ]
Post subject:  Desky. TDesk's trading drone.

ppaulius1 » Mon Feb 18, 2019 6:23 pm wrote:
Thank you very much for a new version, Steve. I tested it and seems mentioned bug has been solved.

Cheers,
Paulius
Fabulous. Thanks for confirming this.

:xm: :rocket:
Author:  SteveHopwood [ Tue Feb 19, 2019 3:12 pm ]
Post subject:  Desky. TDesk's trading drone.

V 2v is in post 1.

This one is for those of you hedging at > 100% and looking for a breakeven. From the updated UG:
  • Closing all of a pair's trades when a hedged position reaches breakeven: this is for those of you using a > 100% PercentageToHedge input:
    • CloseAllAtBreakeven: turns this feature on/off.
    • HedgeProfitTargetCash: close the position when the cash UPL reaches this target. The default of 0 means close the instant the cash UPL reaches break even.
    • HedgeProfitTargetPips: close the position when the pips UPL reaches this target. The default of 0 means close the instant the cash UPL reaches break even. Here are a couple of points to bear in mind. There are circumstances when:
      • The position can be pips positive but cash negative.
      • The position can be cash positive but pips negative. This happens frequently when basket trading, and it is the cash we are making that counts, not the pips.
If you want to check my code, or DIY:
Search for, "extern double PercentageToHedge" and add the inputs:

Code: Select all

//Some breakeven closure options for those hedging at > 100%
extern bool    CloseAllAtBreakeven=false;
extern int     HedgeProfitTargetCash=0;
extern int     HedgeProfitTargetPips=0;
I noticed something I missed from the void CanWeRemoveTheHedge(string symbol, int pairIndex) function. Desky needs to know what trade type failed when closing an individual hedge trade. Scroll down to the if (result) code block and add this underneath that block:

Code: Select all

      //Tell Desky which trade to close on a retry
      if (!result)
      {
         if (hedgeIsBuy)
            BuyClosureFailure = true;
         else
            SellClosureFailure = true;
      }//if (!result)

Go to void DoHedging(string symbol, int pairIndex) and scroll down a few lines to, "CanWeRemoveTheHedge(symbol, pairIndex);". Insert this directly underneath:

Code: Select all

         if (CloseAllAtBreakeven)
         {
            IsHedgedPositionAtBreakeven(symbol);
         }//if (CloseAllAtBreakeven)
Add this function somewhere convenient:

Code: Select all

void IsHedgedPositionAtBreakeven(string symbol)
{

   bool TradesCanClose = false;
   
   //Test for cash BE
   if (CashUpl >= HedgeProfitTargetCash)
      TradesCanClose = true;
      
   //Test for pips BE
   if (!TradesCanClose)
      if (PipsUpl >= HedgeProfitTargetPips)
         TradesCanClose = true;
   
   
   if (TradesCanClose)
   {
      CloseAllTrades(symbol, AllTrades);
      if (ForceTradeClosure)//An order closure failed, so force a retry at the next timer event
      {
         //Set both closure flags
         BuyClosureFailure = true;
         SellClosureFailure = true;
      }//if (ForceTradeClosure)
      
   
   }//if (TradesCanClose)
   
   

}//void IsHedgedPositionAtBreakeven(string symbol)
Go to void OnTimer() and search for, "//Deal with a closure failure". Copy this over the top of the existing block:

Code: Select all

      //Deal with a closure failure
      if (ForceTradeClosure)
      {
         //Rebuild a picture of the position
         CountOpenTrades(symbol);
         
         //A failed hedge breakeven failure
         if(BuyClosureFailure && SellClosureFailure)
         {
            CloseAllTrades(symbol, AllTrades);
         }//if(BuyClosureFailure && SellClosureFailure)
         else
         {
         
            if (BuyClosureFailure)
               CloseAllTrades(symbol, OP_BUY);
            
            if (SellClosureFailure)
               CloseAllTrades(symbol, OP_SELL);
         
         }//else
            
         if (ForceTradeClosure)
         {
            pairIndex--;
            continue;
         }//if (ForceTradeClosure)
         
         //Got here, so all closures succeeded
         BuyClosureFailure = false;
         SellClosureFailure = false;
         
      }//if (ForceTradeClosure)

:xm: :rocket:
Author:  Gertje [ Tue Feb 19, 2019 3:20 pm ]
Post subject:  Desky. TDesk's trading drone.

SteveHopwood » Sun Feb 17, 2019 5:29 pm wrote:I have a present for Gertje. I have extended Peaky so that users can 'flip' the signal generated by the peak hilo. From the updated Peaky user guide:
  • There will be users who will want to trade long from the lower part of the chart even though the short cycle has not completed yet and there is no new peal low. They will also want to trade short from the top of the chart even though there is no new peak high. These two inputs allow this:
    • AllowSignalFlip: this causes Peaky to 'flip' the signal it displays and sends to TDesk:
      • short signal from the top two sixths of the chart even though there is no new peak high. Peaky will be displaying a long signal without the flip.
      • long signal from the bottom two sixths of the chart even though there is no new peak low. Peaky will be displaying a short signal without the flip.
    • NoSignalInMiddleOfChart: this tells Peaky to send TDesk a flat signal if the market is in the middle two sixths of the chart.
Download the latest from either the SPB thread or from Peaky's first home at http://www.stevehopwoodforex.com/phpBB3 ... 46#p161246

:xm: :rocket:
Thanks Steve,

Now it is up to me to get it to work..... :smile:
Author:  SteveHopwood [ Tue Feb 19, 2019 8:22 pm ]
Post subject:  Bloop alert

tutank just sent me another of my copy/paste/forgot-to-edit bloops. Fixed in post 1. Thanks tutank. :clap: :clap: :clap: :clap: :clap:

Easy DIY. Do a search for, "targetNoOfPendingTrades = GridSize - MarketBuysCount;//Not sure if this will give the correct figure." This will take you straight to the line of code that needs editing:
targetNoOfPendingTrades = GridSize - MarketBuysCount;

should be:
targetNoOfPendingTrades = GridSize - MarketSellsCount;

:xm: :rocket:
Author:  SteveHopwood [ Thu Feb 21, 2019 5:27 pm ]
Post subject:  Desky. TDesk's trading drone.

I have written a do it yourself for beginners guide. http://www.stevehopwoodforex.com/phpBB3 ... 92#p166292

:xm: :rocket:
Author:  SteveHopwood [ Fri Feb 22, 2019 11:03 am ]
Post subject:  Desky. TDesk's trading drone.

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.

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