Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
4 registered members (AndrewAMD, fogman, Grant, juanex), 972 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How avoid trading specific asset at certain times #466745
06/30/17 13:26
06/30/17 13:26
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Hi,

My scenario is this: I have a multi asset strategy, using a trade loop like so
Code:
while(asset(loop("EUR/USD","USD/JPY","GBP/USD","GER30"))) {
  ...
}



For GER30, my broker supplies quotes around the clock, but the spread is A LOT higher during off before 6:00 and after 20:00 UTC, so I want to avoid trading those times. What is the best way to achieve this?

I was thinking something like this

Code:
if (Asset == "GER30" && (hour() < 6 || hour() > 19) {
	  //Do nothing
	} else {
		
	if(falling(MMI_Smooth)) {
		if(valley(Trend))
			reverseLong(1, myTMF);
		else if(peak(Trend))
			reverseShort(1, myTMF);
	}
}



This would avoid entering trades during off market hours. However I also use Stops and TMFs to exit trades. Can I avoid triggering those as well (if that makes sense).

Re: How avoid trading specific asset at certain times [Re: Dalla] #466747
06/30/17 14:25
06/30/17 14:25
Joined: Nov 2016
Posts: 66
GreenBoat Offline
Junior Member
GreenBoat  Offline
Junior Member

Joined: Nov 2016
Posts: 66
I guess that TimeFrame and FrameOffset might help you, it's in the manual, page name "BarPeriod, TimeFrame, BarOffset".

Re: How avoid trading specific asset at certain times [Re: GreenBoat] #466779
07/02/17 06:52
07/02/17 06:52
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Hi,

I tried doing this, but it leads to "Inconsistent series!" error.
My script was working perfectly fine before adding this part.
Any ideas?

Code:
static int SkippedBars = 0;	
if(Asset == "GER30") {
  if(between(hour(),MARKETCLOSE,MARKETOPEN-1)) {
       TimeFrame = 0;
       SkippedBars--; // count negative number of bars outside market hours
     } else if(TimeFrame == 0)
       TimeFrame = SkippedBars;
       SkippedBars = 0;
     } else {
        TimeFrame = 1;
     }   
   } else {
     TimeFrame = 1;	
   }


Last edited by Dalla; 07/03/17 05:01.
Re: How avoid trading specific asset at certain times [Re: Dalla] #466795
07/03/17 05:33
07/03/17 05:33
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
It turns out that my Stop is causing the issue. Not sure why though.
If I uncomment this line, my script runs (although with the unwanted side effect that I don't have a Stop anymore)

Code:
Stop = ATR(100) * optimize(0,5,40,5);


Last edited by Dalla; 07/03/17 05:34.
Re: How avoid trading specific asset at certain times [Re: Dalla] #466799
07/03/17 09:29
07/03/17 09:29
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
Both ATR() and optimize() must be called consistently, either always or never. You can skip trading dependent on time, but you cannot skip ATR() and optimize(). - For preventing a stop at night, the only way is handling the stop with a TMF. Otherwise a stop would be always executed since it's an event with high priority.

Re: How avoid trading specific asset at certain times [Re: jcl] #466803
07/03/17 10:50
07/03/17 10:50
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
OK, so rather than doing what I did above, I would do something like

Code:
if(Asset == "GER30" && between(hour(),6,19)) {
	if(falling(MMI_Smooth)) {
		if(valley(Trend))
			reverseLong(1, myTMF);
		else if(peak(Trend))
			reverseShort(1, myTMF);
	}
}



How to handle the stop in TMF?
Can I just check time as above, and return 4 if outside market hours, otherwise 0?

Re: How avoid trading specific asset at certain times [Re: Dalla] #466804
07/03/17 11:14
07/03/17 11:14
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
Yes, that should work.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1