Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Quad, AndrewAMD, Imhotep, TipmyPip, Edgar_Herrera), 809 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Waiting fixed number of bars before next trade #422582
05/13/13 09:24
05/13/13 09:24
Joined: Nov 2012
Posts: 19
Texas, US
D
deweymcg Offline OP
Newbie
deweymcg  Offline OP
Newbie
D

Joined: Nov 2012
Posts: 19
Texas, US
Before entering another trade I want to make sure it has been at least 6 bars since the last trade was opened.

Any suggestions?

Thanks

Re: Waiting fixed number of bars before next trade [Re: deweymcg] #422583
05/13/13 09:46
05/13/13 09:46
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Look in Workshop 4: http://manual.zorro-trader.com/tutorial_trade.htm

There you can see how to make sure it has been at least 3 bars since the last peak or valley before entering another trade. Instead of a peak or valley, use the trade entering itself for setting a signal, and then wait 6 bars instead of 3 after the last signal.

Re: Waiting fixed number of bars before next trade [Re: jcl] #422631
05/13/13 22:07
05/13/13 22:07
Joined: Nov 2012
Posts: 19
Texas, US
D
deweymcg Offline OP
Newbie
deweymcg  Offline OP
Newbie
D

Joined: Nov 2012
Posts: 19
Texas, US
Thanks!

Re: Waiting fixed number of bars before next trade [Re: jcl] #459848
06/08/16 16:55
06/08/16 16:55
Joined: May 2016
Posts: 16
USA
J
JerryS Offline
Newbie
JerryS  Offline
Newbie
J

Joined: May 2016
Posts: 16
USA
I don't see in the code how this makes sure it's been at least 3 bars.

This is the code from the workshop that was referenced:
function run()
{
vars Price = series(price());
vars Trend = series(LowPass(Price,500));

Stop = 4*ATR(100);
if(valley(Trend))
enterLong();
else if(peak(Trend))
enterShort();
}


It doesn't appear that lite-C or Zorro has a function for "bars since" something has occurred. How do we handle this situation?
There are many situations when you would want to test waiting at least one or two bars since some event has occurred.

Re: Waiting fixed number of bars before next trade [Re: JerryS] #459849
06/08/16 17:33
06/08/16 17:33
Joined: May 2016
Posts: 16
USA
J
JerryS Offline
Newbie
JerryS  Offline
Newbie
J

Joined: May 2016
Posts: 16
USA
Each bar i'm using is 30 mins, so I'm trying the following code:

//////-------------MA LINE CROSS CHECK (crossNOW, crossTF)
bool MAcrossOver = MAshort[1] < MAlong[1] and MAshort[0] > MAlong[0];
bool MAcrossUnder = MAshort[1] > MAlong[1] and MAshort[0] < MAlong[0];
bool MAcrossNOW = MAcrossOver or MAcrossUnder;
if (MAcrossNOW){
timer();
}
var nback = 3;
bool MAcrossNOWrecent = timer() < (nback*1800000);

I'm hoping "MAcrossNOWrecent" will tell me if the event (crossing of two MA lines) occurred less than 3 bars ago (1800000 milliseconds *3).

Re: Waiting fixed number of bars before next trade [Re: JerryS] #459858
06/09/16 00:01
06/09/16 00:01
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline
Senior Member
boatman  Offline
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Try this:

Code:
function run()
{
	vars Price = series(price());
	vars maFast = series(SMA(Price, 50));
	vars maSlow = series(SMA(Price, 200));
	
	vars entries = series(0);
	
	if(crossOver(maFast, maSlow))
	{
		entries[0] = 1;
		if(Sum(entries+1, 6) == 0)
			enterLong();
	}
	
	if(crossUnder(maFast, maSlow))
	{
		entries[0] = 1;
		if(Sum(entries+1, 6) == 0)
			enterShort();		
	}
	
}



This script stores each crossing of the moving averages in a series. The current value of the series is 1 if there was a cross, and 0 if there was no cross. We then shift the series backwards by one bar and sum the number of crosses in the previous 6 bars. We shift the series backwards by one bar in order to exclude the current cross from the summation. If we didn't do this, the script would never enter a trade since the if(Sum(...)) statement would always be true.

Hope that helps.

Re: Waiting fixed number of bars before next trade [Re: boatman] #460082
06/15/16 15:56
06/15/16 15:56
Joined: May 2016
Posts: 16
USA
J
JerryS Offline
Newbie
JerryS  Offline
Newbie
J

Joined: May 2016
Posts: 16
USA
Ok after taking a second glance at this, I'm starting to understand it...
At first I didn't realize you were creating a series of zero's... i didn't know that's how you would do that...

Now from your description I understand that:
entries+1 is not simple 1 plus each value in the entries series, but rather something much more like entries[1]. I'm not sure why we don't use entries[1] but that's fine... (that doesn't seem to be accepted)

So this code says: "If it has crossed over in the prior 6 bars, enter long, and if it crossed under in the prior 6 bars, enter short."


And when you said "the if(Sum(...)) statement would always be true" you mean false I believe.

This makes sense, thank you!!

Re: Waiting fixed number of bars before next trade [Re: JerryS] #460092
06/16/16 02:56
06/16/16 02:56
Joined: Apr 2014
Posts: 482
Sydney, Australia
B
boatman Offline
Senior Member
boatman  Offline
Senior Member
B

Joined: Apr 2014
Posts: 482
Sydney, Australia
Yes, I meant "false" - sorry about that.

Just to clarify, entries[1] is not the same as entries+1. The former is the value of the next-to-last index of the entries series. The latter is the entries series shifted backwards by 1 bar. That is, the former is a single value, the latter is an entire series.

Also, the code says "If it crossed over at the last bar and it HASN'T crossed over OR UNDER in the prior 6 bars, enter long, and if it crossed under at the last bar and HASN'T crossed under OR OVER in the prior 6 bars, enter short."

Hope that helps


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