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 (AndrewAMD, monk12, TipmyPip, Quad, aliswee), 1,031 guests, and 6 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
TMF not executed at each ticks #468971
10/31/17 12:23
10/31/17 12:23
Joined: Sep 2016
Posts: 20
France
J
JohanAu Offline OP
Newbie
JohanAu  Offline OP
Newbie
J

Joined: Sep 2016
Posts: 20
France
Hello everyone,

I am familiar with zorro since last year but live trading since fews weeks now and I would like to report something curious.

I am using Zorro 1.72 and I have observed the following behavior.

According to the documentation of zorro (which is great by the way) :

"All stop, profit, trail, or entry limits are handled by software and controlled at each tick. They are not sent to the broker's server (except for the 'safety net' stop given by StopFactor) and thus not visible to the broker, this way preventing "stop hunting" or similar practices. This also steps around NFA Compliance Rule 2-43(b) that does not allow US citizens to place stop or profit targets"

It works well when live trading only one asset :
- When the take profit is hit, the trade is closed immediately.

But when I use that same algo but with multiple assets in a loop ( while(loop(Assets)) :

- when the take profit is hit, the trade is closed as next bar.
- The only exception is for the asset that is selected in the GUI (see attached files). in that way is works fine.

Is it a behavior that is wanted ? or is it a feature for Zorro S user only ? or is it a bug ?
Please let me know that you think.

This cause trouble because since it close the trade at the next bar, the profit can be quite different from expected.

Best regards,
Johan

Attached Files
MultipleAssetsTMF.png (141 downloads)
Last edited by JohanAu; 10/31/17 12:58.
Re: TMF not executed at each ticks [Re: JohanAu] #468989
11/01/17 09:51
11/01/17 09:51
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
No, Stops and TPs must work in the same way with single and with multiple assets.

If your script behaves different dependent on whether you select the asset by script or with the scrollbox, then I would first suspect some wrong initialization. Make sure that you set the parameters for the right asset, after and not before selecting it. And set Stop and TP before entering the trade, not after it.


Re: TMF not executed at each ticks [Re: jcl] #469008
11/02/17 07:36
11/02/17 07:36
Joined: Sep 2016
Posts: 20
France
J
JohanAu Offline OP
Newbie
JohanAu  Offline OP
Newbie
J

Joined: Sep 2016
Posts: 20
France
Hi Jcl,

Thank for your hints,

According to your comment, I have added the is(INITRUN) check when loading the assetList (which was not the case).

I am using now the following script for test purpose :

Code:
function run()
{
set(PLOTNOW);
set(LOGFILE);
set(PRELOAD);
Verbose=7;
StartDate = 20150615;
EndDate = 20171001;
Weekend=0;

if(is(INITRUN)) {
		assetList("AssetsStrategy.csv"); // load asset list
}

while (asset(loop(Assets)))
{

BarPeriod = 15;
MaxLong = 4;
var winprofit;
set(NFA);
vars Price = series(price());
var NbDevUp=1.7;
var NbDevDn=1.7;
BBands((series(1000*priceClose())),20,NbDevUp,NbDevDn,MAType_SMA);
vars upperBand = series(rRealUpperBand/1000);
vars lowerBand = series(rRealLowerBand/1000);
plot("Bollinger1",rRealUpperBand/1000,BAND1,BLACK);
plot("Bollinger2",rRealLowerBand/1000,BAND2,GREY);
set(PLOTNOW);
set(TICKS);

printf("n Asset  : %s ",Asset);
printf("n price  : %.8f ",Price[0]);
printf("n UpperBand  : %.8f ",upperBand[0]);
printf("n LowerBand  : %.8f ",lowerBand[0]); 

if (crossUnder(Price, lowerBand) && NumOpenLong <MaxLong)
	{

	Lots = 1;
    TakeProfit = 1.0375*price();
	winprofit = (WinLong - LossLong);
	
	printf("n Asset  : %s ",Asset);
	printf("n pip cost : %.8f ",PIPCost);
	printf("n pip  : %.8f ",PIP);
	printf("n commission cost: %.8f ",CommissionCost);
	printf("n commission : %.8f ",Commission);
	printf("n lot amount : %.8f ",LotAmount);
	printf("n lot  : %.8f ",Lots);
	printf("n spread  : %.8f ",Spread);
	printf("n price  : %.8f ",Price[0]);
	printf("n UpperBand  : %.8f ",upperBand[0]);
	printf("n LowerBand  : %.8f ",lowerBand[0]);
	printf("n win - loss in btc : %.8f ",winprofit);
	
	enterLong();
  }	
	
}
	
plot("$ Balance",Balance,NEW,BLUE); 
plot("Equity",Equity,0,GREEN); 

}



It seems that the issue is still present, maybe I have misunderstood something with the BarPeriod (but normally should not affect TMFs).





Last edited by JohanAu; 11/02/17 07:55.
Re: TMF not executed at each ticks [Re: JohanAu] #469012
11/02/17 09:00
11/02/17 09:00
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Yes, that looks quite wrong. I wonder why you get no runtime error with this script.

The order of commands does matter in programming. First set all script parameters, such as the bar period, TICKS, etc, and then load the asset. Not the other way around. Otherwise the asset is not loaded in TICKS mode, but in low resolution. The INITRUN clause is not needed.

You can see in workshop 6 in the manual how a portfolio script should look like.

Re: TMF not executed at each ticks [Re: jcl] #469365
11/13/17 09:25
11/13/17 09:25
Joined: Sep 2016
Posts: 20
France
J
JohanAu Offline OP
Newbie
JohanAu  Offline OP
Newbie
J

Joined: Sep 2016
Posts: 20
France
Hi Jcl,

Thank you for your response.
I have modified the function according to your comments :

Code:
function TradeBBands()
{
var NbDevUp=1.7;
var NbDevDn=1.7;
var MaxTradePerAsset = 4;

vars Price = series(price());
BBands((series(1000*priceClose())),20,NbDevUp,NbDevDn,MAType_SMA);
vars upperBand = series(rRealUpperBand/1000);
vars lowerBand = series(rRealLowerBand/1000);
Lots = 1;

if (crossUnder(Price, lowerBand) && NumOpenLong <MaxTradePerAsset)
	{
  TakeProfit = 1.0375*price();
	enterLong();
  }		
}


function run()
{
set(LOGFILE+PRELOAD+NFA+TICKS);
BarPeriod = 15;
Weekend = 0;
Verbose=7;
Capital = 0.009;
StartDate = 20150615;
EndDate = 20171001;

assetList("AssetsToUse.csv"); // load asset list

while (asset(loop(Assets)))
{
TradeBBands();	
}	
}



Tested it again and the issue is still present.
The trade is close at the right time only for one asset.
I don't know what variable I can check to diagnose the faulty element. Do you have any tips ?

BR, Johan

Re: TMF not executed at each ticks [Re: JohanAu] #469367
11/13/17 10:39
11/13/17 10:39
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Looks better now. At least I see no obvious reason for a delayed exit. But I would not use price() for a TakeProfit. That means the limit can be already below the current price.

For diagnose, use a TMF that prints the current time, asset, TradeProfitLimit, and TradePriceClose. That should give insight in the trade exit behavior.


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