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

Desky. TDesk's trading drone.
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5545
Page 11 of 50
Author:  SteveHopwood [ Sat Nov 10, 2018 2:36 pm ]
Post subject:  Desky. TDesk's trading drone.

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:
Author:  SteveHopwood [ Sun Nov 11, 2018 3:01 pm ]
Post subject:  Desky. TDesk's trading drone.

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:
Author:  trader689 [ Sun Nov 11, 2018 9:22 pm ]
Post subject:  Desky. TDesk's trading drone.

Great thanks Steve! All set for the new week with a fixed Desky - woot :cheer: :party:
Author:  SteveHopwood [ Mon Nov 12, 2018 12:29 am ]
Post subject:  Desky. TDesk's trading drone.

: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:
Author:  SteveHopwood [ Mon Nov 12, 2018 12:28 pm ]
Post subject:  Desky. TDesk's trading drone.

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

:xm: :rocket:
Author:  Gertje [ Mon Nov 12, 2018 12:56 pm ]
Post subject:  Desky. TDesk's trading drone.

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)
Author:  SteveHopwood [ Mon Nov 12, 2018 1:01 pm ]
Post subject:  Desky. TDesk's trading drone.

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:
Author:  SteveHopwood [ Mon Nov 12, 2018 2:06 pm ]
Post subject:  Desky. TDesk's trading drone.

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:
Author:  SteveHopwood [ Mon Nov 12, 2018 3:37 pm ]
Post subject:  Bloop alert

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:
Author:  SteveHopwood [ Mon Nov 12, 2018 4:52 pm ]
Post subject:  Desky. TDesk's trading drone.

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:
All times are UTC Page 11 of 50