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
2 registered members (AndrewAMD, Nymphodora), 972 guests, and 8 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
enterLong() behaviour with Entry #475807
01/08/19 15:52
01/08/19 15:52
Joined: Sep 2018
Posts: 29
K
kerplunk1899 Offline OP
Newbie
kerplunk1899  Offline OP
Newbie
K

Joined: Sep 2018
Posts: 29
Hi all,

I am trying to build a simple strategy, but my poor experience with Zorro is getting me stuck with a (I think) simple/stupid issue.

So far in my scripts I have always entered the trades at market.
What I thought I have understood technically is that, in order to get the trade started, the functions enterLong() and enterShort() need to be called only one single time on a single execution of the run()/tick().
And that always worked fine.

What I'm trying to do now, is to enter the trade using Limit orders.
I have tried both Entry and LimitOrders variable, like this:

Code:
if( CONDITION ){
	Entry=x;
	enterLong();
}


The CONDITION I'm putting accurately is TRUE only in one single bar and not in the next ones (at least not in the very next ones), as I have always did in my previous strategies based on market enters.
What I would expect is that whenever the price reaches the x price (before the EntryTime), a trade get started.
But this does not happened. The trades are just never opened.

I have tried to place the enterLong() call after and outside the if condition so that it get "always" executed by the script, and the trades actually take place.

Code:
if (NumOpenTotal < 1)
	enterLong();


This way though, I can hardly control my trades as they get constantly open whenever the price is above x.


This is why I'm pretty sure I haven't quite understood how to use this function properly.

What should I write in order to place a pending order calling a function ONCE? Is it possible or is it just not the way Zorro works?

I really hope anybody can help me!
Thanks so much!





Last edited by kerplunk1899; 01/09/19 19:29.
Re: enterLong() behaviour with Entry [Re: kerplunk1899] #475818
01/08/19 18:34
01/08/19 18:34
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline
Member
Brax  Offline
Member
B

Joined: Aug 2017
Posts: 102
Spain
If you want to only open a stop/limit order in one particular bar, then you can use this:

if(CONDITION)
enterlong(x) //x>0 for a stop order, x<0 for a limit order
else
enterlong() //Whatever your usual entry may be

Entry and LimitOrders are global switches, so you have to change them whenever you don´t need them.

Hope this helps.

Re: enterLong() behaviour with Entry [Re: Brax] #475820
01/08/19 20:15
01/08/19 20:15
Joined: Aug 2018
Posts: 98
O
OptimusPrime Offline
Junior Member
OptimusPrime  Offline
Junior Member
O

Joined: Aug 2018
Posts: 98
If you still have difficulty, post your script.

The example you gave will always open a Long position whenever there is none open.


Thanks so much,

OptimusPrime

Re: enterLong() behaviour with Entry [Re: OptimusPrime] #475839
01/09/19 21:38
01/09/19 21:38
Joined: Sep 2018
Posts: 29
K
kerplunk1899 Offline OP
Newbie
kerplunk1899  Offline OP
Newbie
K

Joined: Sep 2018
Posts: 29
Thank you both.
Probably with a practical example we can understand each other better.

Let's say that I want to build a strategy based on 4Hours bars (Barperiod = 240), that enters a Long Trade whenever the price breaks the highest point of the last 30 bars, from below.
What I would write is this:


Code:
#include <profile.c>


function run(){

StartDate = 2018;
EndDate = 2018;
LookBack = 30;
BarPeriod = 240;
asset("EUR/USD");

var enterPrice = HH(30, 1);
EntryTime = 100;

TakeProfit=70*PIP;
Stop=50*PIP;

	if (enterPrice != Entry){    //whenever a new price is found
		printf("n%d-%d-%d |%d| %d:%d:%.0f", day(), month(), year(), dow(), hour(), minute(), second() );
		printf(" - Enter at %.5f", enterPrice);
		Entry = enterPrice;
		enterLong();
	}

}



What am I doing wrong?
Is this kind of scripting correct for Zorro?

Plus, what if I want to make sure only 1 trade at a time is open?
Usually I put the enterLong() line between an if like this:

Code:
if(NumOpenTotal<1){
	enterLong()
}



But here it doesn't seem to work.

Thanks again so much.

Last edited by kerplunk1899; 01/09/19 21:39.
Re: enterLong() behaviour with Entry [Re: kerplunk1899] #475859
01/10/19 16:44
01/10/19 16:44
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline
Member
Brax  Offline
Member
B

Joined: Aug 2017
Posts: 102
Spain
You must compare your current price with enterprice, you don´t know what value Entry at first may have.

Try it.

Code:
if (enterPrice > Price[0]){		
	Entry = enterPrice;
	enterLong();
}



You can use NumOpenTotal and so on to filter the number of active trades.

Last edited by brax; 01/10/19 16:45.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1