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/2120:47.
Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge)
[Re: simonkrebs]
#482849 04/07/2106:1404/07/2106:14
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/2114:5704/07/2114:57
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
Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge)
[Re: simonkrebs]
#482856 04/07/2115:0104/07/2115:01
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.
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.
Re: Zorro version 2.35 - GET_POSITION not working (MT4 bridge)
[Re: simonkrebs]
#482991 04/21/2112:5004/21/2112:50