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

Holy Graily Bob 'n Grid
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4525
Page 31 of 99
Author:  SteveHopwood [ Sat Mar 05, 2016 12:54 pm ]
Post subject:  Holy Graily Bob 'n Grid

Kevin wrote to me again last night with another bloop he found in the code. :clap: :clap: :clap:

V 2c is in post 1. The change is tiny but ridiculously significant for those of us relying on semafor signal closures.

To make the change yourselves, line 2116
if (OldM1SemTime != iTime(Symbol(), TradingTimeFrame, 0))

becomes
if (OldM1SemTime != iTime(Symbol(), PERIOD_M1, 0))

then replace TradingTimeFrame with PERIOD_M1 in line 2118 as well.


PERIOD_M1 is a mql4 'constant' that holds the value 1. Try typing it out instead of copy/pasting and the editor will show you a list of PERIOD constants.

:xm:
Author:  k3v1n0s [ Sat Mar 05, 2016 1:48 pm ]
Post subject:  Holy Graily Bob 'n Grid

Thanks Steve for allowing me to somehow contribute.

Those are my results this week on my live account, and I was playing around (trying different settings) until tuesday evening. :smile: So mostly, from wednesday on, I left HGB'nG trading 10 pairs, OOTB, but trading the thursday candle enabled and breakeven and jumpingstop disabled.
results.PNG
Should I consider leaving my day job? Just kidding. :smile:

Let's be patient and humble.

Cheers,

Kevin
Author:  pt2004 [ Sat Mar 05, 2016 2:05 pm ]
Post subject:  Holy Graily Bob 'n Grid

Hello,

Do you use any trade manager, partial close?

Cheers

PT

k3v1n0s » Sat Mar 05, 2016 2:48 pm wrote:Thanks Steve for allowing me to somehow contribute.

Those are my results this week on my live account, and I was playing around (trying different settings) until tuesday evening. :smile: So mostly, from wednesday on, I left HGB'nG trading 10 pairs, OOTB, but trading the thursday candle enabled and breakeven and jumpingstop disabled.



Should I consider leaving my day job? Just kidding. :smile:

Let's be patient and humble.

Cheers,

Kevin
Author:  k3v1n0s [ Sat Mar 05, 2016 2:08 pm ]
Post subject:  Holy Graily Bob 'n Grid

Hi PT,

Nope, after tuesday evening (and that's when almost all the action of this week happened) I left HGB'nG handsfree, closing out trades by himself. Before that, I was closing manually and trying different settings.

Cheers,

Kevin
Author:  SteveHopwood [ Sat Mar 05, 2016 2:30 pm ]
Post subject:  Holy Graily Bob 'n Grid

Live, lost pips but gained cash:
Lost pips gained cash.png
---------------------------------------------------------------------

I know some of you are interested in my multi-pairs un-interfered with demo:
Full on.png
This is one week of trading.

HGB is loaded onto all the pairs offered by the 'Open Charts in Alphabetical Order Indicator'. Start balance $5,000 so lots 0.05. Current balance $6,160 but the open position takes the equity down to $5915. There are some 0.06 lot trades in there, so the equity has also been over £6,000 at some point.

Amazing to see the pips generated by just 5 trades across the three best performers. Time to expand the pairs on my live account, methinks. :yahoo:

I am beginning to hope that we might attain the holy grail of an EA that can be left mostly to its own devices. Would that be a triumph, or what?

:xm:
Author:  pt2004 [ Sat Mar 05, 2016 2:34 pm ]
Post subject:  Holy Graily Bob 'n Grid

Ok,

Thank you.

Will try this next week.

Cheers

PT
k3v1n0s » Sat Mar 05, 2016 3:08 pm wrote:Hi PT,

Nope, after tuesday evening (and that's when almost all the action of this week happened) I left HGB'nG handsfree, closing out trades by himself. Before that, I was closing manually and trying different settings.

Cheers,

Kevin
Author:  Peepaws [ Sat Mar 05, 2016 4:02 pm ]
Post subject:  Holy Graily Bob 'n Grid

SteveHopwood » Sat Mar 05, 2016 2:30 pm wrote:Live, lost pips but gained cash:


---------------------------------------------------------------------

I know some of you are interested in my multi-pairs un-interfered with demo:


This is one week of trading.

HGB is loaded onto all the pairs offered by the 'Open Charts in Alphabetical Order Indicator'. Start balance $5,000 so lots 0.05. Current balance $6,160 but the open position takes the equity down to $5915. There are some 0.06 lot trades in there, so the equity has also been over £6,000 at some point.

Amazing to see the pips generated by just 5 trades across the three best performers. Time to expand the pairs on my live account, methinks. :yahoo:

I am beginning to hope that we might attain the holy grail of an EA that can be left mostly to its own devices. Would that be a triumph, or what?

:xm:

I am so impressed by everyone's results with HGBnG and so thankful to Steve, Bob, Cyber, and everyone else involved in making HGI and the HGB bots to trade it. I will soon be able to fund a GP account which is what I've been waiting for, for the last year. Anyone using a broker other than Global Prime I would urge you to switch if at all possible. I've been trading with another broker and paying far more for the fixed spreads they offer, which basically kills the profits of any EA I try, while the profits pour in on my GP demo.

Steve I think this EA is a Triumph already and I am very grateful for all the hard work that has gone in to it.

I can't wait to be able to give back to you monitarily but in the meantime you will have to accept my thanks!

:good: :good: :good: :good: :good: :good: :good: :good: :good: :good: :good: :good: :good: :good: :good: :good: :good:
Author:  SteveHopwood [ Sat Mar 05, 2016 5:56 pm ]
Post subject:  Holy Graily Bob 'n Grid

V 2d is in post 1.

Kevin is rapidly developing star status so far as I am concerned. :clap: :clap: :clap: I had noticed that replacement grids were not always being sent as required, and had used the grid-send/remove the ea feature a couple of times on Friday to replace them. I assumed I had something wrong in my own settings and was going to investigate this weekend.

Kevin noticed the same and went digging. He saw that the replacements were in fact being sent, but then instantly deleted. He did some more digging and found some flaws in the program logic that were causing the problems. 2d contains his fixes. They make total sense to me.

Go to void ShouldTradesBeClosed() at line 3840 if you want to make your own changes, and copy this replacement 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
   
}//End void ShouldTradesBeClosed()

Thanks on all our behalves Kevin.

:xm:
Author:  SteveHopwood [ Sun Mar 06, 2016 4:41 pm ]
Post subject:  Holy Graily Bob 'n Grid

Peepaws » Sat Mar 05, 2016 4:02 pm wrote:
II will soon be able to fund a GP account which is what I've been waiting for, for the last year. Anyone using a broker other than Global Prime I would urge you to switch if at all possible.
I second that.

I third, fourth and fifth it as well. GP are a breath of fresh air in the stinking pit occupied by most of the other firms.

:xm:
Author:  SteveHopwood [ Mon Mar 07, 2016 5:11 pm ]
Post subject:  Holy Graily Bob 'n Grid

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:
All times are UTC Page 31 of 99