|
|
How avoid trading specific asset at certain times
#466745
06/30/17 13:26
06/30/17 13:26
|
Joined: Feb 2017
Posts: 369
Dalla
OP
Senior Member
|
OP
Senior Member
Joined: Feb 2017
Posts: 369
|
Hi, My scenario is this: I have a multi asset strategy, using a trade loop like so
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
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: GreenBoat]
#466779
07/02/17 06:52
07/02/17 06:52
|
Joined: Feb 2017
Posts: 369
Dalla
OP
Senior Member
|
OP
Senior Member
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?
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
Dalla
OP
Senior Member
|
OP
Senior Member
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)
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: jcl]
#466803
07/03/17 10:50
07/03/17 10:50
|
Joined: Feb 2017
Posts: 369
Dalla
OP
Senior Member
|
OP
Senior Member
Joined: Feb 2017
Posts: 369
|
OK, so rather than doing what I did above, I would do something like
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

Chief Engineer
|

Chief Engineer
Joined: Jul 2000
Posts: 27,935
Frankfurt
|
|
|
|
|