| / | Forum |
|
Embstj
2007.05.14 09:02
Hello-
I just wanted to know if someone could help me think of a paticular line of code. All I want it to be is very simple- if(Current server time is == to Midnight) The point of it, is that I have it set up that when midnight starts- it begins to look for a possibility to open. Once it makes a trade- it stops looking to open, and starts checking the time again until it hits midnight, and it repeats the process. This way it makes only one trade per day- which is what I want. Since the EA trades off the Daily chart...I want to avoid possible whipsaws. I have it trading 1 lot in multple currencies a day rather then mutliple trades in just one currency. That's all I wanted. Sadly I have tried like 50 datetime combinations, and I can't figure out how to write a simple string above. If someone could help, it would be very thankful...as this is the last piece of code I need to solve in order for my EA to be completly bug-free. If you can make a code that will also be able to work in the strategy tester too (as the stragety tester is quite fishy regarding time): That would be very cool, but I don't really need it. I like just testing it with a practice account anyways. Thanks, -J |
|
The article describes construction of fractal lines of various types using trend lines and fractals. |
33780 |
Rosh
2007.05.14 10:39
It's very easy, like this
if (TimeHour()TimeCurrent()==0 && OrdersTotal()==0) { // check conditions and try to open trades } |
|
Raider
2007.05.14 11:41
Hi Embstj,
Good question - this one is trickier than it looks. Server time "TimeCurrent()" relies on the timestamp of the last incoming tick. If you are on a M1 or M5 chart with a low-volume currency pair, you can't assume that there will be a tick at exactly midnight. No tick at exactly midnight means that the "current server time == midnight" logic won't be triggered. I think a better approach is to look for the first tick that crosses into the midnight hour, like this: if(TimeHour(Time[i+1])>=20 && TimeHour(Time[i])==0)This statement will consistently catch the midnight tick, or if a midnight tick doesn't exist, the first tick after midnight for every timeframe, M1 thru H4. For an idea of use, take a look at the example below....quick and dirty, using the MT ATR as a starting point. It puts a red star on the midnight tick. Cheers, Raider //+------------------------------------------------------------------+ //| ClaptonATR.mq4 | //| Copyright © 2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, MetaQuotes Software Corp." #property link "http://www.metaquotes.net/" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 DodgerBlue #property indicator_width3 3 #property indicator_color3 Red //---- input parameters extern int AtrPeriod=14; //---- buffers double AtrBuffer[]; double TempBuffer[]; double MidniteBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- 1 additional buffer used for counting. IndicatorBuffers(3); //---- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,AtrBuffer); SetIndexBuffer(1,TempBuffer); //---- name for DataWindow and indicator subwindow label short_name="Clapton ATR("+AtrPeriod+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); //---- SetIndexDrawBegin(0,AtrPeriod); //---- SetIndexBuffer(2,MidniteBuffer); SetIndexStyle(2,DRAW_ARROW); SetIndexLabel(2,"Midnite!"); SetIndexArrow(2,182); return(0); } //+------------------------------------------------------------------+ //| Average True Range | //+------------------------------------------------------------------+ int start() { int i,counted_bars=IndicatorCounted(); //---- if(Bars<=AtrPeriod) return(0); //---- initial zero if(counted_bars<1) for(i=1;i<=AtrPeriod;i++) AtrBuffer[Bars-i]=0.0; //---- i=Bars-counted_bars-1; while(i>=0) { double high=High[i]; double low =Low[i]; if(i==Bars-1) TempBuffer[i]=high-low; else { double prevclose=Close[i+1]; TempBuffer[i]=MathMax(high,prevclose)-MathMin(low,prevclose); } i--; } //---- if(counted_bars>0) counted_bars--; int limit=Bars-counted_bars; for(i=0; i<limit; i++) { AtrBuffer[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod,0,MODE_SMA,i); } //---- for(i=0; i<limit; i++) { if(TimeHour(Time[i+1])>=20 && TimeHour(Time[i])==0) MidniteBuffer[i]=AtrBuffer[i]+(Point*3); } return(0); } //+------------------------------------------------------------------+ |
|
Raider
2007.05.14 12:19
Update:
I got to wondering about super-low volume currency pairs...see USDZAR for an example. There are actually instances where there are no ticks for the entire midnight hour, in which case, the example that I posted would miss the first tick at or past midnight. An even more solid method would be: if(TimeHour(Time[i+1])>=12 && TimeHour(Time[i])<12)This statement will pull the first tick at or past midnight (if no midnight tick). .....unless your currency pair goes more than 12 hours without a tick! If that's the case, you'll need more help than I can give.... Cheers, Raider |
|
Embstj
2007.05.15 02:53
Raider wrote: I understand exactly what your saying, but what should 'i' be in this circumstance?Update: I got to wondering about super-low volume currency pairs...see USDZAR for an example. There are actually instances where there are no ticks for the entire midnight hour, in which case, the example that I posted would miss the first tick at or past midnight. An even more solid method would be: if(TimeHour(Time[i+1])>=12 && TimeHour(Time[i])<12)This statement will pull the first tick at or past midnight (if no midnight tick). .....unless your currency pair goes more than 12 hours without a tick! If that's the case, you'll need more help than I can give.... Cheers, Raider Remember that this is a EA, and not a indicator. |
|
Raider
2007.05.16 07:44
The "i" value would be the number of the bar that you are currently evaluating.
|