hi,i got a problem about GV functions these days,and couldn't deal with it,please help.
my object:
1. hedge trading on 3 symbols(with strategies S1,S2,S3),with GV function to synchronize.
2. when a new position opens on symbol 1(with strategy s1),a new hedge position opens on symbol 2(with strategy s2) at once. when positions open on symbol 1 and 2,a new position opens on symbol 3;
3. when position closes on symbol 1,the position on symbol 2 and 3 closes in order.
my problem:
1. position on symbol 2 not always open when a new position opens on symbo 1,that's,some trade would be ignored;
2. many trade signals are ignored on symbol 3.
3. when a position opens on symbol 2 or 3,it close immediately in one bar,not waiting for GV value change on symbol 1.
a snapshot of these problem is in attachment.
and the code for s1,s2,s3 are below.
problem about GV functions for multi symbols trading
problem about GV functions for multi symbols trading
- Attachments
-
- snapshot.JPG
- (194.16 KiB) Downloaded 956 times
Re: problem about GV functions for multi symbols trading
here are the code:
s1:
s1:
Code: Select all
inputs: flag(1),
iSizeZS(10), //ZS's initial position info of first trade of a day
Direction(1), //new position's diretion is the same or adverse to the first position?
Multi(1); //the multiplies of new position to the original position size
var: mp(0), //marketposition status
SizeZS(0), SizeY(20), SizeM(15), //size of each position
modtest(0);
mp = marketposition;
SizeZS = iSizeZS;
modtest = mod(barnumber, 10);
GVSetNamedDouble("GVSizeZS", iSizeZS);
if time > 0900 and time < 1459 then begin // in trading time
if mp <> 0 then begin
if mp[1] = 0 and mp > 0 then //long position was established on last bar
GVSetNamedDouble("GVRTSizeZS", 1*iSizeZS*multi);
if mp[1] = 0 and mp < 0 then // short position was established on last bar
GVSetNamedDouble("GVRTSizeZS", -1*iSizeZS*multi);
if modtest = 8 then begin
if mp > 0 then sell ("Hedge LX") next bar at market
else if mp < 0 then buytocover ("Hedge SX") next bar at market;
end;
end
else if mp = 0 then begin
if mp[1] <> 0 then GVSetNamedDouble("GVRTSizeZS", 0); //when cbot position was flatted,change global var's value
if modtest = 3 then begin //spread in's condition trigged
if Direction = 1 then begin //if the trading direction is the same as the first trade
if flag > 0 then begin
buy ("D+1 LE") iSizeZS*multi contracts next bar at market;
end
else if flag < 0 then begin
sellshort ("D+1 SE") iSizeZS*multi contracts next bar at market;
end;
end
else if Direction = -1 then begin
if flag > 0 then begin
sellshort ("D-1 SE") iSizeZS*multi contracts next bar at market;
end
else if flag < 0 then begin
buy ("D-1 LE") iSizeZS*multi contracts next bar at market;
end;
end;
end;
end;
end
else if time >= 1459 then begin
sell ("EOD LX") next bar at market;
buytocover ("EOD SX") next bar at market;
GVSetNamedDouble("GVSizeZS", iSizeZS);
GVSetNamedDouble("GVRTSizeZS", 0 );
GVSetNamedDouble("GVRTSizeY", 0);
end;
Re: problem about GV functions for multi symbols trading
here is s2:
Code: Select all
var: iSizeZS(0), SizeY(20), RTSizeZS(0), RTSizeY(0), mp(0);
mp = marketposition;
iSizeZS = GVGetNamedDouble("GVSizeZS", -9999);
RTSizeZS = GVGetNamedDouble("GVRTSizeZS", -9999);
//if ZS's position is flatted,
if (RTSizeZS[1]<>0 and RTSizeZS = 0) and mp <> 0 then begin
if mp > 0 then
sell ("HedgeLX") next bar at market
else if mp < 0 then
buytocover ("HedgeSX") next bar at market;
GVSetNamedDouble("GVRTSizeY", 0);
end;
//establish position
if (RTSizeZS[1]=0 and RTSizeZS<>0) and mp=0 then begin
if RTSizeZS > 0 then begin
sellshort ("HedgeSE") SizeY contracts next bar at market;
GVSetNamedDouble("GVRTSizeY", -1*SizeY);
end
else if RTSizeZS < 0 then begin
buy ("HedgeLE") SizeY contracts next bar at market;
GVSetNamedDouble("GVRTSizeY", SizeY);
end;
end;
//print("barnumber: ",BarNumber," time_S: ",time_s," RTSizeZS: ",RTSizeZS);
Re: problem about GV functions for multi symbols trading
here is s3:
Code: Select all
var: iSizeZS(0), SizeM(15), RTSizeZS(0), RTSizeY(0), RTSizeM(0), mp(0);
mp = marketposition;
iSizeZS = GVGetNamedDouble("GVSizeZS", -9999);
RTSizeZS = GVGetNamedDouble("GVRTSizeZS", -9999);
RTSizeY = GVGetNamedDouble("GVRTSizeY", -9999);
//if ZS's position is flatted,
if (RTSizeZS[1]<>0 and RTSizeZS = 0) and (RTSizeY[1]<>0 and RTSizeY = 0) {and mp <> 0} then begin
if mp > 0 then
sell ("HedgeLX") next bar at market
else if mp < 0 then
buytocover ("HedgeSX") next bar at market;
GVSetNamedDouble("GVRTSizeM", 0);
end;
//establish position
if (RTSizeZS[1]=0 and RTSizeZS<>0) and (RTSizeY[1]=0 and RTSizeY<>0) {and mp=0} then begin
if RTSizeZS > 0 then begin
sellshort ("HedgeSE") SizeM contracts next bar at market;
GVSetNamedDouble("GVRTSizeM", -1*SizeM);
end
else if RTSizeZS < 0 then begin
buy ("HedgeLE") SizeM contracts next bar at market;
GVSetNamedDouble("GVRTSizeM", SizeM);
end;
end;
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2958 times
Re: problem about GV functions for multi symbols trading
Hello yoyo2000,
The studies on the charts are calculated asynchronously. Sometimes Get command can be calculated before Set command using Global Variables. Please use the Print statement to check the read-write sequence of your codes.
The studies on the charts are calculated asynchronously. Sometimes Get command can be calculated before Set command using Global Variables. Please use the Print statement to check the read-write sequence of your codes.
Re: problem about GV functions for multi symbols trading
I use SleepEx function to make GV get funtion delay some time,but it doesn't work.
and i have no idea about the wrong of the 3th point of my problem,that's,
"3. when a position opens on symbol 2 or 3,it close immediately in one bar,not waiting for GV value change on symbol 1."
is something wrong with my exit logic ?
best regards.
and i have no idea about the wrong of the 3th point of my problem,that's,
"3. when a position opens on symbol 2 or 3,it close immediately in one bar,not waiting for GV value change on symbol 1."
is something wrong with my exit logic ?
best regards.
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: problem about GV functions for multi symbols trading
give this a tryhi,i got a problem about GV functions these days,and couldn't deal with it,please help.
...and the code for s1,s2,s3 are below.
GlobalVariables GV Latency Tester
viewtopic.php?f=5&t=10780&hilit=latency
Re: problem about GV functions for multi symbols trading
TJ,i'v try your GV latency tester,the delay of my transmmission is between 4 and 11,is it a big latency?
if the latency is too big,s2 and s3 couldn't get GV's realtime change,maybe this is the reason of missing some signal,do you have any way to minimize the latency?
if the latency is too big,s2 and s3 couldn't get GV's realtime change,maybe this is the reason of missing some signal,do you have any way to minimize the latency?
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: problem about GV functions for multi symbols trading
Your chart resolution is only 3 seconds, and yet your latency is 4 to 11 seconds.TJ,i'v try your GV latency tester,the delay of my transmmission is between 4 and 11,is it a big latency?
if the latency is too big,s2 and s3 couldn't get GV's realtime change,maybe this is the reason of missing some signal,do you have any way to minimize the latency?
Your signal is TWO to FOUR bars behind !!!
Can your strategy work with this delay?
You might have to rethink your method.
Re: problem about GV functions for multi symbols trading
yes,maybe latency is a big problem,and I should try to avoid the cumulative latency in my method,and set the time frame longer than latency.
BTW,TJ,your GV lantecy Tester info is below when I print it,why set once, but receive twice,which rec'd time result is the right one?
1.00 Sent Time \n =111852
1.00 Rec'd Time \n =111852\n Latency \n = 7
1.00 Rec'd Time \n =111852\n Latency \n = 51
best regards.
BTW,TJ,your GV lantecy Tester info is below when I print it,why set once, but receive twice,which rec'd time result is the right one?
1.00 Sent Time \n =111852
1.00 Rec'd Time \n =111852\n Latency \n = 7
1.00 Rec'd Time \n =111852\n Latency \n = 51
best regards.
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: problem about GV functions for multi symbols trading
what is your maxbarsback?yes,maybe latency is a big problem,and I should try to avoid the cumulative latency in my method,and set the time frame longer than latency.
BTW,TJ,your GV lantecy Tester info is below when I print it,why set once, but receive twice,which rec'd time result is the right one?
1.00 Sent Time \n =111852
1.00 Rec'd Time \n =111852\n Latency \n = 7
1.00 Rec'd Time \n =111852\n Latency \n = 51
best regards.
are all the sends received twice?
Re: problem about GV functions for multi symbols trading
my maxbarsback = 50
and most received twice,
seldom three times,and rare once
1.00 Rec'd Time \n =112112\n Latency \n = 5
1.00 Rec'd Time \n =112112\n Latency \n = 10
1.00 Sent Time \n =112122
1.00 Rec'd Time \n =112122\n Latency \n = 5
1.00 Rec'd Time \n =112122\n Latency \n = 10
1.00 Sent Time \n =112132
1.00 Rec'd Time \n =112132\n Latency \n = 5
1.00 Sent Time \n =112142
1.00 Rec'd Time \n =112132\n Latency \n = 11
1.00 Rec'd Time \n =112142\n Latency \n = 5
1.00 Rec'd Time \n =112142\n Latency \n = 11
1.00 Sent Time \n =112152
and most received twice,
seldom three times,and rare once
1.00 Rec'd Time \n =112112\n Latency \n = 5
1.00 Rec'd Time \n =112112\n Latency \n = 10
1.00 Sent Time \n =112122
1.00 Rec'd Time \n =112122\n Latency \n = 5
1.00 Rec'd Time \n =112122\n Latency \n = 10
1.00 Sent Time \n =112132
1.00 Rec'd Time \n =112132\n Latency \n = 5
1.00 Sent Time \n =112142
1.00 Rec'd Time \n =112132\n Latency \n = 11
1.00 Rec'd Time \n =112142\n Latency \n = 5
1.00 Rec'd Time \n =112142\n Latency \n = 11
1.00 Sent Time \n =112152
Re: problem about GV functions for multi symbols trading
could you please paste proper print info with command "print" of GV latency Tester?it's too wired.
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: problem about GV functions for multi symbols trading
This is not a One-to-One relationship.yes,maybe latency is a big problem,and I should try to avoid the cumulative latency in my method,and set the time frame longer than latency.
BTW,TJ,your GV lantecy Tester info is below when I print it,why set once, but receive twice,which rec'd time result is the right one?
1.00 Sent Time \n =111852
1.00 Rec'd Time \n =111852\n Latency \n = 7
1.00 Rec'd Time \n =111852\n Latency \n = 51
best regards.
The sender posts the value to GV, it is up to the receiver to retrieve the value.
When a tick comes in to the receiver chart, the indicator will go to GV and fetch the latest value on record, then compares it to the current time to arrive at the latency value.
The more ticks come in, the more print out you will see.
Re: problem about GV functions for multi symbols trading
i see,if sending chart's time frame is 10 s,and receiving chart's time frame is 5 s,then there should be 1 sending info and 2 receiving info.
TJ,you said,i could try a faster computer,I'v tried on another computer which is better than mine,but the latency are the same.could you tell me,according to your experience,on what computer(CPU,memory,and others),latency could be controlled under 2?
TJ,you said,i could try a faster computer,I'v tried on another computer which is better than mine,but the latency are the same.could you tell me,according to your experience,on what computer(CPU,memory,and others),latency could be controlled under 2?
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: problem about GV functions for multi symbols trading
A faster computer would help if and only if the cause of the latency is due to slow computer. You really have to look at the big picture -- the datafeed, the liquidity of the instruments, the resolution of the charts, the method of your analysis, etc. Developing a trading system is a thousand refinement refined one thousand times.i see,if sending chart's time frame is 10 s,and receiving chart's time frame is 5 s,then there should be 1 sending info and 2 receiving info.
TJ,you said,i could try a faster computer,I'v tried on another computer which is better than mine,but the latency are the same.could you tell me,according to your experience,on what computer(CPU,memory,and others),latency could be controlled under 2?
Re: problem about GV functions for multi symbols trading
yes,it's a hard work
for the case of GV function,i found that most of time,GV set function runs early,GV get function runs laterly,but some time,GV get function runs earlier than set function,do you have any tip for controlling the order to make GV get function always later than set function?
best regards.
for the case of GV function,i found that most of time,GV set function runs early,GV get function runs laterly,but some time,GV get function runs earlier than set function,do you have any tip for controlling the order to make GV get function always later than set function?
best regards.
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: problem about GV functions for multi symbols trading
GV, ADE and ELC, etc., are most useful on multiple charts of different resolutions.yes,it's a hard work
for the case of GV function,i found that most of time,GV set function runs early,GV get function runs laterly,but some time,GV get function runs earlier than set function,do you have any tip for controlling the order to make GV get function always later than set function?
best regards.
ie a slow chart as a sender, and faster chart as a receiver.
You can try this method: add the "Sender-Symbol" in the receiver chart as data2, and on your sender chart, add the "Receiver-symbol" as data2. Then you can control the triggering sequence.
Re: problem about GV functions for multi symbols trading
sorry,TJ,i can't catch your words.
for example,a 60s' bar chart as a sender,a 30s' bar chart as a receiver,intrabargeneration=false,so global variable update per min,and the value of this global variable is received twice per min,do you mean,trading only at first receiving?
and your case is spread trading on 2 symbols,how about trading on 3 symbols?
for example,buy symbol 1,and short symbol 2 and 3.
best regards.
for example,a 60s' bar chart as a sender,a 30s' bar chart as a receiver,intrabargeneration=false,so global variable update per min,and the value of this global variable is received twice per min,do you mean,trading only at first receiving?
and your case is spread trading on 2 symbols,how about trading on 3 symbols?
for example,buy symbol 1,and short symbol 2 and 3.
best regards.
- TJ
- Posts: 7752
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1034 times
- Been thanked: 2228 times
Re: problem about GV functions for multi symbols trading
You have to understand how the mechanics work, then decide on your strategy.sorry,TJ,i can't catch your words.
for example,a 60s' bar chart as a sender,a 30s' bar chart as a receiver,intrabargeneration=false,so global variable update per min,and the value of this global variable is received twice per min,do you mean,trading only at first receiving?
e.g. How many ticks are you getting from your sender chart? Do you know? Do you care? What is the ratio of ticks between the sender chart and the receiver chart? What are the timing differences? What happens when there is a no-data period (no trade) in the sender chart? Does the receiver chart keep on working?
I cannot answer your question, only you will know the answer after your careful study of the instruments and their behavior. You are on the right track... print statement is a useful tool, you should be able to find many critical information from your testing.
For inter-chart data transfer, the receiver chart should always the faster one.and your case is spread trading on 2 symbols,how about trading on 3 symbols?
for example,buy symbol 1,and short symbol 2 and 3.
best regards.