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

Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5101
Page 2 of 33
Author:  SteveHopwood [ Wed Mar 08, 2017 2:28 pm ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

V 1b is in post 1, trying to fix some stuff that TJF brought up in a pm this morning. Nice pics TJF - most helpful. Not sure if the fixes are working and I have not had the problem TJF described, but some of the code I wrote yesterday was total bollocks, so better to have an attempted correction.

The default inputs reflect my demo trading on a $10,000 account on the biggies + GJ. I have some lovely trades at the mo.


DIYers:
Comment out line 1942.

Copy this over the top of bool LookForTradeClosure(int ticket).

Code: Select all

bool LookForTradeClosure(int ticket)
{
   //Close the trade if the close conditions are met.
   //Called from within CountOpenTrades(). Returns true if a close is needed and succeeds, so that COT can increment cc,
   //else returns false
   
   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET) ) return(true);
   if (BetterOrderSelect(ticket, SELECT_BY_TICKET) && OrderCloseTime() > 0) return(true);
   
   bool CloseThisTrade = false;
   
   string LineName = TpPrefix + DoubleToStr(ticket, 0);
   //Work with the lines on the chart that represent the hidden tp/sl
   double take = ObjectGet(LineName, OBJPROP_PRICE1);
   if (CloseEnough(take, 0) ) take = OrderTakeProfit();
   LineName = SlPrefix + DoubleToStr(ticket, 0);
   double stop = ObjectGet(LineName, OBJPROP_PRICE1);
   if (CloseEnough(stop, 0) ) stop = OrderStopLoss();
   
   
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)
   {
      //TP
      if (Bid >= take && !CloseEnough(take, 0) && !CloseEnough(take, OrderTakeProfit()) ) CloseThisTrade = true;
      //SL
      if (Bid <= stop && !CloseEnough(stop, 0)  && !CloseEnough(stop, OrderStopLoss())) CloseThisTrade = true;

      
      //Close trade on opposite direction signal
      if (BuyCloseSignal)
         CloseThisTrade = true;

      
      //Delete pendings on a new signal.
      //You may need to make changes here.
      if (!CloseThisTrade)
        if (SellSignal)
            if (DeletePendingsOnNewSignal)
               if (MarketTradesTotal == 0)
                  CloseThisTrade = true;
   
      
     //Change of SS colour and/or opposite direction FB
     //Higher time frame
     if (!CloseThisTrade)
        if (UseSsHigherTimeFrameControl)
        {
            if (SsCloseTradesOnHtfColourChange)
               if(SsHtfColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnHtfColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsHtfColour == red)
                     if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsHigherTimeFrameControl)
       
     //Medium time frame
     if (!CloseThisTrade)
        if (UseSsMediumTimeFrameControl)
        {
            if (SsCloseTradesOnMtfColourChange)
               if(SsMtfColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnMtfColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsMtfColour == red)
                     if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsMediumTimeFrameControl)
       
     //Trading time frame
     if (!CloseThisTrade)
        if (UseSsTradingTimeFrameControl)
        {
            if (SsCloseTradesOnColourChange)
               if(SsColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsColour == red)
                     if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsTradingTimeFrameControl)
       
             
   //Opposite FB with no slope
   if (!CloseThisTrade)
      if (CloseOnOppositeFB)
      {
         if (!UseSsHigherTimeFrameControl)
            if (!UseSsMediumTimeFrameControl)
               if (!UseSsTradingTimeFrameControl)
                  if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                     CloseThisTrade = true;
      }//if (CloseOnOppositeFB)
      
   }//if (OrderType() == OP_BUY)
   
   
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT)
   {
      //TP
      if (Bid <= take && !CloseEnough(take, 0) && !CloseEnough(take, OrderTakeProfit()) ) CloseThisTrade = true;
      //SL
      if (Bid >= stop && !CloseEnough(stop, 0)  && !CloseEnough(stop, OrderStopLoss())) CloseThisTrade = true;



      
      //Close trade on opposite direction signal
      if (SellCloseSignal)
         CloseThisTrade = true;

     //Change of SS colour and/or opposite direction FB
     //Higher time frame
     if (!CloseThisTrade)
        if (UseSsHigherTimeFrameControl)
        {
            if (SsCloseTradesOnHtfColourChange)
               if(SsHtfColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnHtfColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsHtfColour == blue)
                     if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsHigherTimeFrameControl)
       
     //Medium time frame
     if (!CloseThisTrade)
        if (UseSsMediumTimeFrameControl)
        {
            if (SsCloseTradesOnMtfColourChange)
               if(SsMtfColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnMtfColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsMtfColour == blue)
                     if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsMediumTimeFrameControl)
       
     //Trading time frame
     if (!CloseThisTrade)
        if (UseSsTradingTimeFrameControl)
        {
            if (SsCloseTradesOnColourChange)
               if(SsColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsColour == blue)
                     if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsTradingTimeFrameControl)


   //Opposite FB with no slope
   if (!CloseThisTrade)
      if (CloseOnOppositeFB)
      {
         if (!UseSsHigherTimeFrameControl)
            if (!UseSsMediumTimeFrameControl)
               if (!UseSsTradingTimeFrameControl)
                  if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                     CloseThisTrade = true;
      }//if (CloseOnOppositeFB)
      
       
   }//if (OrderType() == OP_SELL)

   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (CloseThisTrade)
   {
      bool result = false;
      
      if (OrderType() < 2)//Market orders
         result = CloseOrder(ticket);
      else
         result = OrderDelete(ticket, clrNONE);
            
      //Actions when trade close succeeds
      if (result)
      {
         DeletePendingPriceLines();
         TicketNo = -1;//TicketNo is the most recently trade opened, so this might need editing in a multi-trade EA
         OpenTrades--;//Rather than OpenTrades = 0 to cater for multi-trade EA's
         return(true);//Makes CountOpenTrades increment cc to avoid missing out ccounting a trade
      }//if (result)
   
      //Actions when trade close fails
      if (!result)
      {
         return(false);//Do not increment cc
      }//if (!result)
   }//if (CloseThisTrade)
   
   //Got this far, so no trade closure
   return(false);//Do not increment cc
   
}//End bool LookForTradeClosure()
Author:  SteveHopwood [ Wed Mar 08, 2017 2:34 pm ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

If you want to stop SuperSlope confusing the picture with its own arrows on the chart:
  • load the indi into the editor.
  • go to line 768 and create a blank line so that 768 becomes 769.
  • type <return;> without the <> at 768.
  • F7 to compile.
:xm:
Author:  TraderJoeForex [ Wed Mar 08, 2017 3:06 pm ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

Cheers Steve. I appreciate your time on this :good:
Author:  cozybooks [ Wed Mar 08, 2017 3:32 pm ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

Steve and TraderJoeForex, what great contributions! :clap: :party: :yahoo:

I am letting this run on a 4-hour TF with the weekly superslope set to 5 periods as the filter with all of the majors except CHF and CAD, which magically take money out of my account whenever I trade them. :roll:

I'm having it close the trades on the opposite FB, so I'll report back on how this works out over time.

The closing on the opposite FB using the 4-hour TF gives me a great system for being miserably stuck in the U.S. (FIFO, NO HEDGING, NO Global Prime and we won't even mention the current President or his orange hair - what more could you ask for!)

Thanks again!! You guys are all superstars!!! :hi: :hi: :cheer: :smile: :party: :clap: :xm:
Author:  SteveHopwood [ Thu Mar 09, 2017 11:44 am ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

cozybooks » Wed Mar 08, 2017 3:32 pm wrote:(..... and we won't even mention the current President or his orange hair - what more could you ask for!)
A paraphrased quip from a satirical, topical news quiz here in the UK:
"America has provided two coloured firsts. First black president. First orange president." :clap: :clap: :clap:

:xm:
Author:  SteveHopwood [ Thu Mar 09, 2017 5:44 pm ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

V 1c is in post 1.

I arrived home to some incorrectly closed trades, all sells - which pointed my nose in the right direction.

DIYers, easiest is to copy the entire bool LookForTradeClosure(int ticket) over the top of the existing function:

Code: Select all

bool LookForTradeClosure(int ticket)
{
   //Close the trade if the close conditions are met.
   //Called from within CountOpenTrades(). Returns true if a close is needed and succeeds, so that COT can increment cc,
   //else returns false
   
   if (!BetterOrderSelect(ticket, SELECT_BY_TICKET) ) return(true);
   if (BetterOrderSelect(ticket, SELECT_BY_TICKET) && OrderCloseTime() > 0) return(true);
   
   bool CloseThisTrade = false;
   
   string LineName = TpPrefix + DoubleToStr(ticket, 0);
   //Work with the lines on the chart that represent the hidden tp/sl
   double take = ObjectGet(LineName, OBJPROP_PRICE1);
   if (CloseEnough(take, 0) ) take = OrderTakeProfit();
   LineName = SlPrefix + DoubleToStr(ticket, 0);
   double stop = ObjectGet(LineName, OBJPROP_PRICE1);
   if (CloseEnough(stop, 0) ) stop = OrderStopLoss();
   
   
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP || OrderType() == OP_BUYLIMIT)
   {
      //TP
      if (Bid >= take && !CloseEnough(take, 0) && !CloseEnough(take, OrderTakeProfit()) ) CloseThisTrade = true;
      //SL
      if (Bid <= stop && !CloseEnough(stop, 0)  && !CloseEnough(stop, OrderStopLoss())) CloseThisTrade = true;

      
      //Close trade on opposite direction signal
      if (BuyCloseSignal)
         CloseThisTrade = true;

      
      //Delete pendings on a new signal.
      //You may need to make changes here.
      if (!CloseThisTrade)
        if (SellSignal)
            if (DeletePendingsOnNewSignal)
               if (MarketTradesTotal == 0)
                  CloseThisTrade = true;
   
      
     //Change of SS colour and/or opposite direction FB
     //Higher time frame
     if (!CloseThisTrade)
        if (UseSsHigherTimeFrameControl)
        {
            if (SsCloseTradesOnHtfColourChange)
               if(SsHtfColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnHtfColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsHtfColour == red)
                     if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsHigherTimeFrameControl)
       
     //Medium time frame
     if (!CloseThisTrade)
        if (UseSsMediumTimeFrameControl)
        {
            if (SsCloseTradesOnMtfColourChange)
               if(SsMtfColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnMtfColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsMtfColour == red)
                     if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsMediumTimeFrameControl)
       
     //Trading time frame
     if (!CloseThisTrade)
        if (UseSsTradingTimeFrameControl)
        {
            if (SsCloseTradesOnColourChange)
               if(SsColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsColour == red)
                     if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsTradingTimeFrameControl)
       
             
   //Opposite FB with no slope
   if (!CloseThisTrade)
      if (CloseOnOppositeFB)
      {
         if (!UseSsHigherTimeFrameControl || !SsCloseTradesOnHtfColourChange)
            if (!UseSsMediumTimeFrameControl || !SsCloseTradesOnMtfColourChange)
               if (!UseSsTradingTimeFrameControl || !SsCloseTradesOnColourChange)
                  if(!OnlyCloseWhenSuperSlopeAgrees)
                     if (FbStatus == fbdownarrowtradable || FbStatus == fbdownarrowuntradable)
                        CloseThisTrade = true;
      }//if (CloseOnOppositeFB)
      
   }//if (OrderType() == OP_BUY)
   
   
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP || OrderType() == OP_SELLLIMIT)
   {
      //TP
      if (Bid <= take && !CloseEnough(take, 0) && !CloseEnough(take, OrderTakeProfit()) ) CloseThisTrade = true;
      //SL
      if (Bid >= stop && !CloseEnough(stop, 0)  && !CloseEnough(stop, OrderStopLoss())) CloseThisTrade = true;



      
      //Close trade on opposite direction signal
      if (SellCloseSignal)
         CloseThisTrade = true;

     //Change of SS colour and/or opposite direction FB
     //Higher time frame
     if (!CloseThisTrade)
        if (UseSsHigherTimeFrameControl)
        {
            if (SsCloseTradesOnHtfColourChange)
               if(SsHtfColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnHtfColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsHtfColour == blue)
                     if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsHigherTimeFrameControl)
       
     //Medium time frame
     if (!CloseThisTrade)
        if (UseSsMediumTimeFrameControl)
        {
            if (SsCloseTradesOnMtfColourChange)
               if(SsMtfColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnMtfColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsMtfColour == blue)
                     if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsMediumTimeFrameControl)
       
     //Trading time frame
     if (!CloseThisTrade)
        if (UseSsTradingTimeFrameControl)
        {
            if (SsCloseTradesOnColourChange)
               if(SsColour != blue)
                  CloseThisTrade = true;              
        
            //Opposite FB signal
            if (!CloseThisTrade)
               if (SsCloseTradesOnColourChange)
                  if (!OnlyCloseWhenSuperSlopeAgrees || SsColour == blue)
                     if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
                        CloseThisTrade = true;
        }//if (UseSsTradingTimeFrameControl)


   //Opposite FB with no slope
   if (!CloseThisTrade)
      if (CloseOnOppositeFB)
      {
         if (!UseSsHigherTimeFrameControl || !SsCloseTradesOnHtfColourChange)
            if (!UseSsMediumTimeFrameControl || !SsCloseTradesOnMtfColourChange)
               if (!UseSsTradingTimeFrameControl || !SsCloseTradesOnColourChange)
                  if(!OnlyCloseWhenSuperSlopeAgrees)
                     if (FbStatus == fbuparrowtradable || FbStatus == fbuparrowuntradable)
                        CloseThisTrade = true;
      }//if (CloseOnOppositeFB)
       
   }//if (OrderType() == OP_SELL)

   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (CloseThisTrade)
   {
      bool result = false;
      
      if (OrderType() < 2)//Market orders
         result = CloseOrder(ticket);
      else
         result = OrderDelete(ticket, clrNONE);
            
      //Actions when trade close succeeds
      if (result)
      {
         DeletePendingPriceLines();
         TicketNo = -1;//TicketNo is the most recently trade opened, so this might need editing in a multi-trade EA
         OpenTrades--;//Rather than OpenTrades = 0 to cater for multi-trade EA's
         return(true);//Makes CountOpenTrades increment cc to avoid missing out ccounting a trade
      }//if (result)
   
      //Actions when trade close fails
      if (!result)
      {
         return(false);//Do not increment cc
      }//if (!result)
   }//if (CloseThisTrade)
   
   //Got this far, so no trade closure
   return(false);//Do not increment cc
   
}//End bool LookForTradeClosure()
It is looking good for this bot once I iron out the wrinkles.

:xm:
Author:  TraderJoeForex [ Thu Mar 09, 2017 11:57 pm ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

Just sharing the set file I am now using to test on H1 using Peak High Low, D1 Superslope and grid for entries. On paper it's a strong combo so lets see :youknow:
Author:  SteveHopwood [ Fri Mar 10, 2017 10:02 am ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

alexandertlh80 » Fri Mar 10, 2017 9:40 am wrote:Hi Steve/All contributors,

Firstly, thanks for a great EA here which i think truly has potential.

One thing i would like to highlight, the EA is calculating pips wrongly on 4 digit brokers. Pls do see attach picture. Spread shown is 0.3pips. The actual spread is 3 pips. Thanks.

Change your broker.

:xm:
Author:  SteveHopwood [ Mon Mar 13, 2017 5:04 pm ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

Latest version is in post 1. There is no need to download it if you already have the existing working version.

Explanation at http://www.stevehopwoodforex.com/phpBB3 ... 50#p152650

:xm:
Author:  SteveHopwood [ Wed Mar 15, 2017 10:31 am ]
Post subject:  Holy Graily Bob 'n Dotty 'n Super Slope 'n Flying Buddha

I have updated the core library at http://www.stevehopwoodforex.com/phpBB3 ... =87&t=5077 to fix a teensy logic flaw that has been there unnoticed throughout all the development of the Dotty family.

I noticed HGBnDnSS sending a grid of pending orders that I did not want - UseGrid = false. The pendings were created because of the FillInGaps input, which I had left set to 'true'.

DIYers, the fix is easy. In both the core library and the original HGBnDnFB that many of us still have on our demos, do a search for this string, without the quotes: "//Has the market moved far enough away from the grid to demand another trade be sent?"

It is line 8612 in the original bot and 7625 in the library. You will see these two blocks of code:

Code: Select all

   //Has the market moved far enough away from the grid to demand another trade be sent?
   if (OpenTrades > 0)
      if (FillInGaps)
         CanWeAddAnotherPendingTrade();
   
     
   //Make sure that the grids on every side have GridSize
   TrimTheGrids();


We need a couple of extra conditionals, so copy this over the top of the existing blocks:

Code: Select all

   //Has the market moved far enough away from the grid to demand another trade be sent?
   if (OpenTrades > 0)
      if (UseOffsetting)
         if (FillInGaps)
            CanWeAddAnotherPendingTrade();
      
   //Make sure that the grids on every side have GridSize
   if (UseGrid)
      TrimTheGrids();
Remember to click Save for the library not compile - .mqh files do not compile until combined with the shell. You will get a fright if you forget - try it for fun as you cannot do any harm.

:xm:
All times are UTC Page 2 of 33