Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, TipmyPip, VoroneTZ, Quad, 1 invisible), 688 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
TradeIsEntry appears to always be False #471945
03/27/18 18:51
03/27/18 18:51
Joined: Sep 2017
Posts: 12
T
Trading4pips Offline OP
Newbie
Trading4pips  Offline OP
Newbie
T

Joined: Sep 2017
Posts: 12
I'm trying to use TradeIsEntry (http://zorro-project.com/manual/en/trade.htm) in my script. However, I'm finding it's always false, even after trades have been entered into. I've tested this in 1.74 and the beta (1.80.7)

I found anther script here: http://www.opserver.de/ubb7/ubbthreads.p...true#Post452443 that uses TradeIsEntry where it appears that TradeIsEntry is also not working.

After I've inserted printf statements in the above code (see below), it is showing that TradeIsEntry is always false.

How can I properly use TradeIsEntry such that it returns True?


Code:
#define H1 (60/BarPeriod)
#define H24 (1440/BarPeriod)
#define W1 (7200/BarPeriod)

int myTMF1() {
	if (TradeIsEntry) { 
		AssetVar[2] += 1; 
			if (TradeIsLong) AssetVar[3] += 1;
			if (TradeIsShort) AssetVar[4] += 1;
		printf("A. \nTradeIsEntry: %.5f, AssetVar[2]: %.5f, AssetVar[3]: %.5f, AssetVar[4]: %.5f\n",TradeIsEntry,AssetVar[2],AssetVar[3],AssetVar[4]);

	}
	return 0;
}

int myTMF() { 

	if (TradeIsEntry) {AssetVar[2] = AssetVar[2] + 1; 
		if (TradeIsLong) AssetVar[3] += 1;
		if (TradeIsShort) AssetVar[4] += 1;
	}
	if (TradeIsLong and TradeIsStop and AssetVar[4] < 1){
		enterShort(myTMF);
		printf("\nB. entershort\n");
		
	printf("\nC. TradeIsEntry: %.5f, AssetVar[2]: %.5f, AssetVar[3]: %.5f, AssetVar[4]: %.5f\n",TradeIsEntry,AssetVar[2],AssetVar[3],AssetVar[4]);
	}
	return 0;
	if (TradeIsShort and TradeIsStop and AssetVar[3] < 1) {
		enterLong(myTMF);	
		printf("\nD. entershort\n");
	}	
	return 0;

	return 0;
}

function frameAlign(BOOL Event){ 
	// Let time frame start when Event == true
	// f.i. frameAlign(hour() == 0); aligns to midnight 
	TimeFrame = 1;
	vars Num = series(0); // use a series for storing Num between calls
	Num[0] = Num[1]+1;    // count Num up once per bar  
	if(!Event) 
	TimeFrame = 0;      // continue current time frame  
	else {
		TimeFrame = -Num[0]; // start a new time frame
		Num[0] = 0;          // reset the counter  
	}
}

function run() {
	set(TICKS|PARAMETERS|FACTORS|LOGFILE); 
	Weekend = 3; // don't run TMF at weekend
	StartDate = 20140901;
	EndDate = 20141231; //preserve 2015 data for OOS testing
	BarPeriod = 60;
	LookBack = 209;
	if (is(INITRUN)) { AssetVar[0] = 0; AssetVar[1] = 0; AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; }
	
	TimeFrame = W1;
	frameAlign(dow() == 7 and hour() == 23); //align weekly chart to a UTC open time of Sunday 2200 (note it is 2100 in summer)
	vars closeW1 = series(priceClose());
	AssetVar[1] = closeW1[0];
	
	TimeFrame = H1;
	if (dow() == 7 and hour() == 23) { AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; } //reset to zero at start of each week
	int exitDay = 5;
	int exitHour = 16;
	
	var entryMultiple = 4;//
	Stop = 30 *PIP;
	Trail =2 * entryMultiple * ATR(168); // optimize(0.5, 0.25, 3.0, 0.25) * entryMultiple * ATR(168); //
		
	if (AssetVar[2] == 0) {
		if (!(dow() == exitDay and hour() >= exitHour)) {
			Entry = closeW1[0] + entryMultiple*ATR(168);
			if (NumOpenLong == 0) enterLong(myTMF1);
			Entry = closeW1[0] - entryMultiple*ATR(168);
			if (NumOpenShort == 0) enterShort(myTMF1); 
			}
		}
	if (AssetVar[2] > 0) {
		if (!(dow() == exitDay and hour() >= exitHour)) {
			Entry = closeW1[0];
			if (NumOpenLong == 0 and AssetVar[3] < 1) {	enterLong(myTMF);} 
			if (NumOpenShort == 0 and AssetVar[4] < 1) { enterShort(myTMF);}
			}
		}
		
		if (dow() == exitDay and hour() == exitHour) {exitLong("*"); exitShort("*");}
		plot("closeW1", closeW1, MAIN, RED);
	
}


Re: TradeIsEntry appears to always be False [Re: Trading4pips] #471955
03/28/18 16:00
03/28/18 16:00
Joined: Sep 2017
Posts: 12
T
Trading4pips Offline OP
Newbie
Trading4pips  Offline OP
Newbie
T

Joined: Sep 2017
Posts: 12
I just tried the above code in 1.80.8 and TradeIsEntry is still not working (it's always False).

Does anyone know if there is there a bug with TradeIsEntry? If TradeIsEntry is working properly, would someone please provide me with a working example of how to use it.

Re: TradeIsEntry appears to always be False [Re: Trading4pips] #471956
03/28/18 16:27
03/28/18 16:27
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
Code:
int tmf() {
	if(TradeIsEntry) printf("\nTradeIsEntry!");
	return 0;
}

function run() {
	Entry = 10*PIP;
	if(random() > 0.9)
		enterLong(tmf);
	if(random() < -0.9)
		exitLong();
}




Re: TradeIsEntry appears to always be False [Re: Trading4pips] #471957
03/28/18 16:28
03/28/18 16:28
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline
User
Sphin  Offline
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
It's more a guess but TradeIsEntry assumes an Entry limit has been hit. Can it be that you search for TradeIsOpen?

Re: TradeIsEntry appears to always be False [Re: Sphin] #471960
03/28/18 19:23
03/28/18 19:23
Joined: Sep 2017
Posts: 12
T
Trading4pips Offline OP
Newbie
Trading4pips  Offline OP
Newbie
T

Joined: Sep 2017
Posts: 12
ty @Sphin, TradeIsOpen also didn't work.

ty @Petra, the code helped a lot and showed me that the issue in the code I posted above were the printf statements. For those that are interested, here is the above code with the correct printf statements:

Code:
#define H1 (60/BarPeriod)
#define H24 (1440/BarPeriod)
#define W1 (7200/BarPeriod)

int myTMF1() {
	if (TradeIsEntry) { 
		AssetVar[2] += 1; 
			if (TradeIsLong){
				AssetVar[3] += 1;
				printf("\nA. TradeIsLong & AssetVar[3] is %.2f\n",(var)AssetVar[3]);
			}	
			if (TradeIsShort) {
				AssetVar[4] += 1;
				printf("\nB. TradeIsShort & AssetVar[4] is %.2f\n",(var)AssetVar[4]);
			}
		printf("\nC. TradeIsEntry: %.2d, AssetVar[2]: %.2f, AssetVar[3]: %.2f, AssetVar[4]: %.2f\n",TradeIsEntry,(var)AssetVar[2],(var)AssetVar[3],(var)AssetVar[4]);

	}
	return 0;
}

int myTMF() { 

	if (TradeIsEntry) {AssetVar[2] = AssetVar[2] + 1; 
		if (TradeIsLong) AssetVar[3] += 1;
		if (TradeIsShort) AssetVar[4] += 1;
	}
	if (TradeIsLong and TradeIsStop and AssetVar[4] < 1){
		enterShort(myTMF);
		printf("\nD. entershortn");
		
	printf("\nE. TradeIsEntry: %.2d, AssetVar[2]: %.2f, AssetVar[3]: %.2f, AssetVar[4]: %.2f\n",TradeIsEntry,(var)AssetVar[2],(var)AssetVar[3],(var)AssetVar[4]);
	}
	return 0;
	if (TradeIsShort and TradeIsStop and AssetVar[3] < 1) {
		enterLong(myTMF);	
		printf("\nE. entershort\n");
	}	
	return 0;

	return 0;
}

function frameAlign(BOOL Event){ 
	// Let time frame start when Event == true
	// f.i. frameAlign(hour() == 0); aligns to midnight 
	TimeFrame = 1;
	vars Num = series(0); // use a series for storing Num between calls
	Num[0] = Num[1]+1;    // count Num up once per bar  
	if(!Event) 
	TimeFrame = 0;      // continue current time frame  
	else {
		TimeFrame = -Num[0]; // start a new time frame
		Num[0] = 0;          // reset the counter  
	}
}

function run() {
	set(TICKS|PARAMETERS|FACTORS|LOGFILE); 
	Weekend = 3; // don't run TMF at weekend
	StartDate = 20140901;
	EndDate = 20141231; //preserve 2015 data for OOS testing
	BarPeriod = 60;
	LookBack = 209;
	if (is(INITRUN)) { AssetVar[0] = 0; AssetVar[1] = 0; AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; }
	
	TimeFrame = W1;
	frameAlign(dow() == 7 and hour() == 23); //align weekly chart to a UTC open time of Sunday 2200 (note it is 2100 in summer)
	vars closeW1 = series(priceClose());
	AssetVar[1] = closeW1[0];
	
	TimeFrame = H1;
	if (dow() == 7 and hour() == 23) { AssetVar[2] = 0; AssetVar[3] = 0; AssetVar[4] = 0; } //reset to zero at start of each week
	int exitDay = 5;
	int exitHour = 16;
	
	var entryMultiple = 4;//
	Stop = 30 *PIP;
	Trail =2 * entryMultiple * ATR(168); // optimize(0.5, 0.25, 3.0, 0.25) * entryMultiple * ATR(168); //
		
	if (AssetVar[2] == 0) {
		if (!(dow() == exitDay and hour() >= exitHour)) {
			Entry = closeW1[0] + entryMultiple*ATR(168);
			if (NumOpenLong == 0) enterLong(myTMF1);
			Entry = closeW1[0] - entryMultiple*ATR(168);
			if (NumOpenShort == 0) enterShort(myTMF1); 
			}
		}
	if (AssetVar[2] > 0) {
		if (!(dow() == exitDay and hour() >= exitHour)) {
			Entry = closeW1[0];
			if (NumOpenLong == 0 and AssetVar[3] < 1) {	enterLong(myTMF);} 
			if (NumOpenShort == 0 and AssetVar[4] < 1) { enterShort(myTMF);}
			}
		}
		
		if (dow() == exitDay and hour() == exitHour) {exitLong("*"); exitShort("*");}
		plot("closeW1", closeW1, MAIN, RED);
	
}


Re: TradeIsEntry appears to always be False [Re: Trading4pips] #471961
03/28/18 19:32
03/28/18 19:32
Joined: Sep 2017
Posts: 12
T
Trading4pips Offline OP
Newbie
Trading4pips  Offline OP
Newbie
T

Joined: Sep 2017
Posts: 12
Unfortunately, I still can't resolve the issue with TradeIsEntry in my code.
It appears to always be false since the printf statement in the TMF never prints.

Here is a snippet of my code. Can anyone review and let me know what I need to change to resolve the issue? Thanks.

Code:
/*                        DISCLAIMERS: 
   The following code and ideas are for educational purposes only
    and is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR,
         CONDITIONS OF ANY KIND, either express or implied.

  Trading involves substantial risk of loss and is not suitable for all 
   investors.  Past performance is not indicative of future results.

   DESCRIPTION: Identify Hi and Low of Open Range and enter into 3 trades 
      on break of either Hi or Low. Set 1 Stop & 3 Targets for scale outs.
*/

// Define AssetVar to be used in run function & TMF
#define EntryHI AssetVar[0]
#define EntryLO AssetVar[1]
#define Range AssetVar[2]
#define TradesToday AssetVar[3]
#define TradesLong AssetVar[4]
#define TradesShort AssetVar[5]

int tmf() {
	// 3 longs / 3 shorts - with 1 Stop & 3 Targets for scale outs
	enterLong(0,EntryHI,Range,Range); // (Lots, Entry, Stop, Target)
	enterLong(0,EntryHI,Range,Range*2);
	enterLong(0,EntryHI,Range,Range*3);
	enterShort(0,EntryLO,Range,Range);
	enterShort(0,EntryLO,Range,Range*2);
	enterShort(0,EntryLO,Range,Range*3);

	if (TradeIsEntry) { // ?? Always appears to be false as printf is never printed. ??
		printf("\nTMF-A. TradeIsEntry! %.5d\n",TradeIsEntry);
		TradesToday += 1;
		if (TradeIsLong) {
			TradesLong += 1;
			printf("\nTMF-B. Trade for %s is Long.\n   TradesToday: (%.0f) & TradesLong: (%.0f) s/b 1, while TradesShort: (%.0f) s/b 0\n",Asset,TradesToday,TradesLong,TradesShort);
		}
		
		if (TradeIsShort) {
			TradesShort += 1;
			printf("\nTMF-C. Trade for %s is Short.\n   TradesToday: (%.0f) & TradesShort: (%.0f) s/b 1, while TradesLong: (%.0f) s/b 0\n",Asset,TradesToday,TradesShort,TradesLong);
		}
	}
	return 0;
}

function run() {
	set(TICKS|LOGFILE); //|RISKLIMIT|PLOTNOW);	
	BarPeriod = 30;		// 1 Hour
	var WiggleRoom = 1;	// Room in *PIPs to add/subtract from entries 
	
	int limit = 3; 		// max number of trades
	Risk = 200; 		// Max Risk per trade
	
	// DATE & TIME VARIABLES (TIMES ARE IN CHICAGO TIME (Central))
	StartDate = 20100102;	// Start date
	EndDate = 20100105;	// End date
	
	AssetZone = CST; 	// Set timezone to Central (i.e. Chicago)
	
	int marketstarthour	= 8;
	int marketstartminute	= 30;
	int marketendhour	= 15;
	int marketendminute	= 0;
	int StartTradingHour	= 9;
	int StartTradingMinute	= 0;
	int StopTradingHour	= 14;
	int StopTradingMinute	= 30;
	int OpenRangeHourEnds 	= 9;	// Open Range Hour ends
	int OpenRangeMinuteEnds = 0;	// Open Range Minute ends

	// COSTS
	Spread = Commission = Slippage = RollLong = RollShort = 0;  // Ignore costs
	
	// INITRUN
	if (is(INITRUN)) {
		EntryHI = 0; EntryLO = 0; Range = 0; TradesToday = 0; TradesLong = 0;
			TradesShort = 0; } // Clear Variables prior to initial run

	while(asset(loop("SPX500"))) {			// Define Assets

		vars hi	= series(priceHigh());  	// Create Series of Highs
		vars lo	= series(priceLow());		// Create Series of Lows
	
		// Print details for debugging
		printf("\nA. %s - hi %.5f, lo %.5f\n",Asset,hi[0],lo[0]);
	
		vars BarHI = series(MaxVal(hi,BarPeriod)); 	// Series of Max Highs
		vars BarLO = series(MinVal(lo,BarPeriod));	// Series of Min Lows
		vars BarRange = series(BarHI[0]-BarLO[0]); 	// Series of Hi-Lo Ranges
		
		// Print details for debugging
		printf("\nB. %s - BarHI %.5f, BarLO %.5f, BarRange %.5f\n",Asset,BarHI[0],BarLO[0],BarRange[0]);
		
		if(lhour() == OpenRangeHourEnds && minute() == OpenRangeMinuteEnds) {
			EntryHI = BarHI[0]+WiggleRoom*PIP;
			EntryLO = BarLO[0]-WiggleRoom*PIP;
			Range = BarRange[0]+(2*WiggleRoom*PIP);
					
			// Print details for debugging
			printf("\nC. %s - EntryHI: %.5f, EntryLO: %.5f, Range: %.5f\n",Asset,EntryHI,EntryLO,Range);
		}
		
		if (lhour() >= StartTradingHour && minute() >= StartTradingMinute && lhour() <= StopTradingHour && minute() <= StopTradingMinute ) {
			
			tmf();	// Call TMF for trades
			//enterLong(tmf);
			//enterShort(tmf);	
		}
	}
}


Re: TradeIsEntry appears to always be False [Re: Trading4pips] #472052
04/03/18 13:55
04/03/18 13:55
Joined: Sep 2017
Posts: 12
T
Trading4pips Offline OP
Newbie
Trading4pips  Offline OP
Newbie
T

Joined: Sep 2017
Posts: 12
Can anyone review my code in the last post and let me know what I need to change so that TradeIsEntry is not always false?

Re: TradeIsEntry appears to always be False [Re: Trading4pips] #472054
04/03/18 14:45
04/03/18 14:45
Joined: Jul 2017
Posts: 784
Z
Zheka Offline
User
Zheka  Offline
User
Z

Joined: Jul 2017
Posts: 784

Frist, As is, your int tmf() is not a "trade-management function". It is not called as an argument in an entry/exit statement, so it is just a normal function.
As a normal function, it has no access to Trade variables , incl. TradeIsEntry.

Second, TradeIsEntry has a value when a trade is entered with "Entry"; Entry has to be set to a value.
Review the manual on Entry.

I did not run nor experimented with the code. Just first observations..

Re: TradeIsEntry appears to always be False [Re: Zheka] #472062
04/03/18 17:43
04/03/18 17:43
Joined: Sep 2017
Posts: 12
T
Trading4pips Offline OP
Newbie
Trading4pips  Offline OP
Newbie
T

Joined: Sep 2017
Posts: 12
ty @Zheka for the comments,

I had tried calling tmf with entry statements but commented them out because they did not work:
//enterLong(tmf);
//enterShort(tmf);

The main issue I'm having is that the manual and all of the examples I've found call the tmf using just enterLong(tmf) or enterShort(tmf). However, I want to enter into either 3 long or short trades (depending on which way the price breaks out) with specific stops and different targets. This is why I have set up these:

enterLong(0,EntryHI,Range,Range); // (Lots, Entry, Stop, Target)
enterLong(0,EntryHI,Range,Range*2);
enterLong(0,EntryHI,Range,Range*3);
enterShort(0,EntryLO,Range,Range);
enterShort(0,EntryLO,Range,Range*2);
enterShort(0,EntryLO,Range,Range*3);

Obviously I'm doing something wrong, but reading the manual does not help as I can not find examples of what I'm trying to do. Any assistance would be greatly appreciated.

Re: TradeIsEntry appears to always be False [Re: Trading4pips] #472063
04/03/18 18:15
04/03/18 18:15
Joined: Jul 2017
Posts: 784
Z
Zheka Offline
User
Zheka  Offline
User
Z

Joined: Jul 2017
Posts: 784
Explore also the second point of my reply.

Page 1 of 2 1 2

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