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

Holy Graily Bob and his Ma, in a Hedge
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4619
Page 2 of 4
Author:  ForexFox [ Thu Mar 03, 2016 9:53 am ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

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.
Author:  patmontes [ Fri Mar 04, 2016 1:31 am ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

Hi Steve
We need to put // as well on line 2110 here for this version?
Author:  SteveHopwood [ Fri Mar 04, 2016 11:10 am ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

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:
Author:  patmontes [ Fri Mar 04, 2016 5:31 pm ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

Ok thanks Steve!
Author:  SteveHopwood [ Sat Mar 05, 2016 1:00 pm ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

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:
Author:  SteveHopwood [ Sat Mar 05, 2016 2:14 pm ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

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:
Author:  patmontes [ Sun Mar 06, 2016 2:55 am ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

thank you Steve!!
Author:  SteveHopwood [ Sun Mar 06, 2016 7:43 pm ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

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:
Author:  patmontes [ Mon Mar 07, 2016 3:06 am ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

I also applied this here

Code: Select all

if (ArraySize(FifoTicket) > 0)
         ArraySort(FifoTicket, WHOLE_ARRAY, 0, MODE_DESCEND);
Author:  SteveHopwood [ Mon Mar 07, 2016 9:50 am ]
Post subject:  Holy Graily Bob and his Ma, in a Hedge

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:
All times are UTC Page 2 of 4