How to add delay in Empty4?

Post Reply
dsugums
Trader
Posts: 117
Joined: Mon Jan 30, 2012 9:57 pm

How to add delay in Empty4?

Post by dsugums »

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;
Image
Image
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Re: How to add delay in Empty4?

Post by milanese »

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;
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
dsugums
Trader
Posts: 117
Joined: Mon Jan 30, 2012 9:57 pm

Re: How to add delay in Empty4?

Post by dsugums »

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

Cheers
ds
Image
Image
dsugums
Trader
Posts: 117
Joined: Mon Jan 30, 2012 9:57 pm

Re: How to add delay in Empty4?

Post by dsugums »

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!
Image
Image
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Re: How to add delay in Empty4?

Post by milanese »

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
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
dsugums
Trader
Posts: 117
Joined: Mon Jan 30, 2012 9:57 pm

Re: How to add delay in Empty4?

Post by dsugums »

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.
Image
Image
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Re: How to add delay in Empty4?

Post by milanese »

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
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Re: How to add delay in Empty4?

Post by Radar »

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.
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
User avatar
fxdaytrader
Trader
Posts: 190
Joined: Sun Jun 10, 2012 7:03 am
Location: Poon-Town (germany, se-asia, se-europe) ...

Re: How to add delay in Empty4?

Post by fxdaytrader »

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 :)
Post Reply

Return to “Coders Hangout”