Desky. TDesk's trading drone.

Post Reply
User avatar
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.

Post by SteveHopwood »

Found the trade management thingy.

I had changed the variable names in line with my usual coding practice and forgot to initialise them. DIYers, put this at the top of OnInit():

Code: Select all

   BreakEvenPips = BreakEvenTargetPips;
   BreakEvenProfit = BreakEvenTargetProfit;
   JumpingStopPips = JumpingStopTargetPips;
   TrailingStopPips = JumpingStopTargetPips;
The functions should run properly now.

Thanks Vince. You were really helpful. :clap: :clap: :clap: :clap: :clap:

:xm: :rocket:
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.
User avatar
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.

Post by SteveHopwood »

V2 is in post 1, with all the latest fixes.

I tracked down the cause of the basket pips thingy not working. It took me over two hours, because I am an idiot. With the markets closed, I was able to load up Desky and see him immediately try to close my trades with BasketTargetPips = 500 - despite the position being about -900.

I sifted through every block of code in OnInit() first, then OnTimer(), inserting an Alert and return after each block.

This eventually took me to this line of code:
pips = (int) CalculateTradeProfitInPips(OrderType()); - do a search for it as there is only the one instance.

This was returning ridiculous results, so I looked at double CalculateTradeProfitInPips(int type). Do the same and you will see the dummy mistake immediately e.g.
profit = bid - OrderOpenPrice();

The 'bid' variable was set to whatever it was after its last iteration through the loop in OnTimer().

The solution is to go back to void CountTradesForGlobalBasket(), scroll down to:
if (!BetterOrderSelect(cc, SELECT_BY_POS, MODE_TRADES) ) continue;

and add this immediately underneath:
GetBasics(OrderSymbol());

This populates the add, bid etc variables with the correct price.

And that took me more than two sodding hours.
:arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg:

Hey ho.

:xm: :rocket:
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.
trader689
Trader
Posts: 674
Joined: Thu Nov 17, 2011 12:53 am

Desky. TDesk's trading drone.

Post by trader689 »

Great thanks Steve! All set for the new week with a fixed Desky - woot :cheer: :party:
User avatar
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.

Post by SteveHopwood »

:arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg:

The fucking Recovery function still does not work properly. Turn it off, dammit.

:arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg:

I had changed some of the variables to global ones i.e. BuyTickets to GlobalBuyTickets. What was I on when I did this?

In the fupdated unction I now have on my demo account, the functions is:

Code: Select all

bool HaveWeHitRecoveryTarget(string symbol, int type)
{
   //Calculate the Recovery target and close the trades if the target price is reached.
   
   GetBasics(symbol);//Probably not needed, but no harm to check.
   
   int cc = 0;
   RecoveryTargetPrice = 0;
   
   if (type == OP_BUY)
   {
      //Add together the price of all the market trades
      for (cc = 0; cc < ArraySize(BuyTickets); cc++)
      {
         if (!BetterOrderSelect(BuyTickets[cc], SELECT_BY_TICKET, MODE_TRADES) )
            continue;//Just in case
         
         RecoveryTargetPrice+= OrderOpenPrice();
      }//for (cc = 0; cc < ArraySize(GlobalBuyTickets); cc++)
      
      //Divide this figure by the ticket array size to arrivc at the breakeven price
      RecoveryTargetPrice/= ArraySize(BuyTickets);
      RecoveryTargetPrice+= (RecoveryProfitP / factor);//Add the lock-in profit pips
      
      //Has the market reached this target? Using bid because buys close at the Bid
      if (bid >= RecoveryTargetPrice)
         return(true);
   
   }//if (type == OP_BUY)

   if (type == OP_SELL)
   {
      //Add together the price of all the market trades
      for (cc = 0; cc < ArraySize(SellTickets); cc++)
      {
         if (!BetterOrderSelect(SellTickets[cc], SELECT_BY_TICKET, MODE_TRADES) )
            continue;//Just in case
         
         RecoveryTargetPrice+= OrderOpenPrice();
      }//for (cc = 0; cc < ArraySize(GlobalSellTickets); cc++)
      
      //Divide this figure by the ticket array size to arrivc at the breakeven price
      RecoveryTargetPrice/= ArraySize(SellTickets);
      RecoveryTargetPrice-= (RecoveryProfitP / factor);//Add the lock-in profit pips
      
      //Has the market reached this target? Using ask because sells close at the Ask
      if (ask <= RecoveryTargetPrice)
         return(true);
   
   }//if (type == OP_SELL)
   

   //Got this far, so no closure
   return(false);

}//End bool HaveWeHitRecoveryTarget(string symbol, int type)
Anybody here with a firing synapse see a fault here before I release it?

I am starting to lose the will to live here.

:arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg: :arrrg:
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.
User avatar
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.

Post by SteveHopwood »

Recovery still is not working folks. Turn it off for now.

:xm: :rocket:
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.
User avatar
Gertje
Trader
Posts: 1936
Joined: Mon Dec 12, 2011 1:17 pm
Location: Middle of the Netherlands

Desky. TDesk's trading drone.

Post by Gertje »

Here is the code from an EA where the recovery works like a charm.
No idea if the code is compatible, I'm no code-slinger by far.

Code: Select all

bool HaveWeHitRecoveryTarget(string symbol, int type, int index)
{
   //Calculate the Recovery target and close the trades if the target price is reached.
   
   int cc = 0;
   RecoveryTargetPrice = 0;
   
   if (type == OP_BUY)
   {
      //Add together the price of all the market trades
      for (cc = 0; cc < ArraySize(BuyTickets); cc++)
      {
         if (!BetterOrderSelect(BuyTickets[cc], SELECT_BY_TICKET, MODE_TRADES) )
            continue;//Just in case
         
         RecoveryTargetPrice+= OrderOpenPrice();
      }//for (cc = 0; cc < ArraySize(BuyTickets); cc++)
      
      //Divide this figure by the ticket array size to arrivc at the breakeven price
      RecoveryTargetPrice/= ArraySize(BuyTickets);
      RecoveryTargetPrice+= (RecoveryProfitPips[index] / factor);
      
      //Has the market reached this target?
      if (bid >= RecoveryTargetPrice)
         return(true);
   
   }//if (type == OP_BUY)

   if (type == OP_SELL)
   {
      //Add together the price of all the market trades
      for (cc = 0; cc < ArraySize(SellTickets); cc++)
      {
         if (!BetterOrderSelect(SellTickets[cc], SELECT_BY_TICKET, MODE_TRADES) )
            continue;//Just in case
         
         RecoveryTargetPrice+= OrderOpenPrice();
      }//for (cc = 0; cc < ArraySize(BuyTickets); cc++)
      
      //Divide this figure by the ticket array size to arrivc at the breakeven price
      RecoveryTargetPrice/= ArraySize(SellTickets);
      RecoveryTargetPrice-= (RecoveryProfitPips[index] / factor);
      
      //Has the market reached this target?
      if (bid <= RecoveryTargetPrice)//Should ths be ask instead of bid?
         return(true);
   
   }//if (type == OP_SELL)
   

   //Got this far, so no closure
   return(false);

}//bool HaveWeHitRecoveryTarget(string symbol, int type)
User avatar
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.

Post by SteveHopwood »

I think Recovery is working now - V 2a in post 1.

I commented out the line of code that closed trades when the Recovery price is reached and so was able to add some Alerts to show what was happening. It turns out that we do need the -1 in the overall divide code.

Here is the function, so you can see where I put the alerts:

Code: Select all

bool HaveWeHitRecoveryTarget(string symbol, int type)
{
   //Calculate the Recovery target and close the trades if the target price is reached.
   
   GetBasics(symbol);//Probably not needed, but no harm to check.
//if (symbol == "AUDJPY") Alert("");   
   int cc = 0;
   RecoveryTargetPrice = 0;
   
   if (type == OP_BUY)
   {
      //Add together the price of all the market trades
      for (cc = 0; cc < ArraySize(BuyTickets); cc++)
      {
         if (!BetterOrderSelect(BuyTickets[cc], SELECT_BY_TICKET, MODE_TRADES) )
            continue;//Just in case
         
         RecoveryTargetPrice+= OrderOpenPrice();
      }//for (cc = 0; cc < ArraySize(GlobalBuyTickets); cc++)
      
//if (symbol == "AUDJPY") Alert(cc, "  ", RecoveryTargetPrice);
      //Divide this figure by the ticket array size to arrivc at the breakeven price
      RecoveryTargetPrice/= (ArraySize(BuyTickets) - 1);
      RecoveryTargetPrice+= (RecoveryProfitP / factor);//Add the lock-in profit pips
//if (symbol == "AUDJPY") Alert(RecoveryTargetPrice);
      
      //Has the market reached this target? Using bid because buys close at the Bid
      if (bid >= RecoveryTargetPrice)
         return(true);
   
   }//if (type == OP_BUY)

   if (type == OP_SELL)
   {
      //Add together the price of all the market trades
      for (cc = 0; cc < ArraySize(SellTickets); cc++)
      {
         if (!BetterOrderSelect(SellTickets[cc], SELECT_BY_TICKET, MODE_TRADES) )
            continue;//Just in case
         
         RecoveryTargetPrice+= OrderOpenPrice();
      }//for (cc = 0; cc < ArraySize(GlobalSellTickets); cc++)
      
      //Divide this figure by the ticket array size to arrivc at the breakeven price
      RecoveryTargetPrice/= (ArraySize(SellTickets) - 1);
      RecoveryTargetPrice-= (RecoveryProfitP / factor);//Add the lock-in profit pips
      
      //Has the market reached this target? Using ask because sells close at the Ask
      if (ask <= RecoveryTargetPrice)
         return(true);
   
   }//if (type == OP_SELL)
   

   //Got this far, so no closure
   return(false);

}//End bool HaveWeHitRecoveryTarget(string symbol, int type)

I have a line drawn on the chart that represents the recovery price and it looks good.

:xm: :rocket:
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.
User avatar
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.

Post by SteveHopwood »

Gertje » Mon Nov 12, 2018 12:56 pm wrote:Here is the code from an EA where the recovery works like a charm.
No idea if the code is compatible, I'm no code-slinger by far.

Code: Select all

bool HaveWeHitRecoveryTarget(string symbol, int type, int index)
{
   //Calculate the Recovery target and close the trades if the target price is reached.
etc   
 
}//bool HaveWeHitRecoveryTarget(string symbol, int type)
Thanks. I only just saw this.

This is the code I adapted for Desky. I have not checked but will probably find that I used slightly different code to size and populate the array.

I am over-complicating thingies anyhow. CountOpenTrades() calculates a variable to hold the number of market trades - MarketBuysCount. I could have used this instead and will try it:
RecoveryTargetPrice/= MarketBuysCount;

Not to worry. The function is working now:
Capture.PNG
+$255 :clap: :clap: :clap:

Hehe. You can see why Thomas did not want to get involved with coding Desky - no doubt he has enough hair-tearing to do with TDesk. :lol:

:xm: :rocket:
You do not have the required permissions to view the files attached to this post.
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.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Bloop alert

Post by SteveHopwood »

Desky on vy FX VPS wasn't trading, so I had a look and there is a mistake in the code that tells Desky what to do if EveryTickMode = false.

I am adding another anti-overtrading filter, and so will upload the fix later. DIYers, do a search for, "if (CandleOpenTime[pairIndex] != iTime(symbol, EveryTickTimeFrame, 0) )"

and change it to:
if (CandleOpenTime[pairIndex] == iTime(symbol, EveryTickTimeFrame, 0) )

:xm: :rocket:
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.
User avatar
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.

Post by SteveHopwood »

V 2b is in post 1, with the fix I described in my previous post.

I have added a new anti-overtrading filter. From the updated UG:
  • Maximum trading pairs: this is another anti-overtrading filter. It allows you to limit the number of pairs that can have open trades:
    • MaxPairsAllowedToTrade: this is the limit to the number of pairs you will allow to trade simultaneously. Desky will initiate trading on no further fresh pairs once this maximum is reached.
:xm: :rocket:
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.
Post Reply

Return to “TDesk: A Thomas Special. The greatest trading tool ever.”