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

GU H1 high/low entry system?
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4702
Page 4 of 9
Author:  themaxx [ Mon May 16, 2016 3:38 pm ]
Post subject:  GU H1 high/low entry system?

SteveHopwood » Sun May 15, 2016 3:15 pm wrote:V 1a is in post 1.

Master bloop spotter dydynamic spotted a mass of bloops :clap: :clap: :clap: :clap: that would have come to light as soon as anyone used tnavi's filter of enabled any of the others. In putting those right I spotted a few more as well that may have had some effect a little further down the line.

:xm:
Thanks Steve, much appreciated!
Author:  sudhindragk [ Mon May 16, 2016 6:03 pm ]
Post subject:  GU H1 high/low entry system?

I will send my 25 to Steve as a token of appreciation for all his hard work.
Author:  SteveHopwood [ Mon May 16, 2016 6:10 pm ]
Post subject:  GU H1 high/low entry system?

sudhindragk » Mon May 16, 2016 6:03 pm wrote:I will send my 25 to Steve as a token of appreciation for all his hard work.
That is most generous of you. Thank you.

:xm:
Author:  SteveHopwood [ Mon May 16, 2016 6:44 pm ]
Post subject:  GU H1 high/low entry system?

Please read my "Edit 16th May 2016" section in post 1.

:xm:
Author:  themaxx [ Tue May 17, 2016 7:22 am ]
Post subject:  GU H1 high/low entry system?

SteveHopwood » Mon May 16, 2016 6:44 pm wrote:Please read my "Edit 16th May 2016" section in post 1.

:xm:
Hi Steve

Thanks for taking the time to code this, I really appreciate it. I threw the EA up on GBPUSD and USDCAD when I got home from work, and it took a few trades all according to plan. This morning however, it entered the standard 8am long/short on GBP, but on CAD it only entered the long, missing the short. I got a few pop up errors - my journal is attached in text format.

My immediate thought was that the market had moved too much between 8:00:00 and 8:00:01, but looking at the chart that was not the case. Any idea why this happened?

I was thinking, would you be able to change the EA so that if a pending is too close to trigger, it just enters a market order? Understand if it's too late to add this in as it was not part of the original spec.

Thanks
Author:  SteveHopwood [ Tue May 17, 2016 11:31 am ]
Post subject:  GU H1 high/low entry system?

themaxx » Tue May 17, 2016 7:22 am wrote: Hi Steve

Thanks for taking the time to code this, I really appreciate it. I threw the EA up on GBPUSD and USDCAD when I got home from work, and it took a few trades all according to plan. This morning however, it entered the standard 8am long/short on GBP, but on CAD it only entered the long, missing the short. I got a few pop up errors - my journal is attached in text format.

My immediate thought was that the market had moved too much between 8:00:00 and 8:00:01, but looking at the chart that was not the case. Any idea why this happened?

I was thinking, would you be able to change the EA so that if a pending is too close to trigger, it just enters a market order? Understand if it's too late to add this in as it was not part of the original spec.

Thanks
The most likely cause is the market being too close to the pending price, so I have added code that tells the bot to send an immediate market trade if we get an error 130. Try this and see how it goes. Looking at the code threw up a few other thingies that needed refining if people are going to try hedging/offsetting.

V 1b of both versions are in post 2.

The easiest way to make your own changes is to copy the whole of LookForTradingOpportunities() over the top of the function, which starts at line 1606:

Code: Select all

void LookForTradingOpportunities()
{


   RefreshRates();
   double take, stop, price;
   int type;
   string stype;//For the alert
   bool SendTrade = false, result = false;
   int err = 0;
   bool s = true;
   bool SendPendingBuyGrid = false, SendPendingSellGrid = false;

   double SendLots = Lot;
   //Check filters
   if (!IsTradingAllowed() ) return;
   
   
   /////////////////////////////////////////////////////////////////////////////////////
   
   //Trading decision.
   bool SendLong = false, SendShort = false;

   //Long trade
   
   //Specific system filters
   if (!BuyOpen)
      if (!BuyStopOpen)
         SendLong = true;
   

   //Usual filters
   if (SendLong)
   {
      //User choice of trade direction
      if (!TradeLong) SendLong = false;

      //tnavi's 4 moving averages filter
      if(UseTnaviMA)
         if(tMaTrend!=up)
            SendLong = false;

      //Bob's 240 H4 ma trend filter
      if (MaPeriod > 0)
         if (MaTrend != up)
            SendLong = false;

      //CSS.         
      if (UseCSS)
      {
         //We are buying the first in the pair ans selling the second, so ensure they are moving in the correct direction and on the right side of 0
         if (CurrDirection1 == downaccelerating || CurrDirection1 == downdecelerating) SendLong = false;
         if (CurrDirection2 == upaccelerating || CurrDirection2 == updecelerating) SendLong = false;
      }//if (UseCSS)
      
      //Other filters
      //Slope must be in the buy area
      if (HtfTimeFrame > 0 && HtfSlopeVal < HtfBuyOnlyLevel) SendLong = false;
      if (LtfTimeFrame > 0 && LtfSlopeVal < LtfBuyOnlyLevel) SendLong = false;
      
      if (UseZeljko && !BalancedPair(OP_BUY) ) SendLong = false;

      if (SendLong)
      { 
         type=OP_BUYSTOP;
         stype = " Buy stop ";
         price = NormalizeDouble(iHigh(Symbol(), TradingTimeFrame, 1) + (HiLoBuffer / factor), Digits);
            
         stop = CalculateStopLoss(OP_BUY, price);
                     
         take = CalculateTakeProfit(OP_BUY, price);
               
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop + (HiddenPips / factor), Digits) );
              
      
          result = SendSingleTrade(Symbol(), type, TradeComment, SendLots, price, stop, take);
          if (result)
          {
               s = OrderSelect(TicketNo, SELECT_BY_TICKET, MODE_TRADES);
               CheckTpSlAreCorrect(type);
               SendTrade = true;//In case of snapshots, or grid trading
               SendPendingBuyGrid = true;//Willo not operate unles user has UseGrid enabled
          }//if (result)
          
          if (!result)
          {
            err=GetLastError();
            if (err == 130)
            {
               price = Ask;
               stop = CalculateStopLoss(OP_BUY, price);                     
               take = CalculateTakeProfit(OP_BUY, price);
               result = SendSingleTrade(Symbol(), OP_BUY, TradeComment, SendLots, price, stop, take);
               if (result)
                  SendTrade = true;//In case of snapshots, or grid trading
            }//if (err == 130)
            else
               OldBarsTime = 0;
          }//if (!result)
            
      }//if (SendLong)
      
   }//if (SendLong)
   
   /////////////////////////////////////////////////////////////////////////////////////

   
   //Short trade
   //Specific system filters
   if (!SellOpen)
      if (!SellStopOpen) 
         SendShort = true;
   
   if (SendShort)
   {      

      //tnavi's 4 moving averages filter
      if(UseTnaviMA)
         if(tMaTrend!=down)
            SendShort = false;

      //User choice of trade direction
      if (!TradeShort) SendShort = false;

      //Other filters
      
      //Bob's 240 H4 ma trend filter
      if (MaPeriod > 0)
         if (MaTrend != down)
            SendShort = false;

      //CSS.         
      if (UseCSS)
      {
         //We are selling the first in the pair ans buying the second, so ensure they are moving in the correct direction and on the right side of 0        
         if (CurrDirection1 == upaccelerating || CurrDirection1 == updecelerating) SendShort = false;
         if (CurrDirection2 == downaccelerating || CurrDirection2 == downdecelerating) SendShort = false;
      }//if (UseCSS)

      //Slope must be in the sell area
      if (HtfTimeFrame > 0 && HtfSlopeVal > HtfSellOnlyLevel) SendShort = false;
      if (LtfTimeFrame > 0 && LtfSlopeVal > LtfSellOnlyLevel) SendShort = false;
      
      if (UseZeljko && !BalancedPair(OP_SELL) ) SendShort = false;
      
      if (SendShort)
      { 
          
         type=OP_SELLSTOP;
         stype = " Sell stop ";
         price = NormalizeDouble(iLow(Symbol(), TradingTimeFrame, 1) - (HiLoBuffer / factor), Digits);
            
         stop = CalculateStopLoss(OP_SELL, price);
                     
         take = CalculateTakeProfit(OP_SELL, price);
               
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop - (HiddenPips / factor), Digits) );
              
      
          result = SendSingleTrade(Symbol(), type, TradeComment, SendLots, price, stop, take);
          if (result)
          {
               s = OrderSelect(TicketNo, SELECT_BY_TICKET, MODE_TRADES);
               CheckTpSlAreCorrect(type);
               SendTrade = true;//In case of snapshots, or grid trading
               SendPendingSellGrid = true;//Willo not operate unles user has UseGrid enabled
          }//if (result)
            
          if (!result)
          {
            err=GetLastError();
            if (err == 130)
            {
               price = Ask;
               stop = CalculateStopLoss(OP_BUY, price);                     
               take = CalculateTakeProfit(OP_BUY, price);
               result = SendSingleTrade(Symbol(), OP_BUY, TradeComment, SendLots, price, stop, take);
               if (result)
                  SendTrade = true;//In case of snapshots, or grid trading
            }//if (err == 130)
            else
               OldBarsTime = 0;
          }//if (!result)
      
      
      }//if (SendShort)
      
   }//if (SendShort)
   
     
////////////////////////////////////////////////////////////////////////////////////////
   
  

   if (SendTrade)
   {
      if (TakeSnapshots)
      {
         DisplayUserFeedback();
         TakeChartSnapshot(TicketNo, " open");
      }//if (TakeSnapshots)

      //Are we grid trading?
      if (UseGrid)
      {
         if (SendPendingBuyGrid)
         {
            SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);
            if (UseHedgingWithGrid)
               SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);  
         }//if (SendPendingBuyGrid)
         
         if (SendPendingSellGrid)
         {
            SendSellGrid(Symbol(), OP_SELLSTOP, NormalizeDouble(Bid - (DistanceBetweenTrades / factor), Digits), Lot);    
            if (UseHedgingWithGrid)
               SendBuyGrid(Symbol(), OP_BUYSTOP, NormalizeDouble(Ask + (DistanceBetweenTrades / factor), Digits), Lot);           
         }//if (SendPendingSellGrid)
         
      }//if (UseGrid)
           
      
   }//if (SendTrade)
   
   
   //Actions when trade send fails
   if (SendTrade && !result)
   {
      OldBarsTime = 0;
   }//if (!result)
   
   
   

}//void LookForTradingOpportunities()
:xm:
Author:  themaxx [ Tue May 17, 2016 11:35 am ]
Post subject:  GU H1 high/low entry system?

SteveHopwood » Tue May 17, 2016 11:31 am wrote: The most likely cause is the market being too close to the pending price, so I have added code that tells the bot to send an immediate market trade if we get an error 130. Try this and see how it goes. Looking at the code threw up a few other thingies that needed refining if people are going to try hedging/offsetting.

V 1b of both versions are in post 2.
You're a super star Steve! :!!: :!!: :!!:
Author:  themaxx [ Fri May 20, 2016 6:49 am ]
Post subject:  GU H1 high/low entry system?

Can someone (not Steve as he's probably too busy) help me modify the code of this EA? I've given it a bash as I'm eager to learn, but it's not working...

I've realised that contrary to my spec, 9/10 I'll close my pendings at the end of the day. And the 1/10 isn't that important to the system - it's more important not to have random pending orders at different levels on the chart. I would like to automate it so after trading finishes (10pm) all pendings are deleted, as I plan to run this EA on as many pairs as possible for diversification purposes.

The first thing I did was modify the existing function "ShouldPendingTradesBeMoved()" to a new function that indiscriminately deletes all pendings:

Code: Select all

void PendingTradesShouldBeDeleted()
{
   bool result = false;
    //Buy stop
   if (BuyStopOpen)
      {
         result = OrderDelete(BuyStopTicketNo);
      }//if (result)
             
   //Sell stop
   if (SellStopOpen)
      {
         result = OrderDelete(SellStopTicketNo);
         }//if (result)
}//End //void PendingTradesShouldBeDeleted() 
Then, in "LookForTradingOpportunities()", I replaced the existing line:

Code: Select all

if (!IsTradingAllowed() ) return;
with:

Code: Select all

    if (!IsTradingAllowed() ) 
    {
    PendingTradesShouldBeDeleted();
    return;
    }
But it doesn't seem to work. Could someone point me in the right direction please? My bad code is attached.

Thanks!
Author:  pips400 [ Fri May 20, 2016 7:19 am ]
Post subject:  GU H1 high/low entry system?

Hi themaxx

I haven't looked under the hood of Steve's code, but typically you want to set up a loop to go through all the trades something like this

Code: Select all

void PendingTradesShouldBeDeleted() {
   int TradeIndex; 
   int TotalNumberOfOrders = OrdersTotal();  
   
   for(TradeIndex = TotalNumberOfOrders - 1; TradeIndex >= 0 ; TradeIndex --) 
      {
      if( ! OrderSelect(TradeIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   // <-- if the OrderSelect fails advance the loop to the next TradeIndex
      
      if( OrderSymbol() != Symbol()) continue;   // <-- select only those on the current symbol
                       
         if ( ! OrderDelete( OrderTicket()))     // <-- try to delete the pending order
            Print("Failed to close: ", OrderTicket(), " Error: ", GetLastError() );  // <-- if the Order Delete failed print the error 
         else 
         {
             Print(StringConcatenate(Symbol()," ", OrderTicket(), " Closed")); 
         }
         
      } //  end of For loop
}
I haven't tested it, but it may give you some ideas. :)
Author:  themaxx [ Fri May 20, 2016 9:05 am ]
Post subject:  GU H1 high/low entry system?

pips400 » Fri May 20, 2016 7:19 am wrote:Hi themaxx

I haven't looked under the hood of Steve's code, but typically you want to set up a loop to go through all the trades something like this

Code: Select all

void PendingTradesShouldBeDeleted() {
   int TradeIndex; 
   int TotalNumberOfOrders = OrdersTotal();  
   
   for(TradeIndex = TotalNumberOfOrders - 1; TradeIndex >= 0 ; TradeIndex --) 
      {
      if( ! OrderSelect(TradeIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   // <-- if the OrderSelect fails advance the loop to the next TradeIndex
      
      if( OrderSymbol() != Symbol()) continue;   // <-- select only those on the current symbol
                       
         if ( ! OrderDelete( OrderTicket()))     // <-- try to delete the pending order
            Print("Failed to close: ", OrderTicket(), " Error: ", GetLastError() );  // <-- if the Order Delete failed print the error 
         else 
         {
             Print(StringConcatenate(Symbol()," ", OrderTicket(), " Closed")); 
         }
         
      } //  end of For loop
}
I haven't tested it, but it may give you some ideas. :)
Thanks! Does the way I call the call the function work?
All times are UTC Page 4 of 9