Holy Graily Bob and his Ma, in a Hedge

EA's inspired by nanningbob's work here, especially those based on his 240 Moving Average trend detection filter.
ForexFox
Posts: 5
Joined: Tue Oct 28, 2014 1:12 pm

Holy Graily Bob and his Ma, in a Hedge

Post by ForexFox »

Excuse me.
I don't know it's normal or weird, just said something I have seen.
When there's only one side like buy trades filled on chart.
If high semafor happened, then EA will close all trades then replace new buy and sell grids.
This situation is normal as EA should done.

But if there are both buy and sell trades filled on chart.
Then when high semafor happened, EA will closed all trades but exclude the opened sell trades.
It will leave the sell trades still opened alone without replacing new buy and sell stop order grids.
This situation is what I have seen in M15 chart on demo account.
Could anyone tell me it's normal or not?
Hope my question is not too dumb.

Regards.
User avatar
patmontes
Trader
Posts: 367
Joined: Wed Apr 23, 2014 10:42 pm

Holy Graily Bob and his Ma, in a Hedge

Post by patmontes »

Hi Steve
We need to put // as well on line 2110 here for this version?
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Holy Graily Bob and his Ma, in a Hedge

Post by SteveHopwood »

patmontes » Fri Mar 04, 2016 1:31 am wrote:Hi Steve
We need to put // as well on line 2110 here for this version?
No, you don't. This is the code snippet:

Code: Select all

   if (!BuyOpen)
      if (!SellOpen)
         SemStatus = "No open trades, so not reading the 3 level indi to lower the pressure on the cpu";
BuyOpen is a boolean set to 'true' if CountOpenTrades() finds a market buy trade. Ditto SellOpen for market sells.

if (!BuyOpen) is saying, "Only execute the next line of code in this block if there are no market buys open. The "!" means "Is not true". A more easily understood code equivalent is:
if (BuyOpen == false).

If there are market buys, then the ea executes line 2 of this code, and aborts the snippet if there are market sells open. Line 3 is only reached if lines 1 & 2 both pass the test of there being no market trades.

:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
patmontes
Trader
Posts: 367
Joined: Wed Apr 23, 2014 10:42 pm

Holy Graily Bob and his Ma, in a Hedge

Post by patmontes »

Ok thanks Steve!
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Holy Graily Bob and his Ma, in a Hedge

Post by SteveHopwood »

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

V 1d 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 2117 - just one line different to its equivalent in HGB'nG.
if (OldM1SemTime != iTime(Symbol(), TradingTimeFrame, 0))

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

then replace TradingTimeFrame with PERIOD_M1 in line 2119 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:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Holy Graily Bob and his Ma, in a Hedge

Post by SteveHopwood »

Very happy with the bot's progress this week.
Ma.png
Floating is a UC hedged position.

$5,000 starting balance, trading the biggies + GJ, 0.05 lot sizes.

:xm:
You do not have the required permissions to view the files attached to this post.
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
patmontes
Trader
Posts: 367
Joined: Wed Apr 23, 2014 10:42 pm

Holy Graily Bob and his Ma, in a Hedge

Post by patmontes »

thank you Steve!!
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Holy Graily Bob and his Ma, in a Hedge

Post by SteveHopwood »

V 1e is in post 1, incorporating the relevant changes provided by Keving for HGB'nG.

To make your own change, go to line 4550 and copy this over the top of the entire function:

Code: Select all

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

   int tries = 0;
   bool ClosePosition = false;
      
   //Semafor
   //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
                  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);
                  
                  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 || SellPipsUpl > 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 grids
                  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);
                        
                  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 (!ClosePosition)
      if (Hedged)
      {
         
         //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 (Hedged)
         
   if (ClosePosition)
   {
      tries = 0;
      ForceTradeClosure = true;
      while(ForceTradeClosure)
      {
         ForceTradeClosure = false;
         //All of these can be replaced by CloseAllTrades(AllTrades)            
         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)
            {
               break;
            }//if (tries >= 100)
      }//while(ForceTradeClosure)
      
   }//if (ClosePosition)
     
}//void ShouldTradesBeClosed()

:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
patmontes
Trader
Posts: 367
Joined: Wed Apr 23, 2014 10:42 pm

Holy Graily Bob and his Ma, in a Hedge

Post by patmontes »

I also applied this here

Code: Select all

if (ArraySize(FifoTicket) > 0)
         ArraySort(FifoTicket, WHOLE_ARRAY, 0, MODE_DESCEND);
User avatar
SteveHopwood
Owner
Posts: 9754
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Holy Graily Bob and his Ma, in a Hedge

Post by SteveHopwood »

patmontes » Mon Mar 07, 2016 3:06 am wrote:I also applied this here

Code: Select all

if (ArraySize(FifoTicket) > 0)
         ArraySort(FifoTicket, WHOLE_ARRAY, 0, MODE_DESCEND);
Nice one Pat. Thanks.

Fix applied to V 1f in post 1. To make your own fix, go to line 3198 and replace the two line snippet with:

Code: Select all

   //Sort ticket numbers for FIFO
   if (ArraySize(FifoTicket) > 0)
      ArraySort(FifoTicket, WHOLE_ARRAY, 0, MODE_DESCEND);
:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. [email protected] is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Post Reply

Return to “Thingy Bob EA's”