Desky. TDesk's trading drone.

Post Reply
User avatar
SteveHopwood
Owner
Posts: 9754
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 »

wallywonka » Thu Jan 02, 2020 11:05 am wrote:
SteveHopwood » Thu Jan 02, 2020 9:27 am wrote:
wallywonka » Wed Jan 01, 2020 11:07 pm wrote:Seems to be a bug in 4b where it won't open a sell trade if set to open trade immediately. If you set to pending it will place the pending sell okay.
Make sure your MaxTradesPerDay input is set to zero.

:xm: :rocket:
Steve, yeah it is on Zero but only opens Buys when set to send trades immediately...

I am just using pending now as a workaround, no idea why it's happening.
I don't see how this can be caused by the max daily trades thingy, but do me a favour please. Load the code into the editor and do a search for //Max trades during the day

Comment out the code block, recompile and see if the bot starts sending sells again.

: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. [email protected] 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: 9754
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 4c is inpost 1, with the scaling back in code added. Details in the user guide.

DIYers, add the inputs. Search for: extern int NoOfLevels=4;

Add the scale back in inputs underneath:
extern bool UseScaleBackIn=false;
extern string ScaleBackInTradeComment="Scale in";

Go to: bool scaleOutStopLoss(int ticket)

Replace the entire function with this:

Code: Select all

bool scaleOutStopLoss(int ticket)
{

   /*
   Called from countOpenTrades()
   
   This function examines an open trade to see if the phased stop loss should be used.
   Returns 'true' if there is a part-closure, else false.
   
   This cannot be applied to hedged trades.
   */
   
   //Check the order is still open
   if (!betterOrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
      return(false);
      
   //Cannot work this function if there is no stop loss
   //if (closeEnough(OrderStopLoss(), 0) ) 
   //   return(false); 

   //Save stuff for easier typing
   int type = OrderType();
   string symbol = OrderSymbol();
   double price = OrderOpenPrice();
   double stop = OrderStopLoss();
   double take = OrderTakeProfit();
   if (HideStopLossAndTakeProfit)
      stop = calculateStopLoss(symbol, type, price);
      
   getBasics(symbol);//Always good to include this in a function

   //No further action needed if the trade is in profit
   if (type == OP_BUY)
      if (bid > price)
      {
         return(false);
      }//if (bid > price)
      
   if (type == OP_SELL)
      if (ask < price)
      {
         return(false);
      }//if (ask < price)
      
   
   //We have a trade and it is a loser. Calculate the distance
   //in between the order open price and the stop loss. The order open price
   //does not change following a partial closure. Not when tested on a GP demo, at least. Fuck
   //only knows what happens with the criminal element masquerading as 'brokers'.
   double slpips = MathAbs(price - stop);
   //Calculate the sl levels at which to partially close the trade.
   double slLevel = slpips / NoOfLevels;
   
   //A variable to tell the code that part-closure is needed.
   bool closeNeeded = false;
   //A variable to hold the calculated price at each level.
   double calculatedLevel = price;
   //A variable to hold the amount to part-close
   double lotsToClose = normalizeLots(symbol, Lot / NoOfLevels);
   //Alert(lotsToClose);
   double targetLots = 0;
   
   //Loop through the levels and set the closeNeeded bool if the market has moved to
   //the calculatedLevel price
   for (int cc = 1; cc <= NoOfLevels; cc++)
   {
            
      //Buy trade
      if (type == OP_BUY)
      {
         //The trade is losing by at least one level
         calculatedLevel-= slLevel;
         if (bid <= calculatedLevel)
         {
            //We need to know if there has already been a partial close at this stop level
            targetLots = Lot - (lotsToClose * cc);            
            if (OrderLots() > targetLots)
            {
               closeNeeded = true;
               break;
            }//if (OrderLots() > targetLots)
               
         }//if (bid <= calculatedLevel)
            
      }//if (type == OP_BUY)
      
      
      //Sell trade
      if (type == OP_SELL)
      {
         //The trade is losing by at least one level
         calculatedLevel+= slLevel;
         if (ask >= calculatedLevel)
         {
            //We need to know if there has already been a partial close at this stop level
            targetLots = Lot - (lotsToClose * cc);            
            if (OrderLots() > targetLots)
            {
               closeNeeded = true;
               break;
            }//if (OrderLots() > targetLots)
         }//if (ask <= calculatedLevel)
            
      }//if (type == OP_SELL)
      
      
      //Alert(calculatedLevel);
   }//for (int cc = 1; cc <= NoOfLevels; cc++)
   
   //Should part of the trade be closed:
   if (closeNeeded)
   {
      bool result = OrderClose(ticket, lotsToClose, OrderClosePrice(), 5, clrNONE);
      if (result)
      {
         //Replace the trade with a stop order if scaling back in
         if (UseScaleBackIn)
         {
            int tries = 0;//To exit an endless loop because something went wrong
            double newPrice = 0;

            //Buy stop
            if (type == OP_BUY)
            {
               //Calculate the price for the stop order
               newPrice = NormalizeDouble(calculatedLevel + slLevel, digits);
               
               //We must have the order sent
               result = false;
               while (!result)
               {
                  if (IsTradeContextBusy() )
                     Sleep(2000);

                  result = sendSingleTrade(symbol, OP_BUYSTOP, ScaleBackInTradeComment, lotsToClose, newPrice, stop, take);
                  
                  //Exit an endless loop if something went wrong
                  if (!result)
                  {
                     tries++;
                     if (tries >= 100)
                        break;
                     Sleep(1000);   
                  }//if (!result)
               }//while (!result)
            }//if (type == OP_BUY)
            
         
            //Sell stop
            if (type == OP_SELL)
            {
               //Calculate the price for the stop order
               newPrice = NormalizeDouble(calculatedLevel - slLevel, digits);

               //We must have the order sent
               result = false;
               while (!result)
               {
                  if (IsTradeContextBusy() )
                     Sleep(2000);

                  result = sendSingleTrade(symbol, OP_SELLSTOP, ScaleBackInTradeComment, lotsToClose, newPrice, stop, take);
                  //Exit an endless loop if something went wrong
                  if (!result)
                  {
                     tries++;
                     if (tries >= 100)
                        break;
                     Sleep(1000);   
                  }//if (!result)
               }//while (!result)
            }//if (type == OP_SELL)
            
         
         }//if (UseScaleBackIn)
         
         
         return(true);
      }//if (result)
   }//if (closeNeeded)
   

   //Got here, so no closure
   return(false);

}//End bool scaleOutStopLoss(int ticket)
The scale back in code is the same as the code I added earlier to SPB. There may be bugs.

: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. [email protected] 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: 9754
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 »

4d is in post 1. The scale in/out code is working properly.

I explain how to DIY in this post: viewtopic.php?p=169327#p169327

: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. [email protected] 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
Sojourner
Trader
Posts: 105
Joined: Fri Apr 27, 2012 7:36 pm

Desky. TDesk's trading drone.

Post by Sojourner »

Getting this when Trying to compile:
You do not have the required permissions to view the files attached to this post.
User avatar
SteveHopwood
Owner
Posts: 9754
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 »

Sojourner » Fri Jan 03, 2020 7:27 pm wrote:Getting this when Trying to compile:
Get the correct TDesk stuff downloaded you idiot.

You are supposed to know what you are talking about when you post.

Or are you merely a dimwit in disguise? In need of demotion?
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. [email protected] 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
Sojourner
Trader
Posts: 105
Joined: Fri Apr 27, 2012 7:36 pm

Desky. TDesk's trading drone.

Post by Sojourner »

Sorry but I thought I did. I've been using Taipan's thing and got an email that said there was a new Desky so I downloaded it. Never had a problem compiling desky before.
Maybe I've got my posts mixed up.
User avatar
Vokin
Trader
Posts: 50
Joined: Tue Dec 06, 2011 4:31 pm

Desky. TDesk's trading drone.

Post by Vokin »

Sojourner » Fri Jan 03, 2020 8:53 pm wrote:Sorry but I thought I did. I've been using Taipan's thing and got an email that said there was a new Desky so I downloaded it. Never had a problem compiling desky before.
Maybe I've got my posts mixed up.
I had the same problem a long time ago, the mistake was always on my side. I compiled in the editor from the directory where the related files were missing. :youknow:
User avatar
Vokin
Trader
Posts: 50
Joined: Tue Dec 06, 2011 4:31 pm

Desky. TDesk's trading drone.

Post by Vokin »

Hi Steve,
maybe something wrong with basket - or my mistake. I'm set TP 75 for basket, but at screen is TP10 - so it also closed.
Can you help me?
Regards
V.
You do not have the required permissions to view the files attached to this post.
User avatar
SteveHopwood
Owner
Posts: 9754
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 »

Vokin » Fri Jan 10, 2020 2:05 pm wrote:Hi Steve,
maybe something wrong with basket - or my mistake. I'm set TP 75 for basket, but at screen is TP10 - so it also closed.
Can you help me?
Regards
V.
Your mistake. It is Friday. Look at your BasketFridayCashTargets input.

: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. [email protected] 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
Vokin
Trader
Posts: 50
Joined: Tue Dec 06, 2011 4:31 pm

Desky. TDesk's trading drone.

Post by Vokin »

Understand - I thought the setting:
-- Trading done for the day inputs -- false, applies to the entire section.
Anyway - thanks for answer.
Post Reply

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