Gamestudio Links
Zorro Links
Newest Posts
rMomentum always returns 0 when checking for peak/valley
by jcl
Today at 17:38
a little help here?
by 3run
Today at 16:38
How to set a pair trading order right
by jcl
Today at 11:46
Dual Momentum Algorithm - The way Zorro would have done it
by Hredot
Today at 05:21
HIgh FRequency Trading Script -- Highly Profitable
by Yosh
Yesterday at 19:27
Linear Regression in objective function
by jcl
11/22/17 15:40
MT4 vs Zorro
by pascalx
11/22/17 14:00
AUM Magazine
Latest Screens
RPG PARTY
Triton Wing now available on Steam
AckCon'17: Lotter vs The World
Triton Wing
Who's Online
14 registered (Lobo, Hredot, painkiller, 3run, alibaba, Kartoffel, FLD, RealSerious3D, Jerome8911, 1 invisible), 169 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
ech87, Lobo, Andy60, AzzoCorp, franzz
17813 Registered Users
Topic Options
Rate This Topic
#468971 - 10/31/17 13:23 TMF not executed at each ticks
JohanAu Offline
Newbie

Registered: 09/24/16
Posts: 17
Loc: 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


Attachments
MultipleAssetsTMF.png




Edited by JohanAu (10/31/17 13:58)

Top
#468989 - 11/01/17 10:51 Re: TMF not executed at each ticks [Re: JohanAu]
jcl Online

Chief Engineer

Registered: 07/22/00
Posts: 25939
Loc: 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.


Top
#469008 - 11/02/17 08:36 Re: TMF not executed at each ticks [Re: jcl]
JohanAu Offline
Newbie

Registered: 09/24/16
Posts: 17
Loc: 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).






Edited by JohanAu (11/02/17 08:55)

Top
#469012 - 11/02/17 10:00 Re: TMF not executed at each ticks [Re: JohanAu]
jcl Online

Chief Engineer

Registered: 07/22/00
Posts: 25939
Loc: 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.

Top
#469365 - 11/13/17 10:25 Re: TMF not executed at each ticks [Re: jcl]
JohanAu Offline
Newbie

Registered: 09/24/16
Posts: 17
Loc: 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

Top
#469367 - 11/13/17 11:39 Re: TMF not executed at each ticks [Re: JohanAu]
jcl Online

Chief Engineer

Registered: 07/22/00
Posts: 25939
Loc: 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.

Top



Gamestudio download | chip programmers | Zorro platform | shop | resources | magazine | manual | support faq | bugs

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) 3dgamestudio.net