Reply

Time and Day of Week

1 replies

jdowney

Customer, bbp_participant, community, 12 replies.

Visit profile

10 years ago #111930

Hi All.

 

Can anyone help with this condition that I am tyring to do.

I would like to do the following

If Day is Tuesday and time is between 14:00 and 15:00 close all trades and not place any trades during this time on Tuesday between the hours of 14:00 and 15:00.

 

So Far I have got the following and cannot get the condition to work it still places trades Hhmm.

 

  }
   //————————————–
   // Rule 3
   if (((TimeDayOfWeek(Time[0]) == 2)
      && ((TimeHour(Time[0]) >= 14)
      && (TimeHour(Time[0]) <= 15))))
   {
      // Action #1
       sqCloseAllOrders();

      // Action #2
       // do nothing
   }

   return(0);
}

//+——————————————————————+
 

 

 

 

 

END IF;

//——————————————————————–
// Rule 3

IF (((DayOfWeek[0] = _CONSTANT_)
      And ((Hour[0] >= 14)
      And (Hour[0] <= 15))))
THEN
   // Action #1
      Close all orders;

   // Action #2
   Do Nothing

END IF;
 

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

10 years ago #123568

can you post your .sqw file here? It will be easier to check that.

Mark
StrategyQuant architect

0

jdowney

Customer, bbp_participant, community, 12 replies.

Visit profile

10 years ago #123577

can you post your .sqw file here? It will be easier to check that.

Thanks Mark,

Attached is .SQW file and chart from MT4. Please note that I am using current symbol and Timeframe in the .sqw file but I use the 15m chart on the GBPCAD Symbol.

0

jdowney

Customer, bbp_participant, community, 12 replies.

Visit profile

10 years ago #123578

Hi Mark

 

Screen shot attached.

 

Regards John.

0

jimasks

Customer, bbp_participant, community, 45 replies.

Visit profile

10 years ago #123588

Sorry for jumping in on this discussion, but I think this will do what you want. 

 

1. I put the test to close in the first tab. This way any trades that were open are closed at the time you want.

2. I added some code to allow trading on the other two tabs that will exclude the time/date you wanted. 

 

I didn’t test it, but one needs to be careful of the Tuesday at 14 hr. I think I got it built so there is no conflict between a possible open and close time. 

 

For example: the close all tab will only operate starting Tuesday at 1400 and quit just before Tuesday 1500. Then the EA can open trades anytime up until Tuesday 1400 and start allowing opening trades at Tuesday 1500. 

 

Check my work and see if it operates the way you would like.

 

Hope this helps.

 

Jim

 

PS. I think this could be generalized easily from the input parameters if one wanted. 

0

jdowney

Customer, bbp_participant, community, 12 replies.

Visit profile

10 years ago #123596

Hi Jim

Thanks it works exactly the way I wanted.

 

I presume I still need the first tab to close any orders that might open, am I correct? Once again Thank You much appreciated.

Regards John.

// CloseAllonTimeDate

IF (((DayOfWeek[0] = _CONSTANT_)
      And ((Hour[0] >= 14)
      And (Hour[0] < 15))))
THEN
   // Action #1
      Close all orders;

   // Action #2
   Do Nothing

END IF;
 

0

jimasks

Customer, bbp_participant, community, 45 replies.

Visit profile

10 years ago #123604

Not a problem jdoweny,

 

and yes you will still need to the first tab to close trades during that time period. You should check to see if it closes all trades or if it closes all trades with the given symbol.  I didn’t look, but I think the close all orders will only operate on the trades that are open with the chart symbol… but I am not sure. 

0

Viewing 6 replies - 1 through 6 (of 6 total)