enterLong() behaviour with Entry

Posted By: kerplunk1899

enterLong() behaviour with Entry - 01/08/19 15:52

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!




Posted By: Brax

Re: enterLong() behaviour with Entry - 01/08/19 18:34

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.
Posted By: OptimusPrime

Re: enterLong() behaviour with Entry - 01/08/19 20:15

If you still have difficulty, post your script.

The example you gave will always open a Long position whenever there is none open.
Posted By: kerplunk1899

Re: enterLong() behaviour with Entry - 01/09/19 21:38

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.
Posted By: Brax

Re: enterLong() behaviour with Entry - 01/10/19 16:44

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.
© 2024 lite-C Forums