Gamestudio Links
Zorro Links
Newest Posts
Can't go to FALSEGOTO:DOUBLE?
by Turrican
Today at 00:34
Chamferbox Lucky Pack, once a year chance, 90% OFF limited deals
by Chamferbox
Yesterday at 21:10
How detect 200 bars after trade was opened?
by Tuguldur717
Yesterday at 13:58
Data quality and accuracy of test results
by brax
Yesterday at 13:44
Can be changed the header in Zorro?
by tomaslolo
Yesterday at 12:12
Price difference between last tick and previous.
by JRA
Yesterday at 11:47
Zorro on Linux
by alb
02/21/18 20:47
AUM Magazine
Latest Screens
Forgotten Tales - Demo version
RPG PARTY
Triton Wing now available on Steam
AckCon'17: Lotter vs The World
Who's Online
17 registered (dmac, Hredot, Cheulmen, BlackJack, MatPed, Kartoffel, alibaba, AndrewAMD, 3 invisible), 475 Guests and 9 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
tomaslolo, dmac, alb, may, piddle61
17896 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: 20
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 Offline

Chief Engineer

Registered: 07/22/00
Posts: 26227
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: 20
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 Offline

Chief Engineer

Registered: 07/22/00
Posts: 26227
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: 20
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 Offline

Chief Engineer

Registered: 07/22/00
Posts: 26227
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