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

Desky. TDesk's trading drone.
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5545
Page 8 of 50
Author:  Barcode [ Tue Oct 30, 2018 10:48 pm ]
Post subject:  Desky. TDesk's trading drone.

Steve,

My account is in Aussie dollars but messages are showing it in pounds.

It would be nice if it was true as it would be a nice increase :clap: :clap:
Author:  SteveHopwood [ Tue Oct 30, 2018 10:54 pm ]
Post subject:  Desky. TDesk's trading drone.

V 1t is in post one in response to this utterly brilliant pm from David (davista).
davista wrote:Hi Steve

I've noticed a couple of possible minor bloops in Desky v1r which, although I doubt have anything whatsoever to do with the problem with individual basket trading errant open/closing, I thought I'd flag 'em anyway.

On Oct 20th you posted a fix in //Hedging:
Subject: Desky. TDesk's trading drone.
Looking at the code and nothing to do with what we are discussing here, highlights a bloop. Line 3830 in V 1k is this: pairIndex++;
This should clearly be:
pairIndex--;
However in line 4170 of version 1r I notice it's still pairIndex++

Code: Select all

         if (hedged)
         {
            CanWeRemoveTheHedge(symbol, pairIndex);
            if (ForceTradeClosure)
            {
               pairIndex++;
               continue;
            }//if (ForceTradeClosure)
Is this correct or should it be pairIndex--?


Also, in void CanPendingsBeDeleted(string symbol)

Line 2576 of version 1r is:

Code: Select all

   for (int PairIndex = 0; PairIndex < ArraySize(TDeskSignals); PairIndex++)
Should this be ArraySize(TDeskSymbols); ?

Cheers, David
All of David's suggestions are clearly correct so I adopted them without hesitation.

Still not sure that anything posted here deals with the opening-closing trades thingy. Never mind. At least some of the body of the code has been corrected today.

Thanks David. We all owe you. :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap: :clap:

:xm: :rocket:
Author:  SteveHopwood [ Tue Oct 30, 2018 11:05 pm ]
Post subject:  Desky. TDesk's trading drone.

Barcode » Tue Oct 30, 2018 10:48 pm wrote:Steve,

My account is in Aussie dollars but messages are showing it in pounds.
Here we are developing the most sophisticated trading software in the entire history of Forex trading software, and you I think about this?

Wouldn't care to reevaluate your priorities would you fella? Or maybe you want me te reevaluate them for you?

I remind you that cretins are not welcome at SHF. Ask yourself this: do you really want me to consider you to be a cretin?

Note the lack of my usual sign-off, dimwit.
Author:  SteveHopwood [ Wed Oct 31, 2018 1:08 pm ]
Post subject:  Desky. TDesk's trading drone.

I have located the source of those rapidly opening and closing trades. It is the hedging code and nothing to do with the individual pair basket trading.

For reasons that I cannot yet find, Desky is hedging an individual open trade even though it is in the direction of TDesk's signal. Then it is finding the hedge and closing it because it in the opposite direction to the hedge.

:arrrg: :arrrg: :arrrg: :arrrg: :arrrg:
Author:  Bruster400 [ Wed Oct 31, 2018 1:48 pm ]
Post subject:  Desky. TDesk's trading drone.

Having great fun testing out different strategies with this EA. :yahoo: No big deal, one for a future updates maybe.... I've just tried switching "StopTrading" to "true" and it didn't do anything. I've looked and the bool isn't checked in the code anywhere - I might be out of date(version 1p), so if this is already fixed then delete this.
Author:  SteveHopwood [ Wed Oct 31, 2018 2:18 pm ]
Post subject:  Desky. TDesk's trading drone.

Bruster400 » Wed Oct 31, 2018 1:48 pm wrote:Having great fun testing out different strategies with this EA. :yahoo: No big deal, one for a future updates maybe.... I've just tried switching "StopTrading" to "true" and it didn't do anything. I've looked and the bool isn't checked in the code anywhere - I might be out of date(version 1p), so if this is already fixed then delete this.
Nice spot. Thanks. :clap: :clap: :clap:

I will add the code to the update coming this afternoon.

I found the cause of the trade open/close thingy, and it really should have been blindingly obvious, even to me.

The culprit is HedgeOnFlatSignal and its partner CloseHedgeOnFlatSignal. Here is what was happening with these two inputs enabled:
  • TDesk generated a FLAT signal and so cheerfully sent a hedge trade in the opposite direction.
  • Next time around, Desky discovered the FLAT signal again and gleefully closed the hedge trade.
I should have thought of that. :arrrg:

Hey ho.

:xm: :rocket:
Author:  SteveHopwood [ Wed Oct 31, 2018 2:42 pm ]
Post subject:  Desky. TDesk's trading drone.

V 1u is in post 1, with the hedging thingy fixed and FLAT signal hedging removed.

Thomas sent me this explanation of the PriceFractions TP and SL option. I have added it to the user guide:

I am used from stocks and options trading to set TPs and SLs in percent of price. For example a TP of 10% means a $20 stock has to move $2, while a $200 stock has to move $20.

This problem is to a smaller degree also existent in Forex. Lets take USDCAD with a price around 1.30 and NZDUSD with a price around 0.65. To achieve a 100 pips TP, NZDUSD would have to move twice as much than USDCAD in relation to the price.

A pip is defined as a change of ±1 at the 5th digit of price. Hence the 10000th (0.0001) fractions. 100 of these fractions equal 100 pips if the price is exactly 1.0.

For USDCAD (@1.30) 100 of these fractions equal 130 pips while for NZDUSD (@0.65) 100 of these fractions equal 65 pips. If we calculate SLs and TPs this way, each pair now has to move the same distance relative to its price.
Thanks for that Thomas - most helpful. :clap: :clap: :clap:

:xm: :rocket:
Author:  SteveHopwood [ Thu Nov 01, 2018 5:35 pm ]
Post subject:  Desky. TDesk's trading drone.

I did a bit of code rearranging in 1u that stopped Desky trading altogether.

Fixed in 1v in post 1.

1u DIYers, do a search for, "//Deal with pending orders when the margin level drops below our minimum." Insert this just above the subsequent code block:

Code: Select all

      //Is there a trading signal?
      if (OpenTrades == 0)
      {
         BuySignal = false;
         SellSignal = false;
         if ((TimeLocal() - TDeskTimes[pairIndex]) / 60 <= MaxSignalAgeMinutes)
         {
            if (signal == LONG)
               BuySignal = true;
            
            if (signal == SHORT)
               SellSignal = true;
               
         
         }//if (if ((TimeLocal() - TDeskTimes[pairIndex]) / 60 <= MaxSignalAgeMinutes))
         
      }//if (OpenTrades == 0)
:xm: :rocket:
Author:  SteveHopwood [ Thu Nov 01, 2018 5:51 pm ]
Post subject:  Desky. TDesk's trading drone.

I just made a teensy addition to 1v after I noticed it was not showing that I had grid trading enabled.

Easy DIY. Do a search for, "SM("Recovery is enabled" + NL);" and insert this somewhere convenient:

Code: Select all

   if (UseGridTrading)
      SM("Grid trading is enabled" + NL);
:xm: :rocket:
Author:  SteveHopwood [ Thu Nov 01, 2018 6:06 pm ]
Post subject:  Desky. TDesk's trading drone.

Another teensy change to 1v to make him display the correct number of market trades in the global basket bit of the chart display.

DIY: do a search for, "//We are only concerned with market trades here". Look a few lines down and you will see this:
GlobalTradesTotal+= 1;

This needs moving inside the code block you just searched for, so the whole function looks like this:

Code: Select all

void CountTradesForGlobalBasket()
{

   //Counts all open trades when the user is trading an all-position basket
   
   TotalPipsUpl = 0;//Global pips total
   TotalCashUpl = 0;//Global cash total
   ArrayFree(GlobalTickets);
   ArrayResize(GlobalTickets, 0);
   GlobalTradesTotal = 0;
   int pips = 0;
   int cc = 0;
      
   if (OrdersTotal() == 0)
      return;
      
   for (cc = OrdersTotal() - 1; cc >= 0; cc--)
   {
      //bool TradeWasClosed = false;//See 'check for possible trade closure'

      //Ensure the trade is still open
      if (!BetterOrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;

      
      //Ensure the EA 'owns' this trade
      if (OrderMagicNumber() != MagicNumber) continue;
      if (OrderCloseTime() > 0) continue; 

      //We are only concerned with market trades here
      if (OrderType() < 2)
      {
         TotalCashUpl+= OrderProfit() + OrderSwap() + OrderCommission();
         pips = (int) CalculateTradeProfitInPips(OrderType());
         TotalPipsUpl+= pips;
         GlobalTradesTotal+= 1;
      }//if (OrderType() < 2)
   
      //Store the ticket numbers of all order types for closure/deletion
      ArrayResize(GlobalTickets, GlobalTradesTotal + 1);
      GlobalTickets[GlobalTradesTotal] = OrderTicket();
      

   }//for (cc = OrdersTotal() - 1; cc >= 0; cc--)
   

   //Sort ticket numbers for FIFO
   if (ArraySize(GlobalTickets) > 0)
      ArraySort(GlobalTickets, WHOLE_ARRAY, 0, MODE_DESCEND);
    

}//End void CountTradesForGlobalBasket()
The do a search for, "//This came from DigitalCrypto. Thanks David." and copy this over the top of the existing block:

Code: Select all

   //This came from DigitalCrypto. Thanks David.
   if (TreatAllPairsAsBasket)
   {
      sizingInfo = "Global basket take profit is active. Market trades count = " + IntegerToString(GlobalTradesTotal);
      if (BasketTargetCash > 0)
         sizingInfo +=  ": All pair basket cash take profit = " + AccountCurrency() + " " + DoubleToStr(BasketTargetCash, 2) 
         + ": Current = " + DoubleToStr(TotalCashUpl, 2) + ": Highest = " + DoubleToStr(HighestCashUpl, 2);
   
      if (BasketTargetPips > 0)
         sizingInfo +=  ": All pair basket take profit pips = " + IntegerToString(BasketTargetPips)
          + ": Highest = " + IntegerToString(HighestPipsUpl);
     
   }
   SM(sizingInfo + NL);
By the bye for you fledgling coders: GlobalTradesTotal+= 1; and GlobalTradesTotal++; mean the same thing. No idea why I chose the former here as it is two more keystrokes.

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