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

How to add delay in Empty4?
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3289
Page 1 of 1
Author:  dsugums [ Wed Nov 27, 2013 12:29 pm ]
Post subject:  How to add delay in Empty4?

I am trying my hand on an EA modification. A bit confused on how to add a delay a trade opening after getting all the conditions true. I have 4h candle closing at 9am with all the conditions fulfilled, but I would like to delay opening the trade at 9.30am.

I am using Steve's shell EA for this experiment. Any help appreciated.

Cheers
ds

Code: Select all

 //Long 
   if (SendLong)
   {
       
      stype = " Buy ";
      price = Ask;//Change this to whatever the price needs to be
         
      if (!SendAlertNotTrade)
      {
         
         
         take = CalculateTakeProfit(OP_BUY);
         
         stop = CalculateStopLoss(OP_BUY);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop, Digits) );

         type = OP_BUY;
         
      }//if (!SendAlertNotTrade)
      
      SendTrade = true;
      
   }//if (SendLong)
   
   //Short
   if (SendShort)
   {
      stype = " Sell ";
      price = Bid;//Change this to whatever the price needs to be

      if (!SendAlertNotTrade)
      {
         
         take = CalculateTakeProfit(OP_SELL);
         
         stop = CalculateStopLoss(OP_SELL);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(NormalizeDouble(stop, Digits), price);
         
         type = OP_SELL;
      }//if (!SendAlertNotTrade)
         
      SendTrade = true;
Author:  milanese [ Wed Nov 27, 2013 12:56 pm ]
Post subject:  Re: How to add delay in Empty4?

dsugums wrote:I am trying my hand on an EA modification. A bit confused on how to add a delay a trade opening after getting all the conditions true. I have 4h candle closing at 9am with all the conditions fulfilled, but I would like to delay opening the trade at 9.30am.

I am using Steve's shell EA for this experiment. Any help appreciated.

Cheers
ds

Code: Select all

 //Long 
   if (SendLong)
   {
       
      stype = " Buy ";
      price = Ask;//Change this to whatever the price needs to be
         
      if (!SendAlertNotTrade)
      {
         
         
         take = CalculateTakeProfit(OP_BUY);
         
         stop = CalculateStopLoss(OP_BUY);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop, Digits) );

         type = OP_BUY;
         
      }//if (!SendAlertNotTrade)
      
      SendTrade = true;
      
   }//if (SendLong)
   
   //Short
   if (SendShort)
   {
      stype = " Sell ";
      price = Bid;//Change this to whatever the price needs to be

      if (!SendAlertNotTrade)
      {
         
         take = CalculateTakeProfit(OP_SELL);
         
         stop = CalculateStopLoss(OP_SELL);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(NormalizeDouble(stop, Digits), price);
         
         type = OP_SELL;
      }//if (!SendAlertNotTrade)
         
      SendTrade = true;
Hi,

you can use the sleep(value_in_ms) command would look like

Code: Select all

 //Long 
   if (SendLong)
   {
       //---- wait for 30 min
      Sleep(1800000);
      stype = " Buy ";
      price = Ask;//Change this to whatever the price needs to be
         
      if (!SendAlertNotTrade)
      {
         
         
         take = CalculateTakeProfit(OP_BUY);
         
         stop = CalculateStopLoss(OP_BUY);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(price, NormalizeDouble(stop, Digits) );

         type = OP_BUY;
         
      }//if (!SendAlertNotTrade)
      
      SendTrade = true;
      
   }//if (SendLong)
   
   //Short
   if (SendShort)
   {
       //---- wait for 30 min
      Sleep(1800000);
      stype = " Sell ";
      price = Bid;//Change this to whatever the price needs to be

      if (!SendAlertNotTrade)
      {
         
         take = CalculateTakeProfit(OP_SELL);
         
         stop = CalculateStopLoss(OP_SELL);
         
         
         //Lot size calculated by risk
         if (RiskPercent > 0) SendLots = CalculateLotSize(NormalizeDouble(stop, Digits), price);
         
         type = OP_SELL;
      }//if (!SendAlertNotTrade)
         
      SendTrade = true;
Author:  dsugums [ Wed Nov 27, 2013 1:16 pm ]
Post subject:  Re: How to add delay in Empty4?

Thanks mate. Will give it a go and see how it behaves!

Cheers
ds
Author:  dsugums [ Thu Nov 28, 2013 5:09 am ]
Post subject:  Re: How to add delay in Empty4?

I have included the sleep function in the EA but not sure it is working. Is there any way to show the counter running once triggered on the chart or alert that the sleep mode activated?

I am concerned now that the sleep mode does not work!
Author:  milanese [ Thu Nov 28, 2013 9:01 am ]
Post subject:  Re: How to add delay in Empty4?

dsugums wrote:I have included the sleep function in the EA but not sure it is working. Is there any way to show the counter running once triggered on the chart or alert that the sleep mode activated?

I am concerned now that the sleep mode does not work!

Hi you could put this before the sleep command

Code: Select all

Alert("Buy/Sell signal I will now wait 30 min before open");


Cheers :)

Tommaso
Author:  dsugums [ Thu Nov 28, 2013 10:37 am ]
Post subject:  Re: How to add delay in Empty4?

Thanks Tomasso. It works now, but I get bombarded with alerts without knowing which pair/chart being triggered! I need to retire from programming, lol. Problems are never ending.
Author:  milanese [ Thu Nov 28, 2013 10:49 am ]
Post subject:  Re: How to add delay in Empty4?

dsugums wrote:Thanks Tomasso. It works now, but I get bombarded with alerts without knowing which pair/chart being triggered! I need to retire from programming, lol. Problems are never ending.
if it works you can comment out the alert code, it was only to proof that it works ;)

Cheers :)

Tommaso
Author:  Radar [ Sat Dec 07, 2013 10:09 pm ]
Post subject:  Re: How to add delay in Empty4?

Hey guys,

Just a thought... Sleep() will work fine in a single-symbol EA, but for multi-symbol, you'd need to set a variable for each symbol's signal that contains the time (say SymbolSignalTime), then, on each loop, subtract SymbolSignalTime from CurrentTime... When it hits 1800000, then send the trade.

I'd have written the code, but I haven't done or looked at any coding for a while, and, as with any new skill that we're learning, if we don't use it, we lose it :(

Have fun!

Radar =8^)

edit
P.S. I just realized you'd need to set a bool, SymbolSignalRecieved... Only check SymboSignalTime when SymbolSignalRecieved is true.
Author:  fxdaytrader [ Wed Dec 11, 2013 6:20 pm ]
Post subject:  Re: How to add delay in Empty4?

that is the point. Also if you are using ordermanagement-functions you may get in trouble if they are not called for 30 minutes or so ...

So I think a quick bool-functions would do the trick, set a globalvar for the pair and if the ea should sleep for that pair you could set the value of the starting time. before an ordersend we could check if the variable exists/is empty and send the order, if there is a time specified we check if current time - time of the var >= sleeping time. if not, we return ...

just a quick thought :)
All times are UTC Page 1 of 1