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

Holy Graily Bob 'n Grid
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4525
Page 32 of 99
Author:  k3v1n0s [ Mon Mar 07, 2016 5:59 pm ]
Post subject:  Holy Graily Bob 'n Grid

SteveHopwood » 07 Mar 2016, 18:11 wrote:Kevin's fixes are working beautifully in 2d. The successful side of my GU hedge was just closed after the semafor signal appeared, and HGB has sent the protective buy stop grid.
Thanks Kevin. :clap: :clap: :clap: :clap: :clap:
:xm:
Steve,

That's amazing! Let those pips flow into our accounts now ;)

HGB'nG is making a bomb today... Already 89 pips in the bag, and another 111 floating! :yahoo:

Quite a good start into the week. ;)
monday.PNG
Cheers,

Kevin
Author:  szfxtrader [ Mon Mar 07, 2016 6:55 pm ]
Post subject:  Holy Graily Bob 'n Grid

k3v1n0s » Mon Mar 07, 2016 5:59 pm wrote:
Steve,

That's amazing! Let those pips flow into our accounts now ;)

HGB'nG is making a bomb today... Already 89 pips in the bag, and another 111 floating! :yahoo:

Quite a good start into the week. ;)



Cheers,

Kevin
Could you please share your settings file? Thank you in advance!
Author:  k3v1n0s [ Mon Mar 07, 2016 7:05 pm ]
Post subject:  Holy Graily Bob 'n Grid

Hi szfxtrader,

Sure, here you have it :
HGBnG.set
I let HGB'nG run handsfree on 10 pairs : EURUSD, USDJPY, EURJPY, EURGBP, GBPUSD, GBPJPY, AUDUSD, AUDJPY, USDCAD, CADJPY.

Don't forget to adapt trading hours, I live on GMT+1.

Cheers,

Kevin
Author:  szfxtrader [ Mon Mar 07, 2016 7:12 pm ]
Post subject:  Holy Graily Bob 'n Grid

k3v1n0s » Mon Mar 07, 2016 7:05 pm wrote:Hi szfxtrader,

Sure, here you have it :



I let HGB'nG run handsfree on 10 pairs : EURUSD, USDJPY, EURJPY, EURGBP, GBPUSD, GBPJPY, AUDUSD, AUDJPY, USDCAD, CADJPY.

Don't forget to adapt trading hours, I live on GMT+1.

Cheers,

Kevin
Thank you very much!
Author:  patmontes [ Tue Mar 08, 2016 1:38 am ]
Post subject:  Holy Graily Bob 'n Grid

Hi Guys
Just checking if same transpired on your GY H4 charts. Up Green Arrow, Grid buy sells where sent, Sells triggered and in profit, yellow range wavy appeared on top of price, open and stop orders got closed, we are in proft, wait for next signal. :hi:
Author:  Lazerus [ Tue Mar 08, 2016 10:07 am ]
Post subject:  Holy Graily Bob 'n Grid

k3v1n0s » Mon Mar 07, 2016 7:05 pm wrote:Hi szfxtrader,

Sure, here you have it :



I let HGB'nG run handsfree on 10 pairs : EURUSD, USDJPY, EURJPY, EURGBP, GBPUSD, GBPJPY, AUDUSD, AUDJPY, USDCAD, CADJPY.

Don't forget to adapt trading hours, I live on GMT+1.

Cheers,

Kevin

Hi Kevin,
first of all I´d like to thank you and steve for their effort in this ea! :!!:

could you please tell me which timeframe you are working on?

regards and thanks

Marc
Author:  k3v1n0s [ Tue Mar 08, 2016 10:57 am ]
Post subject:  Holy Graily Bob 'n Grid

Hi Lazerus,

My effort is nothing compared to Steve's. You have to thank him way more. ;)

I'm running HGB'nG on H4.

Cheers,

Kevin
Author:  SteveHopwood [ Tue Mar 08, 2016 2:36 pm ]
Post subject:  Holy Graily Bob 'n Grid

V 2e is in post 1.

I had three badly losing GJ trades closed by the bot earlier on, and I have no idea why. I still have no idea why, but digging through the code I saw that I had not implemented yellow wavy line closure. I have implemented that and added a feature to stop it closing groups of trades unless they are in a cash profit. From the updated user guide:
  • CloseOnYellowRangeWave: tells HGB'nG to close all open trades and delete outstanding stop/limit orders when HGI judges the market to be ranging. This does not apply to hedged positions.
  • OnlyCloseProfitablePositions: acts with CloseOnYellowRangeWave and is best limited to the stop orders only system. This prevents HGB'nG from closing groups of trades if they are not in a cash profit.
Are you getting into making these changes for yourselves? If so:
Line 8 becomes:
#define version "Version 2e"

Go to line 239 and insert this:

Code: Select all

//Stop unprofitable positions being closed by either of the two inputs above.
extern bool    OnlyCloseProfitablePositions=true;
Then go to void ShouldTradesBeClosed() roughly at line 3843 and copy this over the top of the entire function:

Code: Select all

void ShouldTradesBeClosed()
{
       
   if (OpenTrades == 0)
      return;//Nothing to do

   int tries = 0;
   //We only want trades closing if the trades are based on a previous candle's signal
   if (LatestTradeTime < iTime(Symbol(), TradingTimeFrame, 0) )
   {
      
      //Opposite direction semafor
      //Close buys
      if (CloseTradesOnRelevantSemafor || CloseImmediatelySemaforAppears)//semafor
      {
            //SemStatus will only == highsemafor or highsemafornow if CloseImmediatelySemaforAppears is enabled
            if (SemStatus == highsemafor || SemStatus == highsemafornow)
            {
               tries = 0;
               //Close buys
               if (BuyOpen && (!CloseOnlyInPositivePips || BuyPipsUpl > 0))
               {
                  ForceTradeClosure = true;
                  while (ForceTradeClosure)
                  {
                     CloseAllTrades(OP_BUY);
                     CloseAllTrades(OP_BUYSTOP);
                     if (DeleteAndReplaceLosersGrid || !SellOpen)
                        CloseAllTrades(OP_SELLSTOP);
                     if (ForceTradeClosure)
                        Sleep(1000);
                     tries++;
                     if (tries >= 100)
                     {
                        ForceTradeClosure = false;
                        break;
                     }//if (tries >= 100)
                  }//while (ForceTradeClosure)
               
                  //Replace the grids for the stop orders method
                  if (GridType == Stop_Orders_Only)
                  {
                     if (ReplaceWinnersGrid)
                        if (SellOpen)//open sells means the cycle has not ended and we want new buy stop orders ready in case market resumes its upward move
                           SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
                     if (DeleteAndReplaceLosersGrid)
                        if (SellOpen)//open sells means the cycle has not ended and we want new sell stop orders much closer to the market
                           SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);
                  }//if (GridType == Stop_Orders_Only)
                  
                  return;//Nothing more for this function to do
               }//if (BuyOpen)
            }//if (SemStatus == highsemafor || SemStatus == highsemafornow)
            
            //SemStatus will only == lowsemafor or lowsemafornow if CloseImmediatelySemaforAppears is enabled
            if (SemStatus == lowsemafor || SemStatus == lowsemafornow)
            {        
               tries = 0;
               //Close sells
               if (SellOpen && (!CloseOnlyInPositivePips || BuyPipsUpl > 0))
               {
                  ForceTradeClosure = true;
                  while (ForceTradeClosure)
                  {
                     CloseAllTrades(OP_SELL);
                     CloseAllTrades(OP_SELLSTOP);
                     if (DeleteAndReplaceLosersGrid || !BuyOpen)
                        CloseAllTrades(OP_BUYSTOP);
                     if (ForceTradeClosure)
                        Sleep(1000);
                     tries++;
                     if (tries >= 100)
                     {
                        ForceTradeClosure = false;
                        break;
                     }//if (tries >= 100)
                  }//while (ForceTradeClosure)
                  
                  //Replace the sell grid for the stop orders method
                  if (GridType == Stop_Orders_Only)
                  {
                      if (ReplaceWinnersGrid)
                        if (BuyOpen)//open buys means the cycle has not ended and we want new sell stop orders ready in case market resumes its downward move
                           SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);
                      if (DeleteAndReplaceLosersGrid)
                        if (BuyOpen)//open buys means the cycle has not ended and we want new buy stop orders much closer to the market
                           SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
                  }//if (GridType == Stop_Orders_Only)
   
                  return;//Nothing more for this function to do
                     
               }//if (SellOpen)              
            }//if (SemStatus == lowsemafor || SemStatus == lowsemafornow)         
        
      }//if (CloseTradesOnRelevantSemafor || CloseImmediatelySemaforAppears)//semafor
   }//if (LatestTradeTime < iTime(Symbol(), TradingTimeFrame, 0) )
           
   
   //Hedged position. Has it hit tp?
   if (Hedged)
   {
      bool ClosePosition = false;
      
      //Have we hit pips upl
      if (HedgeProfitPips > 0)
         if (PipsUpl >= HedgeProfitPips)
            ClosePosition = true;
            
      //Have we hit cash upl
      if (!ClosePosition)   
         if (HedgeProfitCash > 0)
            if (CashUpl >= HedgeProfitCash)
               ClosePosition = true;
               
      if (ClosePosition)
      {
         tries = 0;
         ForceTradeClosure = true;
         while(ForceTradeClosure)
         {
            ForceTradeClosure = false;
            if (BuyOpen)
               CloseAllTrades(OP_BUY);
            if (SellOpen)
               CloseAllTrades(OP_SELL);   
            if (SellStopOpen)
               CloseAllTrades(OP_SELLSTOP);
            if (SellLimitOpen)
               CloseAllTrades(OP_SELLLIMIT);
            if (BuyStopOpen)
               CloseAllTrades(OP_BUYSTOP);
            if (BuyLimitOpen)
               CloseAllTrades(OP_BUYLIMIT);   
               
               tries++;
               if (tries >= 100)
               {
                  ForceTradeClosure = false;
                  break;
               }//if (tries >= 100)
         }//while(ForceTradeClosure)
         
            
      }//if (ClosePosition)
      
      //Close the profitable bit of the hedge following a yellow wavy line
      if (CloseProfitableSideOnYellowWavy)
         if (WaveStatus == Waverange)
         {
            //Is the buy side in a cash profit
            if (BuyCashUpl >= 0)
            {
               tries = 0;
               ForceTradeClosure = true;
               while(ForceTradeClosure)
               {
                  ForceTradeClosure = false;
                  if (BuyOpen)
                     CloseAllTrades(OP_BUY);
                  if (BuyStopOpen)
                     CloseAllTrades(OP_BUYSTOP);
                  if (BuyLimitOpen)
                     CloseAllTrades(OP_BUYLIMIT);   
                     
                     tries++;
                     if (tries >= 100)
                     {
                        ForceTradeClosure = false;
                        break;
                     }//if (tries >= 100)
               }//while(ForceTradeClosure)

               //Grid replacement
               if (!ForceTradeClosure)
               {
                  //Replace the buy grid in case the market continues to rise
                  SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
                  //Replace the sell grid in the hope that the market will fall
                  SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);
               }//if (!ForceTradeClosure)
               
               if (!ForceTradeClosure)
                  return;//Everything worked. Makes a bloody change.            
            }//if (BuyCashUpl >= 0)
            
            //Is the sell side in a cash profit
            if (SellCashUpl >= 0)
            {
               tries = 0;
               ForceTradeClosure = true;
               while(ForceTradeClosure)
               {
                  ForceTradeClosure = false;
                  if (SellOpen)
                     CloseAllTrades(OP_SELL);
                  if (SellStopOpen)
                     CloseAllTrades(OP_SELLSTOP);
                  if (SellLimitOpen)
                     CloseAllTrades(OP_SELLLIMIT);   
                     
                     tries++;
                     if (tries >= 100)
                     {
                        ForceTradeClosure = false;
                        break;
                     }//if (tries >= 100)
               }//while(ForceTradeClosure)

               //Grid replacement
               if (!ForceTradeClosure)
               {
                  //Replace the sell grid in the hope that the market continues to fall
                  SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);
                  //Replace the buy grid in case it rises instead
                  SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
               }//if (!ForceTradeClosure)
               
               if (!ForceTradeClosure)
                  return;//Everything worked. Makes a bloody change.            
            }//if (SellCashUpl >= 0)
            
         
         }//if (WaveStatus == Waverange)
         
        
      //A hedged position overrides all else, so no need to continue with this function.
      return;
         
   }//if (Hedged)
      
   
   //We only want trades closing if the trades are based on a previous candle's signal
   if (LatestTradeTime < iTime(Symbol(), TradingTimeFrame, 0) )
   {
      //Buy signal
      if (BuySignal)
         if (OriginalSignal != OP_SELL)
         {
            tries = 0;
            ForceTradeClosure = true;
            while(ForceTradeClosure)
            {
               if (SellOpen)
                  CloseAllTrades(OP_SELL);
               if (SellStopOpen)
                  CloseAllTrades(OP_SELLSTOP);
               if (SellLimitOpen)
                  CloseAllTrades(OP_SELLLIMIT);
                  tries++;
                  if (tries >= 100)
                  {
                     ForceTradeClosure = false;
                     break;
                  }//if (tries >= 100)
           }//while(ForceTradeClosure)
           if (!ForceTradeClosure)
               if(BuyOpen) //)//open buys means the cycle has not ended and we want new sell stop orders ready in case market resumes its downward move
                  //Replace the sell grid in the case that the market continues to fall
                  SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);   
         }//if (OriginalSignal != OP_SELL)
         
      //Sell signal
      if (SellSignal)
         if (OriginalSignal != OP_BUY)
         {
            tries = 0;
            ForceTradeClosure = true;
            while(ForceTradeClosure)
            {
               if (BuyOpen)
                  CloseAllTrades(OP_BUY);
               if (BuyStopOpen)
                  CloseAllTrades(OP_BUYSTOP);
               if (BuyLimitOpen)
                  CloseAllTrades(OP_BUYLIMIT);
                  tries++;
                  if (tries >= 100)
                  {
                     ForceTradeClosure = false;
                     break;
                  }//if (tries >= 100)
           }//while(ForceTradeClosure)
           if (!ForceTradeClosure)
               if(SellOpen)//open sells means the cycle has not ended and we want new buy stop orders ready in case market resumes its upward move
                  //Replace the buy grid in the case that the market continues to rise
                  SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);      
         }//if (OriginalSignal != OP_BUY)
            
   }//if (LatestTradeTime < iTime(Symbol(), TradingTimeFrame, 0) )
      
   
   
   //No trade signal. Delete existing pendings if none of them have filled.
   if (LatestTradeTime >= iTime(Symbol(), TradingTimeFrame, 0) )
      if (HgiSignalStatus == hginosignal && WaveStatus == Wavenone && SemStatus == nosemafor)
         if (!BuyOpen)
            if (!SellOpen)
            {
               tries = 0;
               ForceTradeClosure = true;
               while(ForceTradeClosure)
               {
                  ForceTradeClosure = false;
                  if (SellStopOpen)
                     CloseAllTrades(OP_SELLSTOP);
                  if (SellLimitOpen)
                     CloseAllTrades(OP_SELLLIMIT);
                  if (BuyStopOpen)
                     CloseAllTrades(OP_BUYSTOP);
                  if (BuyLimitOpen)
                     CloseAllTrades(OP_BUYLIMIT);   
                  tries++;
                  if (tries >= 100)
                  {
                     ForceTradeClosure = false;
                     break;
                  }//if (tries >= 100)
              }//while(ForceTradeClosure) 
            }//if (!SellOpen)
            
   //All market trades have hit tp
   if (PendingTradesTotal <= GridSize)//There should be up to GridSize * 2
      if (MarketTradesTotal == 0)//And all the market trades have hit tp or sl
      {
         ForceTradeClosure = true;
         while(ForceTradeClosure)
         {
            tries = 0;
            ForceTradeClosure = false;
            if (SellStopOpen)
               CloseAllTrades(OP_SELLSTOP);
            if (SellLimitOpen)
               CloseAllTrades(OP_SELLLIMIT);
            if (BuyStopOpen)
               CloseAllTrades(OP_BUYSTOP);
            if (BuyLimitOpen)
               CloseAllTrades(OP_BUYLIMIT);   
                  tries++;
                  if (tries >= 100)
                  {
                     ForceTradeClosure = false;
                     break;
                  }//if (tries >= 100)
        }//while(ForceTradeClosure) 
      }//if (MarketTradesTotal == 0)//And all the market trades have hit tp or sl
   
   //Yellow wavy range
   if (CloseOnYellowRangeWave)
   {
      //Buy trades
      if (!OnlyCloseProfitablePositions || BuyCashUpl > 0)
      {
         ForceTradeClosure = true;
         while(ForceTradeClosure)
         {
            tries = 0;
            ForceTradeClosure = false;
            if (BuyOpen)
               CloseAllTrades(OP_BUY);
            if (BuyStopOpen)
               CloseAllTrades(OP_BUYSTOP);
            if (BuyLimitOpen)
               CloseAllTrades(OP_BUYLIMIT);   
            
            tries++;
            if (tries >= 100)
            {
               ForceTradeClosure = false;
               break;
            }//if (tries >= 100)
         }//while(ForceTradeClosure) 
         CountOpenTrades();
         
      }//if (!OnlyCloseProfitablePositions || BuyCashUpl > 0)
      
      //Sell trades
      if (!OnlyCloseProfitablePositions || SellCashUpl > 0)
      {
         ForceTradeClosure = true;
         while(ForceTradeClosure)
         {
            tries = 0;
            ForceTradeClosure = false;
            if (SellOpen)
               CloseAllTrades(OP_SELL);
            if (SellStopOpen)
               CloseAllTrades(OP_SELLSTOP);
            if (SellLimitOpen)
               CloseAllTrades(OP_SELLLIMIT);   
            
            tries++;
            if (tries >= 100)
            {
               ForceTradeClosure = false;
               break;
            }//if (tries >= 100)
         }//while(ForceTradeClosure) 
         CountOpenTrades();
         
      }//if (!OnlyCloseProfitablePositions || SellCashUpl > 0)
      
   
   }//if (CloseOnYellowRangeWave)
   
   
}//End void ShouldTradesBeClosed()

:xm:
Author:  Raj4x [ Tue Mar 08, 2016 3:14 pm ]
Post subject:  Holy Graily Bob 'n Grid

SteveHopwood » Mon Mar 07, 2016 10:41 pm wrote:Kevin's fixes are working beautifully in 2d. The successful side of my GU hedge was just closed after the semafor signal appeared, and HGB has sent the protective buy stop grid.

Thanks Kevin. :clap: :clap: :clap: :clap: :clap:

:xm:
Awesome community effort :cheer: :cheer: :cheer:
Author:  SteveHopwood [ Tue Mar 08, 2016 6:45 pm ]
Post subject:  Holy Graily Bob 'n Grid

V 2f is in post 1, thanks to Kevin.

He has spotted a few thingies that were wrong, added a few thingies to make the options better and rearranged a few thingies to make them more logical.

This is breathtaking stuff guys. Reading someone else's code is something I find really hard to do. HGB'nG started life as HGB plus a grid. Then came hedging. Then semafor........ Every time we add a layer of complexity to the code we add the opportunity for LUC to pay us a visit - and it becomes increasingly more difficult to sort out something that is not quite right.

Thanks Kevin. We owe you. :clap: :clap: :clap: :clap: :clap: :clap: :clap:

:xm:
All times are UTC Page 32 of 99