Gamestudio Links
Zorro Links
Newest Posts
AssetsSP50.csv
by oldflatop. 04/19/21 10:21
Experience with Dukascopy plugin
by Hajoha. 04/19/21 09:11
OANDA-US No Balance Showing
by nullantechamber. 04/18/21 10:24
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/17/21 15:55
Script Template
by DdlV. 04/17/21 15:07
Sierra Chart Plugin
by AndrewAMD. 04/16/21 13:21
AUM Magazine
Latest Screens
Hecknex World
Scheherazade's Journey
Paradox Vector
The Space Between
Who's Online Now
7 registered members (AndrewAMD, oldflatop, AdamWu, Quad, Hajoha, 2 invisible), 415 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
nayan, taygeezy, dadbean, VizTra, simonkrebs
18629 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Zorro version 2.35 - GET_POSITION not working (MT4 bridge) #482847
04/06/21 20:47
04/06/21 20:47
Joined: Apr 2021
Posts: 6
S
simonkrebs Offline OP
Newbie
simonkrebs  Offline OP
Newbie
S

Joined: Apr 2021
Posts: 6
Hello,

I have tested the Alice6 script from the Blackbook. Unfortunately the determination of OldLots does not work, so the positions from the last cycle (2 months before) are not closed.

The problem seems to be that the brokercommand GET_POSITION does not give a result. This should work since Zorro version 2.35, but unfortunately does not for me.

Then wrote a short test script, it doesn't give any results either. Tested with Darwinex and Global Prime (Zorro 2.35 with MT4 bridge).

Here's the test script:

Code
function run() {
	set(PLOTNOW+BALANCE+LOGFILE);
	set(PRELOAD); //reduce load for fetching data from MT4 server
	set(NOLOCK); //speed up API access
	LookBack = 0;

	assetList("AssetsGP");	
	asset("EUR/USD");
	
	printf("\n%d", (int)brokerCommand(GET_POSITION,Asset)); //doesnt work

	exitLong("*"); //workaround for simply closing all open positions in the trading account -> doesn't work, too

	if(Live && !is(LOOKBACK)) 
		quit("Ok!");
}



As a workaround, I tried just using exitLong to close all positions, but that doesn't work either. It just doesn't do anything at all. Here my guess is that the trades from the previous sessions are not recognized as open positions.

Can anyone help me with this?

Thx,

Simon

Last edited by simonkrebs; 04/06/21 20:47.
Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge) [Re: simonkrebs] #482849
04/07/21 06:14
04/07/21 06:14
Joined: Mar 2017
Posts: 18
J
jyd Online
Newbie
jyd  Online
Newbie
J

Joined: Mar 2017
Posts: 18
GET_POSITION works for me. Have you updated your Zorro MT4 EA, which contains the implementation of GET_POSITION? My understanding is that exitLong() only works with the Zorro tracked orders. If it is not tracked, it can't be closed.

Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge) [Re: simonkrebs] #482855
04/07/21 14:57
04/07/21 14:57
Joined: Apr 2021
Posts: 6
S
simonkrebs Offline OP
Newbie
simonkrebs  Offline OP
Newbie
S

Joined: Apr 2021
Posts: 6
Hi jyd, I checked again today and it did not work. Here's the code for my script:

Code
// Simple portfolio rotation /////////////
//////////////////////////////////////////

#define RISK	0.7	// no risk, no fun

var Momentums[100],Weights[100];

void rotate(int GoLong)
{
	var Invest = RISK*(Capital+ProfitTotal);
	for(listed_assets) {
		int NewLots = Invest*Weights[Itor]/MarginCost;
		if(Test) {
			if(NewLots > LotsPool && GoLong)
				enterLong(NewLots-LotsPool);
			else if(NewLots < LotsPool)
				exitLong(0,0,LotsPool-NewLots);
		} else if(Live) {
			int OldLots = brokerCommand(GET_POSITION,Asset);
			if(NewLots > OldLots && GoLong)
				enterLong(NewLots-OldLots);
			else if(NewLots < OldLots)
				enterShort(OldLots-NewLots);
		}
	}
}

void run() 
{
	set(PLOTNOW|LOGFILE);
	StartDate = ifelse(Live,NOW,20120101); 
	EndDate = 20181231;
	BarPeriod = 1440;
	LookBack = 100;
	SaveMode = 0;
	
	assetList("AssetsSP30");
	Capital = slider(1,10000,0,20000,"Capital","");
	
	for(listed_assets) { 
		asset(Asset);
		vars Prices = series(priceClose());
		Momentums[Itor] = ROC(Prices,LookBack-1);
	}

	if((Live && !is(LOOKBACK))
		|| (Test && tdm(0) == 1 && month(0)%2)) // first trading day of every second month
	{
		distribute(Weights,Momentums,NumAssetsListed,5,0.5); 
		rotate(0);	// exit old positions
		rotate(1);	// enter new positions
	}

	if(Live && !is(LOOKBACK)) quit("Ok!");
}


I did two attempts, on the first he opened 5 positions. Directly after I started the script a second time. This time Zorro tried to open another 5 positions, but could not close the trades from the previous run. So there was not enough margin left to place all orders.

Can anyone help me fix this?

Thanks in advance,

Simon

Attached Files Bildschirmfoto 2021-04-07 um 16.48.33.jpgBildschirmfoto 2021-04-07 um 16.49.08.jpg
Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge) [Re: simonkrebs] #482856
04/07/21 15:01
04/07/21 15:01
Joined: Feb 2017
Posts: 1,227
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,227
Chicago
Quote
Have you updated your Zorro MT4 EA
You did not confirm that you updated your EA on the MT4 side. Did you? When in doubt, delete your EA completely and reinstall it.

Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge) [Re: simonkrebs] #482857
04/07/21 15:10
04/07/21 15:10
Joined: Feb 2017
Posts: 1,227
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,227
Chicago
Also, the code you are showing was designed for an NFA plugin. The MT4 bridge is not an NFA plugin. This needs a rewrite.

Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge) [Re: AndrewAMD] #482860
04/07/21 16:51
04/07/21 16:51
Joined: Apr 2021
Posts: 6
S
simonkrebs Offline OP
Newbie
simonkrebs  Offline OP
Newbie
S

Joined: Apr 2021
Posts: 6
Thanks AndrewAMD, yes I updated the EA (removed all files and replaced with the DLL and EQ4 files from the zip).

So you mean the code is not working with MT4? What's the reason for that?

Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge) [Re: simonkrebs] #482861
04/07/21 17:50
04/07/21 17:50
Joined: Feb 2017
Posts: 1,227
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,227
Chicago
The non-NFA plugins (Oanda, MT4, etc) have an "enter trade exit trade" interface to the broker. So individual trades must be managed.

The NFA plugins (IB, etc) have an "order placement" interface to the broker. You place orders to change position. Position tracking is especially useful here. There is no need to manage individual "trades".

These have implications on how you should program your script for live trading.

Further reading:
https://zorro-project.com/manual/en/trading.htm
https://zorro-project.com/manual/en/hedge.htm
https://zorro-project.com/manual/en/buylong.htm
https://zorro-project.com/manual/en/trademode.htm

Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge) [Re: simonkrebs] #482862
04/07/21 18:12
04/07/21 18:12
Joined: Apr 2021
Posts: 6
S
simonkrebs Offline OP
Newbie
simonkrebs  Offline OP
Newbie
S

Joined: Apr 2021
Posts: 6
Ok, I see. Thanks for your answer, that was very helpful.

Is there a possibility to just close all trades before rotate(1) is been executed?

Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge) [Re: simonkrebs] #482863
04/08/21 00:16
04/08/21 00:16
Joined: Mar 2017
Posts: 18
J
jyd Online
Newbie
jyd  Online
Newbie
J

Joined: Mar 2017
Posts: 18
AndrewAMD is right. The code you posted seems to be JCL's stock investment code from black book, which is designed for IB. MT4 is a FX and CFDs trading platform. So make sure you know what you are trying to do first.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1