Posted By

tedpenner on 04/27/14


Tagged


Versions (?)

Tradestation Strategy Builder v1.0 EL Code


 / Published in: C#
 

https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=133749&SearchTerm=&txtExactMatch=

https://community.tradestation.com/Discussions/DATA/20130724211539Strategy_Builder.pdf

  1. { Doug McCrary with TS helped me fix the code to reflect my ADX Halt trading criteria. He said that he thought the builder was made by Michael Burke in Forida but wasn't absolutely positive. }
  2.  
  3. { Properties Initialized > Choose Value AnalysisTechnique_Initialized which refers to the method in the code. This will bring up the winform and in an uncommon way of doing it. }
  4.  
  5. { Set up Namespaces }
  6. using elsystem.windows.forms;
  7. using elsystem.drawing;
  8.  
  9. { Declare Inputs }
  10. inputs:
  11. FilterCriteria(0),
  12. TriggerCriteria(0),
  13. ExitCriteria(0),
  14. FC1_MaLen1(50), FC1_MaLen2(200), FC2_PctRLen(50), FC2_PctRTreshold(50), FC3_DMILen(50),
  15. TC1_MaLen1(20), TC1_MaLen2(50), TC2_MaLen(20), TC3_MOLen(20),
  16. XC0_BSE(20), XC1_ATRLen(20), XC1_ATRs(2), XC2_MALen(20), XC3_MOLen(20),
  17. ADXLength(14), //Part of HALT if ADX is less than 20.
  18. MinADX(20); //Part of HALT if ADX is less than 20.
  19. { Define Variables }
  20.  
  21. vars:
  22. FC1_MaVal1(0), FC1_MaVal2(0), FC2_PctRVal(0), FC3_DMIPlus(0), FC3_DMIMinus(0),
  23. TC1_MaVal1(0), TC1_MaVal2(0), TC2_MaVal(0), TC3_MOVal(0),
  24. XC1_ATR(0), XC1_ATRVal(0), XC2_MAVal(0), XC3_MOVal(0),
  25. FCCond(False), MP(0);
  26.  
  27. vars:
  28. ADXOK(false); //Part of HALT if ADX is less than 20.
  29.  
  30. vars: Form SBForm( Null ), Label SBLabel1(Null), Label SBLabel2(Null ),
  31. Label SBLabel3(Null), Label SBLabel4(Null), Label SBLabel5(Null),
  32. Font SBTitle(Null);
  33.  
  34. method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
  35.  
  36. var: string tempstr;
  37. begin
  38.  
  39. { Define "If" Statements }
  40. If Getappinfo(aiOptimizing) = 0 then begin
  41. SBForm = form.create("StrategyBuilder", 1080, 105);
  42. SBLabel1 = Label.Create("Strategy Builder (Long Entry Only)", 720, 18);
  43. SBLabel1.Location( 1,1 );
  44. SBTitle = Font.Create("",8,fontstyle.bold);
  45. SBLabel1.Font = SBTitle;
  46. SBLabel2 = Label.Create("", 720, 18);
  47. tempstr = "Current Input Settings:( Filter Criteria = " + numtostr(FilterCriteria,0) +
  48. " / Trigger Criteria = " + numtostr(TriggerCriteria,0) +
  49. " / Exit Criteria = " + numtostr(ExitCriteria,0) + " )";
  50. SBLabel2.Text = tempstr;
  51. SBLabel2.Location( 5,19 );
  52. SBLabel2.Font = SBTitle;
  53. tempstr = "Filter Inputs: 0 = No Filter, " +
  54. "1 = " + numtostr(FC1_MaLen1,0) + " MovAvg > " +
  55. numtostr(FC1_MaLen2,0) + " MovAvg, " +
  56. "2 = " + numtostr(FC2_PctRLen,0) + " %R > " +
  57. numtostr(FC2_PctRTreshold,0) + ", " +
  58. "3 = " + numtostr(FC3_DMILen,0) + " DMI+ > " +
  59. numtostr(FC3_DMILen,0) + " DMI-";
  60. SBLabel3 = Label.Create("", 720, 18);
  61. SBLabel3.Text = tempstr;
  62. SBLabel3.Location( 10,38 );
  63. tempstr = "Trigger Inputs: 0 = Bar Close, " +
  64. "1 = " + numtostr(TC1_MaLen1,0) + " MovAvg Xabove " +
  65. numtostr(TC1_MaLen2,0) + " MovAvg, " +
  66. "2 = Low Xabove " + numtostr(TC2_MaLen,0) + " MovAvg ofHighs, " +
  67. "3 = " + numtostr(TC3_MOLen,0) + " MomentumAvg Xabove 0";
  68. SBLabel4 = Label.Create("", 720, 18);
  69. SBLabel4.Text = tempstr;
  70. SBLabel4.Location( 10,57 );
  71. tempstr = "Exit Inputs: 0 = " +
  72. numtostr(XC0_BSE,0) + " BarsSinceEntry " +
  73. "1 = " + numtostr(XC1_ATRLen,0) + " ATR Trails " +
  74. numtostr(XC1_ATRs,0) + " ATRs, " +
  75. "2 = High Xbelow " + numtostr(XC2_MALen,0) + " MovAvg ofLows, " +
  76. "3 = " + numtostr(XC3_MOLen,0) + " MomentumAvg Xbelow 0";
  77. SBLabel5 = Label.Create("", 720, 18);
  78. SBLabel5.Text = tempstr;
  79. SBLabel5.Location( 10,76 );
  80. SBForm.AddControl(SBLabel1);
  81. SBForm.AddControl(SBLabel2);
  82. SBForm.AddControl(SBLabel3);
  83. SBForm.AddControl(SBLabel4);
  84. SBForm.AddControl(SBLabel5);
  85. SBForm.Dock = DockStyle.bottom;
  86. SBForm.show();
  87. end;
  88.  
  89. end;
  90. ADXOK = ADX(ADXLength) >= MinADX; //ADX Calculation, Part of HALT if ADX is less than 20.
  91. If FilterCriteria = 1 then begin
  92. FC1_MaVal1 = Average(Close, FC1_MaLen1);
  93. FC1_MaVal2 = Average(Close, FC1_MaLen2);
  94. end;
  95.  
  96. If FilterCriteria = 2 then
  97. FC2_PctRVal = PercentR(FC2_PctRLen);
  98. If FilterCriteria = 3 then begin
  99. FC3_DMIPlus = DMIPLus(FC3_DMILen);
  100. FC3_DMIMinus = DMIMinus(FC3_DMILen);
  101. end;
  102.  
  103. If TriggerCriteria = 1 then begin
  104. TC1_MaVal1 = Average(Close, TC1_MaLen1);
  105. TC1_MaVal2 = Average(Close, TC1_MaLen2);
  106. end;
  107.  
  108. If TriggerCriteria = 2 then
  109. TC2_MaVal = Average(Close, TC2_MaLen);
  110. If TriggerCriteria = 3 then
  111. TC3_MOVal = Average(Momentum(Close, TC3_MOLen),3);
  112. If ExitCriteria = 1 then begin
  113. XC1_ATR = AvgTrueRange(XC1_ATRLen);
  114. XC1_ATRVal = XC1_ATR * XC1_ATRs;
  115. end;
  116.  
  117. If ExitCriteria = 2 then
  118. XC2_MAVal = Average(Close, XC2_MALen);
  119. If ExitCriteria = 3 then
  120. XC3_MOVal = Average(Momentum(Close, XC3_MOLen),3);
  121. SetStopShare;
  122. MP = MarketPosition;
  123. Switch(FilterCriteria)
  124. Begin
  125. Case 0: FCCond = TRUE;
  126. Case 1: FCCond = FC1_MaVal1 > FC1_MaVal2;
  127. Case 2: FCCond = FC2_PctRVal > FC2_PctRTreshold;
  128. Case 3: FCCond = FC3_DMIPlus > FC3_DMIMinus;
  129. Default: FCCond = FALSE;
  130. end;
  131.  
  132. { Define "Switch" Statements }
  133. Switch(TriggerCriteria)
  134. Begin
  135. Case 0: if MP = 0 AND FCCond and ADXOK then Buy("LE") this bar on Close; //HALT if ADX is less than 20.
  136. Case 1: if MP = 0 AND FCCond and ADXOK AND TC1_MaVal1 > TC1_MaVal2 then
  137. Buy("Avgx LE") this bar on Close;
  138. Case 2: if MP = 0 AND FCCond and ADXOK AND Low > TC2_MaVal then
  139. Buy("Lx LE") this bar on Close;
  140. Case 3: if MP = 0 AND FCCond and ADXOK AND TC3_MOVal > 0 then
  141. Buy("Mox LE") this bar on Close;
  142. Default: FCCond = FALSE;
  143. end;
  144.  
  145. Switch(ExitCriteria)
  146. Begin
  147. Case 0: If MP = 1 AND BarsSinceEntry >= XC0_BSE then
  148. Sell("BSE LX") this bar on Close;
  149. Case 1: If MP = 1 then Setdollartrailing(XC1_ATRVal * BigPointValue);
  150. Case 2: If MP = 1 AND High Crosses Below XC2_MAVal then
  151. Sell("Hx LX") this bar on Close;
  152. Case 3: If MP = 1 AND XC3_MOVal Crosses Below 0 then
  153. Sell("Mox LX") this bar on Close;
  154. Default: SetExitonClose;
  155. end;

Report this snippet  

You need to login to post a comment.