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

Desky. TDesk's trading drone.
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5545
Page 9 of 50
Author:  SteveHopwood [ Tue Nov 06, 2018 11:56 am ]
Post subject:  Desky. TDesk's trading drone.

V 1w is in post 1.

I found Desky frozen this morning and found an Array out of range error at line 4400 - no idea why this should have happened.

Do a search for "ArrayResize(TimeToStartTrading, ArraySize(TDeskSymbols));"

Alter it slightly so that it is:
ArrayResize(TimeToStartTrading, ArraySize(TDeskSymbols) + 1);

I do not know if this will help.

Re the rapid opening/closing of trades thingy reported in the Confused thread, I have absolutely no idea what is causing this.

:xm: :rocket:
Author:  SteveHopwood [ Wed Nov 07, 2018 11:14 am ]
Post subject:  Desky. TDesk's trading drone.

V 1x is in post 1.

Twice Desky showed the, "Your global cash TP has been hit. All your trades should have closed." message but little had happened. This is fixed in 1x. You do not need the update if you are not trading the entire position as a basket.

DIYers, the mistakes I made in the code were ridiculous, but easy to fix.

I had not actually populated the array that holds every ticket number in the global basket. Go to void CountTradesForGlobalBasket(), scroll down to just underneath, "if (OrderCloseTime() > 0) continue;" and insert the code that builds the array:

Code: Select all

      ArrayResize(GlobalTickets, GlobalTradesTotal + 1);
      GlobalTickets[GlobalTradesTotal] = OrderTicket();
      GlobalTradesTotal++;
Then replace the existing void GlobalBasketClosure() function with this:

Code: Select all

void GlobalBasketClosure()
{

      
   ForceWholePositionClosure = false;
  
   
   //Just in case
   if (OrdersTotal() == 0) return;
   if (GlobalTradesTotal == 0) return;
   
   bool result = false;
   for (int pass = 0; pass <= 1; pass++)
   {
      
      for (int cc = ArraySize(GlobalTickets) - 1; cc >= 0; cc--)
      {
         if (!BetterOrderSelect(GlobalTickets[cc], SELECT_BY_TICKET, MODE_TRADES) ) continue;
         if (OrderMagicNumber() != MagicNumber) continue;
         
         while(IsTradeContextBusy()) Sleep(100);
         
         //Close market orders first
         if (OrderType() < 2)
         {
            result = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, CLR_NONE);
            if (result) 
            {
               cc++;
            }//(result) 
            
            if (!result)
            {
               ReportError(" CloseOrder()", ocm);
               ForceWholePositionClosure= true;
            }//if (!result)
   
            
         }//if (OrderType() < 2)
         
         //Delete pending orders
         if (pass == 1)
         {   
            if (OrderType() > 1) 
            {
               result = OrderDelete(OrderTicket(), clrNONE);
               if (result) 
               {
                  cc++;
               }//(result) 
      
               if (!result)
               {
                  ReportError(" Delet Order()", odm);
                  ForceWholePositionClosure = true;
               }//if (!result)
            }//if (OrderType() > 1) 
         }//if (pass == 1)
              
      }//for (int cc = ArraySize(GlobalTickets) - 1; cc >= 0; cc--)
      
      //Recount the position now the market trades have been closed
      if (pass == 0)
         CountTradesForGlobalBasket();
      
   }//for (int pass = 0; pass <= 1; pass++)
         

}//End void GlobalBasketClosure()
:xm: :rocket:
Author:  SteveHopwood [ Wed Nov 07, 2018 2:53 pm ]
Post subject:  Desky. TDesk's trading drone.

Mauro emailed today to remind me that Recovery is not quite working properly - I had forgotten.

This should be fixed in 1x because I saw the problem within seconds of glaring at the code. I have not updated any version numbers because I have applied this fix to uploads of:
  • Desky.
  • Peaky on Steroids.
  • Peaky on Steroids TD.
  • Slopey Peaky Bob Experimental.

The fix is simple and you coders will see where I went wrong instantly:
  • Do a search for, "RecoveryTargetPrice/= ArraySize(BuyTickets);" and replace it with, "RecoveryTargetPrice/= (ArraySize(BuyTickets) - 1);"
  • Do a search for, "RecoveryTargetPrice/= ArraySize(SellTickets);" and replace it with, "RecoveryTargetPrice/= (ArraySize(SellTickets) - 1);"
Explanation for fledgling coders:
BuyTickets[] is an array that can hold any number of elements - you can think of these as boxes and I will call them that from here on. The "[]" after the variable name tells the compiler that it is dealing with an array. The number of boxes goes inside the [] so that BuyTickets[4] is an array with 4 boxes.

CrapQl4 indexes arrays starting from 0. Imagine there are three buy trades open with these ticket numbers: 123, 578; 692 and they are stored in the BuyTickes[3] array:
  • BuyTicket[0] = 123.
  • BuyTicket[1] = 578.
  • BuyTicket[2] = 692.
For reasons known only to the lunatics that wrote CrapQl4, an array has to have one more box than is going to be used, so BuyTickets[3] will be empty and unused.

This is why "RecoveryTargetPrice/= ArraySize(BuyTickets);" failed. It was dividing the recovery target price by one more than it should have been.

Yep. Bonkers. As I have often remarked in the past, welcome to my world. :arrrg:

:xm: :rocket:
Author:  c1borg [ Wed Nov 07, 2018 4:44 pm ]
Post subject:  Desky. TDesk's trading drone.

If you have time (might just be me) when shirt protection is selected the EA will not load. No rush as im not using it at the moment. Great work :hi:
Author:  SteveHopwood [ Wed Nov 07, 2018 5:08 pm ]
Post subject:  Desky. TDesk's trading drone.

c1borg » Wed Nov 07, 2018 4:44 pm wrote:If you have time (might just be me) when shirt protection is selected the EA will not load. No rush as im not using it at the moment. Great work :hi:
Fixed in post 1.

DIYers, go to the end of the file and scroll upwards for, "}//if (UseShirtProtection)". A few lines above that you you will see this code snippet:

Code: Select all

         if (GlobalVariableCheck(BTSTrailingStopPipsGV))
            GlobalVariableDel(BTSTrailingStopPipsGV);
         return;
Delete the, "return;" command.

:xm: :rocket:
Author:  billv [ Wed Nov 07, 2018 8:00 pm ]
Post subject:  Desky. TDesk's trading drone.

Thanks Steve :hi:
Author:  Bruster400 [ Thu Nov 08, 2018 9:27 am ]
Post subject:  Desky. TDesk's trading drone.

SteveHopwood » Wed Oct 31, 2018 3:42 pm wrote: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:
Thanks Steve, that helps me understand it........ even if I don't agree with it.... I don't want to offend anyone here so please all take this post as just my opinion and not a comment on anyone else's.

I just wanted to add my view of how to automate SL and TP calculations and explain why I feel that price fractions isn't for me. When trading stocks, people tend to invest a lump of cash and then measure the performance based on the % change in the value of that cash. They don't care if they have to buy 10 shares with their lump or 1000 shares, it's all the same - it's just a lump sum invested. If price moves up, say 10%, then they might sell or add more. They are focussed on % price moves because that's the way it works.

On forex, the banks work in much the same way. They will invest a % of their cash holding in a particular currency in the hope that it will deliver a % return. They are not bothered about pips but rather the current value of their lump sum invested. However, for the short term trader using leverage, things are very different.

Short term trading is all about probability. We are looking for what is "most likely" to happen in terms of price movement. Our entries and money management are designed to be aligned to what is most "likely" to happen to price. An "edge" is simply a term used to describe the amount your strategy beats the average or random outcome. So when looking for SL's and TP's we should be looking for measures with similar probability of happening. Price moves don't always give us this. (and pip moves definitely don't!)

Take USDCAD and NZDUSD as an example. Their current prices at this time are 1.31017 and 0.67918 resp. A 0.5% move in each would be a price move of 0.006551(USDCAD) and 0.003396(NZDUSD) resp. So this could be used as a TP or SL perhaps? Well, let's look at how "likely" those moves are. Based on a 14 day ATR, these moves would be 95% (USDCAD) and 261%(NZDUSD) of ATR. So for USDCAD to reach its 0.5% price move it would have to move less than it's done on average each day for the last 14 days - so that's quite likely. However, NZDUSD would have to move 2.61 times its average daily price move which is much less likely. So a 0.5% move in price is much more "likely" to happen on USDCAD than NZDUSD and that changes everything when you're betting on probabilities.

If you're trading multiple currencies and you want to take the same "risk" on each, my belief is that you need to risk the same amount of cash on each "event" (SL or TP) that has the same probability of happening. I feel that sized positions and ATR based SL's and TP's are the only way to do this.

Just my opinion....

Bruster
Author:  SteveHopwood [ Thu Nov 08, 2018 9:34 am ]
Post subject:  Desky. TDesk's trading drone.

Bruster400 » Thu Nov 08, 2018 9:27 am wrote: I feel that sized positions and ATR based SL's and TP's are the only way to do this.
I will add this feature soon.

:xm: :rocket:
Author:  SteveHopwood [ Thu Nov 08, 2018 9:48 am ]
Post subject:  Desky. TDesk's trading drone.

V 1y is in post 1.

This update is only of interest to those of you with UseTradingDoneForTheWeek enabled, your target is hit and then you change your mind and decide to carry on trading. Pre-1y, this was impossible. Wait until the weekend if this is not an issue for you, as I will add ATR-based SL andTP.

DIYers, do a search for, "//This allows DoneForTheWeek to reset to 'true' following a restart." and insert this just above:

Code: Select all

   //Delete the global variable if the user has a change of mind and decides to carry on trading
   if (!DoneForTheWeek)
      if (GlobalVariableCheck(DoneForTheWeekGV))
         GlobalVariableDel(DoneForTheWeekGV);
      
:xm: :rocket:
Author:  tomele [ Thu Nov 08, 2018 11:08 am ]
Post subject:  Desky. TDesk's trading drone.

Hi Bruster.
Bruster400 » 08 Nov 2018, 10:27 wrote:So when looking for SL's and TP's we should be looking for measures with similar probability of happening. Price moves don't always give us this. (and pip moves definitely don't!)

...

If you're trading multiple currencies and you want to take the same "risk" on each, my belief is that you need to risk the same amount of cash on each "event" (SL or TP) that has the same probability of happening. I feel that sized positions and ATR based SL's and TP's are the only way to do this.
We already have this possibility in Desky as well as in TDesk's simulation module. We have fixed pips, price fractions and atr percent as alternative SL/TP calculation methods. We obviously agree that fixed pips is the weakest method.

I totally agree to what you write. Nevertheless, after 3 weeks of daily simulations on my side, price fractions have performed slightly better than atr percent in my scenario. The position sizing aspect might be the missing part that would change everything.

Thanks for being the first one giving feedback. :clap:

Cheers
Thomas
All times are UTC Page 9 of 50