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

Goldy
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=6421
Page 13 of 14
Author:  SteveHopwood [ Sun Jul 06, 2025 7:37 pm ]
Post subject:  Re: Goldy

Modest progress for me last week but still ended up in profit. This included one disaster when I set StopTrading to 'true' whilst the position was in DD and G immediately closed all the trades at a loss. No idea why, so maybe best to remove her from the chart rather than what I did if you want to shut her down.

:xm: :rocket:
Author:  SteveHopwood [ Tue Jul 08, 2025 3:37 pm ]
Post subject:  Re: Goldy

V 1j is in post 1.

I added the feature to the chart display to show how the equity has increased from the start of each week. This will fluctuate with each tick. The idea is to help us decide when to pull the plug on a position manually.

This gave me the idea to implement a weekly equity gain take profit figure. The input is EquityTpMultiplier. Your equity gain TP is multiplied by this to give a weekly target. Goldy will shut up shop for the week once this figure is reached. A zero input will turn this feature off. There is also the option to remove Goldy from the chart altogether once the target is met.

:xm: :rocket:
Author:  SteveHopwood [ Thu Jul 17, 2025 11:46 am ]
Post subject:  Re: Goldy

V 1k is in post 1.

Early Goldy's development, I noticed that the equity target tp would occasionally be exceeded but the trades not closed. The distance to the next target would be a negative. Simplified version: target is 10; equity is 12; distance to next target is -2. I added a block of code to deal with this and it has worked so far as closing the position is concerned.

For reasons I cannot find in the code, this negative distance to next target is sometimes left as the negative. Here is what then happens:
  • The conditions exist to start a new position. "Yippee" cries Goldy enthusiastically and sends the new position.
  • There is another tick. Goldy sees that the equity is exceeding the negative distance, yells, "Yippee" joyously and deletes all the stop orders.
This happens tick by tick until we move out of trading hours.

V 1k appears to have solved this.

DIYers, go to void ShouldTradesBeClosed() and add this to the top of the function:

Code: Select all

   if (MarketTradesTotal == 0)
      return;//Only need this function if there are market orders   
Somehow, hedgeProfitTarget is being left negative, so do a search for this comment in OnTick():
//Ensure that the relevant gv's exist and replace them if not

Underneath the block of code that ends with:
cashToAddToEquity = GlobalVariableGet(cashToAddtGvName);

Insert this block:

Code: Select all

   /*Somehow, the hedgeProfitTarget could be left at less than the account equity
   after an equity TP closure. This would result in new positions being opened
   and immediately closed - no idea why. This code block attempts to solve the problem.
   */
   if (OpenTrades == 0)
   {
      if (hedgeProfitTarget <= AccountEquity() )
      {
         hedgeProfitTarget = NormalizeDouble((AccountEquity() + cashToAddToEquity), 2);
         GlobalVariableSet(hedgeProfitTargetGvName, hedgeProfitTarget);
      }//if (hedgeProfitTarget <= AccountEquity() )
      
   }//if (OpenTrades == 0)
:xm: :rocket:
Author:  marx64 [ Wed Jul 23, 2025 6:44 pm ]
Post subject:  Re: Goldy

Hi folks,
I have tried Goldy for several months in all available versions. My verdict: Goldy is not ready for live trading in current version. It might work, but it needs a constant manual intervention, which is not the idea of the automatic trading system. So please don't try this at home.
Author:  SteveHopwood [ Tue Aug 05, 2025 2:04 pm ]
Post subject:  Re: Goldy

V 1j is in post 1.

The weekly target stuff was a disaster, presumably through faulty coding. I have stripped out the code rather than battle to correct it. Manually stopping Goldy once a notional weekly target has been reached is hardly an onerous thingy to have to do.

A few weeks ago I found myself with 41 market sell orders. I have added code to prevent this happening and it seems to be working. Look directly underneath the MaxTradesAllowedPerPair input and you will see a new one - MaxTradesAllowedInTotal. This defaults to 20. Goldy will not send any more stop orders once the total of stops and market trades reaches this total, however unbalanced this leaves the position.

orso wrote to me last week saying that he was offsetting at two (MinOpenTradesToStartOffset = 2) and finding that this was doing an excellent job of keeping on top of draw down. I have tried this so far this week and it has indeed been successful. Early days for me but not for orso, so thanks my friend. :clap: :clap: :clap: :clap: :clap: I have made 2 the default in 1j.

A little irritant has emerged. Sometimes, when I press the F7 key to look at the inputs, the window loads without the section headers. Make sure you save your setfile so you can retrieve them if this happens to you.

:xm: :rocket:
Author:  AltosT [ Tue Aug 05, 2025 10:06 pm ]
Post subject:  Re: Goldy

Hi Steve - You have got a little out of sync. You posted 1j on July 9. This should be 1L if I am not mistaken.
Author:  SteveHopwood [ Wed Aug 06, 2025 11:54 am ]
Post subject:  Re: Goldy

AltosT wrote: Tue Aug 05, 2025 10:06 pm Hi Steve - You have got a little out of sync. You posted 1j on July 9. This should be 1L if I am not mistaken.
I probably just mixed up the versions. I have reuploaded the bot as V 1l. It doesn't really matter, but I also removed a redundant equity gain display from the chart so re-download if any of this bothers you.

The DIY is easy. You will see this version number at the top of the file:
#define version "Version 1j"

Change it to:
#define version "Version 1l"

Then do a search for this line of code:
SM(" Equity gain so far this week " + AccountCurrency() + " "

Comment out the code block so that it looks like this:

Code: Select all

   //SM("    Equity gain so far this week " + AccountCurrency() + "  " 
     // + DoubleToStr(weeklyEquityGain, 2) + "  Weekly target gain is " 
     // + AccountCurrency() + "  " + DoubleToStr(weeklyEquityTarget, 2) + NL);
:xm: :rocket:
Author:  SteveHopwood [ Sun Aug 17, 2025 4:34 pm ]
Post subject:  Re: Goldy

V 1m is in post 1.

I noticed that the, "Distance to next equity target" display was remaining negative after a position closure occurred after the equity had shot past the initial target. To explain with a ludicrously simple example:
  • Equity target is 10.
  • The actual equity has shot past this figure and is now 11 so the distance to the next equity target is now -1.
  • Goldy was not recalculating the various targets and distances so the distance to the next equity target would remain at -1 when she sent the new position.
  • Goldy would instantly spot that the current equity of 11 was greater than the target of -1 and so would delete all the new stop orders. :arrrg:
V 1m is an attempt to solve this.

The DIY is relatively straight forward. Save your setfile. Navigate to the void OnTick() function and scroll down to the CountOpenTrades(); command.

The next command is ShouldTradesBeClosed();

Replace the command with this code block:

Code: Select all

   //The next function deals with hedge/basket closures, so comment it out if not needed
   if (ShouldTradesBeClosed() )
   {
      //ShouldTradesBeClosed() deletes the globals if the closure target was hit,
      //so force a recalculation of the target at the next tick
      return;
   }//if (ShouldTradesBeClosed() )
I have changed the ShouldTradesBeClosed() function from a void to a boolean. Right click on the ShouldTradesBeClosed() command and click, "Go to Definition" (the top of the list). This will take you straight to the top of the function. Replace the entire function with this:

Code: Select all

bool ShouldTradesBeClosed()
{
   //Examine baskets of trades for possible closure
   
   if (OpenTrades == 0)
      return(false);//Nothing to do

   if (MarketTradesTotal == 0)
      return(false);//Only need this function if there are market orders   

   int tries = 0;
   bool closePosition = false;
/*      
   //Global variables to help detect deposits into the account.
   // 1) Detect any manual deposit (positive jump in AccountBalance
   //    that isn't due to closed trades—in demo it's just a deposit)
   double currentBalance = AccountBalance();
   double deltaBalance   = currentBalance - g_lastBalance;
   if(deltaBalance > 0)
   {
      // Assume it's a deposit; accumulate
      g_totalDeposits += deltaBalance;
   }//if(deltaBalance > 0)
   g_lastBalance = currentBalance;

   // 2) Compute "true" profit based on equity minus deposits
   double currentEquity     = AccountEquity();
   double equityNetOfDeposits = currentEquity - g_totalDeposits;
   double profitSoFar       = equityNetOfDeposits - g_initialBalance;//CR's original
   //hedgeProfitTarget = equityNetOfDeposits - g_initialBalance;//To fit with my coding
Alert(profitSoFar);
return;   
*/
   //Hedged position. Has it hit tp?
   if (!closePosition)
   {
      //Have we hit cash tp?
      if (!closePosition)   
         if (!CloseEnough(hedgeProfitTarget, 0) )
            if (AccountEquity() >= hedgeProfitTarget)
               closePosition = true;
         
   }//if (!closePosition)

   //Goldy kept on missing opportunities to close down when the cash upl
   //had shot well past hedgeProfitTarget. The chart feedback would show
   //a negative distance to the next euity target which meant that
   //the equity was well above the target. This next snippet is an attepmt
   //to deal with this.
   if (!closePosition)
      if (hedgeProfitTarget - AccountEquity() < 0)
         closePosition = true;
      
   //Exit the function if the target has not been reached
   if (!closePosition)
      return(false);
         
   if (closePosition)
   {
      tries = 0;
      ForceTradeClosure = true;
      while(ForceTradeClosure)//CloseAllTrades() resets ForceTradeClosure unless the close fails
      {
         ForceTradeClosure = false;
         CloseAllTrades(AllTrades);  
         tries++;
         if (tries >= 100)
         {
            break;
         }//if (tries >= 100)
      }//while(ForceTradeClosure)
      Alert(TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES) + " Equity target reached. All orders should have closed and the position re-started.");
   
      // Check if we should suspend trading due to previous ADX peak detection
      if (adxPeakDetectedAwaitingEquityTarget && SuspendTradingAfterEquityTargetOnADXPeak)
      {
         tradingSuspendedByADX = true;
         adxPeakDetectedAwaitingEquityTarget = false; // Reset the flag
         string suspendMessage = StringConcatenate(
            "Trading Suspended for ", Symbol(), 
            " - Equity target hit after ADX peak reversal. Trading suspended until ADX rises above ", 
            DoubleToStr(AdxTradeAllowedLevel, 0)
         );
         if (IncludeMobileDevicesInAlerts)
            SendNotification(suspendMessage);
         Alert(suspendMessage);
      }
      
      //Delete the gvs
      if (closePosition)
      {
         GlobalVariableDel(cashToAddtGvName);
         GlobalVariableDel(hedgeProfitTargetGvName);
         
         return(true);
      
      }//if (closePosition)
      
   
      /*
      //Remove the expert?
      if (RemoveGoldyAfterWeeklyEquityTpHit)
         if (!ForceTradeClosure)
            RemoveExpert = true;
      */
   
   }//if (closePosition)
   
   //Got here, so no position closure
   return(false);
   
}//bool ShouldTradesBeClosed()
Go to the top of the file and change the version number and recompile. Reload your setfile.

:xm: :rocket:
Author:  SteveHopwood [ Sun Aug 31, 2025 4:29 pm ]
Post subject:  Re: Goldy

A quick update.

I am finding orso's idea of offsetting at 2 really helpful. Lots of orders close with a teensy overall profit then the occasional run to the equity TP moves the account forward.

This is helping the accounts to recover from the weekly TP disaster.

Onwards and upwards.

:xm: :rocket:
Author:  trader689 [ Sun Aug 31, 2025 8:48 pm ]
Post subject:  Re: Goldy

looks like things are headed in the right direction, this is encouraging to hear. Thanks for the update

trader
SteveHopwood wrote: Sun Aug 31, 2025 4:29 pm A quick update.

I am finding orso's idea of offsetting at 2 really helpful. Lots of orders close with a teensy overall profit then the occasional run to the equity TP moves the account forward.

This is helping the accounts to recover from the weekly TP disaster.

Onwards and upwards.

:xm: :rocket:
All times are UTC Page 13 of 14