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

Holy Graily Bob's Candle Power
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5272
Page 21 of 36
Author:  tomele [ Mon Oct 09, 2017 9:10 am ]
Post subject:  Holy Graily Bob's Candle Power

Hi.

The immediate close might have to do with SsCloseTradesOnColourChange.
Line 2254 should be: if (SsColour == blue)

EDIT: CP is still closing trades. There must be something else.
Author:  tomele [ Mon Oct 09, 2017 9:50 am ]
Post subject:  Holy Graily Bob's Candle Power

Hi.

Found another reason for closing: MaTrend is an empty string at that moment.

Change line 2205 to: if (MaTrend == down) and line 2260 to: if (MaTrend == up)

EDIT: Although this works, the correct solution is to add "if (UseBobMoving Average) to both blocks.

So the both blocks should be

Code: Select all

         //Change of moving average trend
         if (!CloseThisTrade)
            if (UseBobMovingAverage)
               if (MaCloseTradesOnTrendChange)
                  if (MaTrend == down)
                     CloseThisTrade = true;

         //Change of moving average trend
         if (!CloseThisTrade)
            if (UseBobMovingAverage)
               if (MaCloseTradesOnTrendChange)
                  if (MaTrend == up)
                     CloseThisTrade = true;
Author:  SteveHopwood [ Mon Oct 09, 2017 10:14 am ]
Post subject:  Holy Graily Bob's Candle Power

Thanks Thomas. :clap: :clap: :clap: :clap: :clap: :clap: :clap:

The fix is already in post 1. Thomas led me to the bloop in one of his previous posts. The problem was me forgetting to add a check to the moving average closure block that were are using Bob's moving average.

V 1a for the hoi polloi is in post 1.

For the classy people here, easiest is simply to copy the entire function over the top of the existing one:

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();
   
   //Direction hgi yellow range wave   
   if (HgiCloseOnYellowWavy)
      if (TradeHgiStatus == hgiyellowrangewavey)
         CloseThisTrade = true;
        
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   if (!CloseThisTrade)
   {
      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;
   
         
         
      //Hidden HGI code
      
         //Original Hgi closure
         if (!CloseThisTrade)
            if (CloseOnLargeArrows)
               if (HgiStatus == hgidownarrowtradable)
                  if (!OnlyCloseWinningTrades || (OrderProfit() + OrderCommission() + OrderSwap()) > 0)
                     if (OrderOpenTime() < iTime(Symbol(), HgiTimeFrame, 0) )//Don't close trades opened during the current HGI candle
                        CloseThisTrade = true;
            
         if (!CloseThisTrade)
            if (CloseOnBlueWavy)
               if (HgiStatus == hgibluewavyshort)
                  if (!OnlyCloseWinningTrades || (OrderProfit() + OrderCommission() + OrderSwap()) > 0)
                     if (OrderOpenTime() < iTime(Symbol(), HgiTimeFrame, 0) )//Don't close trades opened during the current HGI candle
                        CloseThisTrade = true;
      
         
         //Opposite direction directional hgi
         if (!CloseThisTrade)
            if (UseHgiTrendFilter)
               if (HgiCloseOnOppositeSignal)
                  if (TradeHgiStatus == hgidownarrowtradable || TradeHgiStatus == hgibluewavyshort)
                     CloseThisTrade = true;
                  
             
         //Change of SS colour
         if (!CloseThisTrade)
            if (UseSuperSlope)
               if (SsCloseTradesOnColourChange)
                  if (SsColour == red)
                     CloseThisTrade = true; 

         //Change of moving average trend
         if (!CloseThisTrade)
            if (UseBobMovingAverage)
               if (MaCloseTradesOnTrendChange)
                  if (MaTrend == down)
                     CloseThisTrade = true;

         //Change of peaky direction
         if (!CloseThisTrade)
            if (UsePeaky)
               if (PeakyCloseTradesOnDirectionChange)
                  if (PeakyStatus == shortdirection)
                     CloseThisTrade = true;

            
      }//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;
   
   
         
         //Original Hgi closure
         if (CloseOnLargeArrows)
            if (HgiStatus == hgiuparrowtradable)
               if (!OnlyCloseWinningTrades || (OrderProfit() + OrderCommission() + OrderSwap()) > 0)
                  if (OrderOpenTime() < iTime(Symbol(), HgiTimeFrame, 0) )//Don't close trades opened during the current HGI candle
                     CloseThisTrade = true;
         
         if (!CloseThisTrade)
            if (CloseOnBlueWavy)
               if (HgiStatus == hgibluewavylong)
                  if (!OnlyCloseWinningTrades || (OrderProfit() + OrderCommission() + OrderSwap()) > 0)
                     if (OrderOpenTime() < iTime(Symbol(), HgiTimeFrame, 0) )//Don't close trades opened during the current HGI candle
                        CloseThisTrade = true;
      
         //Opposite direction directional hgi
         if (!CloseThisTrade)
            if (UseHgiTrendFilter)
               if (HgiCloseOnOppositeSignal)
                  if (TradeHgiStatus == hgiuparrowtradable || TradeHgiStatus == hgibluewavylong)
                     CloseThisTrade = true;

         //Change of SS colour
         if (!CloseThisTrade)
            if (UseSuperSlope)
               if (SsCloseTradesOnColourChange)
                  if (SsColour == blue)
                     CloseThisTrade = true; 

         //Change of moving average trend
         if (!CloseThisTrade)
            if (UseBobMovingAverage)
               if (MaCloseTradesOnTrendChange)
                  if (MaTrend == up)
                     CloseThisTrade = true;

         //Change of peaky direction
         if (!CloseThisTrade)
            if (UsePeaky)
               if (PeakyCloseTradesOnDirectionChange)
                  if (PeakyStatus == longdirection)
                     CloseThisTrade = true;

            
      }//if (OrderType() == OP_SELL)
   }//if (!CloseThisTrade)
   
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////
   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()
Those of you who already made the changes as Thomas posted them, note my changes to the moving average test so that they make more sense:
For buy trades: if (MaTrend == down)
For sell trades: if (MaTrend == up)

Thanks Thomas. You saved me some brain pain this morning. :clap: :clap: :clap: :clap: :clap: :clap: :clap:

:xm:
Author:  Barcode [ Mon Oct 09, 2017 10:59 am ]
Post subject:  Holy Graily Bob's Candle Power

Thanks Thomas / Steve. Looking much better. :clap: :clap:

Bob
Author:  SteveHopwood [ Mon Oct 09, 2017 2:53 pm ]
Post subject:  Holy Graily Bob's Candle Power

Ehu-style dashboard ea for CP and found a bloop in the Peaky code.

Classy people, do a search for "int Highest = iHigh(symbol, tf, bars);"

You will see these two lines of code:
int Highest = iHigh(symbol, tf, bars);
int Lowest = iLow(symbol, tf, bars);

They should be:

int Highest = iHighest(symbol, tf, bars);
int Lowest = iLowest(symbol, tf, bars);

iHigh() returns the high price of the selected candle. iHighest() returns the the shift of the bar with the highest price - this is what we need here.

Update for the peasants in post 1 - still V 1a.

:xm:
Author:  SteveHopwood [ Mon Oct 09, 2017 5:42 pm ]
Post subject:  Holy Graily Bob's Candle Power

I still hadn't quite got those Peaky calls quite right - I left out the mode, which can be to the high or low or open or close prices. Classy people, the code should read:

int Highest = iHighest(symbol, tf, MODE_HIGH, bars);
int Lowest = iLowest(symbol, tf, MODE_LOW, bars);

Codaly challlenged peasants, the fix is in post 1.

:xm:
Author:  wallywonka [ Tue Oct 10, 2017 12:56 am ]
Post subject:  Holy Graily Bob's Candle Power

Seems to be a bug if you remove the HGI direction filter it will take Short/Long trades and wont look at the other filters SS/Peaky etc
Author:  xphoton [ Tue Oct 10, 2017 1:41 am ]
Post subject:  Holy Graily Bob's Candle Power

wallywonka » Tue Oct 10, 2017 8:56 am wrote:Seems to be a bug if you remove the HGI direction filter it will take Short/Long trades and wont look at the other filters SS/Peaky etc
You can comment line 1951~1958 for quick fix.
They will be judged after. The Reserved code has not finished.

Code: Select all

      //Reserved for SuperSlope
         //Reserved for MA
            if (!UseHgiTrendFilter)
            {
               BuySignal = true;
               SellSignal = true;
               BuyCloseSignal = false;
               SellCloseSignal = false;
               return;
            }//if (!UseHgiTrendFilter)
Author:  wallywonka [ Tue Oct 10, 2017 6:09 am ]
Post subject:  Holy Graily Bob's Candle Power

xphoton » Tue Oct 10, 2017 1:41 am wrote:
wallywonka » Tue Oct 10, 2017 8:56 am wrote:Seems to be a bug if you remove the HGI direction filter it will take Short/Long trades and wont look at the other filters SS/Peaky etc
You can comment line 1951~1958 for quick fix.
They will be judged after. The Reserved code has not finished.
That did the trick!
Author:  SteveHopwood [ Tue Oct 10, 2017 9:05 am ]
Post subject:  Holy Graily Bob's Candle Power

xphoton » Tue Oct 10, 2017 1:41 am wrote:
wallywonka » Tue Oct 10, 2017 8:56 am wrote:Seems to be a bug if you remove the HGI direction filter it will take Short/Long trades and wont look at the other filters SS/Peaky etc
You can comment line 1951~1958 for quick fix.
They will be judged after. The Reserved code has not finished.

Code: Select all

      //Reserved for SuperSlope
         //Reserved for MA
            if (!UseHgiTrendFilter)
            {
               BuySignal = true;
               SellSignal = true;
               BuyCloseSignal = false;
               SellCloseSignal = false;
               return;
            }//if (!UseHgiTrendFilter)
Nice spot xphoton. Thanks. :clap: :clap: :clap: :clap: :clap: :clap: :clap:

Most of us have not noticed this because we are using HGI. Classy people, you know what to do. No need to comment it out; just delete it. Slightly unkempt people, your fix is in post 1.

:xm:
All times are UTC Page 21 of 36