Chart #2 is basically a slave chart that contains only the Data2 instrument. The strategy running on Chart #2 does no calculations--it simply waits for order signals and parameters to be passed to it via global variables and then it executes orders on Data2 of the spread pair.
I downloaded the Global Variable 2.2 word document and structured my code after its examples, but still must be missing some things:
1. The "return" variables that I am using in setting named integer and named Boolean global variables only return zero--even though the GVs are being created.
2. It's not clear to me whether when using the GV wrappers you still need to include a LastBarOnChart critierion.
3. Because the _Rtn variables are always = 0, the order execution does not happen for Data1. When I comment out the test the exit order is executed.
4. Can a local variable use the same name as a global variable?
5. Are there any housekeeping best practices when it comes to resetting global variables?
Here's the test Chart #1 GV setting code:
Code: Select all
{*************************************************************************************************************************************************************
Name : $Arb_Exit_Order_EMD_GV_Test
Last Modified Date : 08/26/2012
**************************************************************************************************************************************************************}
[IntrabarOrderGeneration = true];
//************************************************************************************************************************************************************
// inputs and variable initialization section
//************************************************************************************************************************************************************
inputs:
Exit_Target (188.0),
Position_Size (1),
Trade_Direction ("Long"),
StartTime (930);
variables:
Delta (0),
Get_GV_Position_Size (0),
Get_GV_Trigger_Long_Target (false),
int GV_Position_Size_Rtn (0),
int GV_Trigger_Long_Target_Rtn (0);
//************************************************************************************************************************************************************
// calculations
//************************************************************************************************************************************************************
Delta = close data1 - close data2;
//************************************************************************************************************************************************************
// target order execution section
//************************************************************************************************************************************************************
if LastBarOnChart then begin
If CurrentTime >= StartTime then begin
if Trade_Direction = "Long" and Delta >= Exit_Target then begin
GV_Position_Size_Rtn = GVSetNamedInt("GV_Position_Size",Position_Size); // set global variable to position size value
GV_Trigger_Long_Target_Rtn = GVSetNamedBool("GV_Trigger_Long_Target",True); // set long exit trigger global variable to true
if GV_Position_Size_Rtn > 0 and GV_Trigger_Long_Target_Rtn > 0 then begin // test for successful write of global variable before executing
sell Position_Size shares next bar at market;
end;
Get_GV_Position_Size = GVGetNamedInt("GV_Position_Size",-9999); // for output to see if GV is created
Get_GV_Trigger_Long_Target = GVGetNamedBool("GV_Trigger_Long_Target"); // for output to see if GV is created
end;
end;
end;
//************************************************************************************************************************************************************
// diagnostic print section
//************************************************************************************************************************************************************
Print(
"Date= ", date,
" Time= ", time,
" Delta= ", Delta,
" Exit_Target= ", Exit_Target,
" Position_Size= ", Position_Size,
" Get_GV_Position_Size= ", Get_GV_Position_Size,
" Get_GV_Targ_Trigger_Long= ", Get_GV_Trigger_Long_Target,
" GV_Position_Size_Rtn= ", GV_Position_Size_Rtn,
" GV_Trigger_Long_Target_Rtn= ", GV_Trigger_Long_Target_Rtn
);