1m script is a signal script, keeping monitoring message sent by the 5m script, which is an indicator and sends a message to global space via GVsetNamedInt/GVgetNamedInt function pair.
If 5m sees a bullbar in a 5m chart, it sets a named value string "B5" to 1, likewise, if it sees a bearbar, it sets "S5" to 1. Otherwise, both are set to 0.
entry signal:
1m keeps pulling these two named values from global space, if it sees a bullbar in a 1m chart and also gets B5=1, a buy order is issued; if it sees a bearbar and gets S5=1, a shortsell order is issued.
exit signal:
exit on reverse entry signal.
Intraordergeneration set to be TRUE in both scripts.
5m indicator:
Code: Select all
[IntraBarOrderGeneration = true]
if C-O>0 then begin
GVSetNamedInt("B5",1);
end
else begin
GVSetNamedInt("B5",0);
end;
if O-C>0 then begin
GVSetNamedInt("S5",1);
end
else begin
GVSetNamedInt("S5",0);
end;
1m signal script:
Code: Select all
[IntraBarOrderGeneration = true]
B5sig=GVGetNamedInt("B5",-999);
S5sig=GVGetNamedInt("S5",-999);
if tradingtime and B5sig=1 then begin
if marketposition=0 and C-O>0 then
buy 1 contract next bar at market;
if marketposition=-1 then
buytocover 1 contract next bar at market;
end;
if tradingtime and S5sig=1 then begin
if marketposition=0 and O-C>0 then
sellshort 1 contract next bar at market;
if marketposition=1 then
sell 1 contract next bar at market;
end;
With such a loose entry condition, I was expecting many trades on backtesting. However, none was observed. More perplexing, it worked on replay mode and realtime. Anyone has any clue? thanks.
-K