/ Published in: C#
https://community.tradestation.com/Discussions/Topic.aspx?Topic_ID=133749&SearchTerm=&txtExactMatch=
https://community.tradestation.com/Discussions/DATA/20130724211539Strategy_Builder.pdf
https://community.tradestation.com/Discussions/DATA/20130724211539Strategy_Builder.pdf
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
{ 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. } { 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. } { Set up Namespaces } using elsystem.windows.forms; using elsystem.drawing; { Declare Inputs } inputs: FilterCriteria(0), TriggerCriteria(0), ExitCriteria(0), FC1_MaLen1(50), FC1_MaLen2(200), FC2_PctRLen(50), FC2_PctRTreshold(50), FC3_DMILen(50), TC1_MaLen1(20), TC1_MaLen2(50), TC2_MaLen(20), TC3_MOLen(20), XC0_BSE(20), XC1_ATRLen(20), XC1_ATRs(2), XC2_MALen(20), XC3_MOLen(20), ADXLength(14), //Part of HALT if ADX is less than 20. MinADX(20); //Part of HALT if ADX is less than 20. { Define Variables } vars: FC1_MaVal1(0), FC1_MaVal2(0), FC2_PctRVal(0), FC3_DMIPlus(0), FC3_DMIMinus(0), TC1_MaVal1(0), TC1_MaVal2(0), TC2_MaVal(0), TC3_MOVal(0), XC1_ATR(0), XC1_ATRVal(0), XC2_MAVal(0), XC3_MOVal(0), FCCond(False), MP(0); vars: ADXOK(false); //Part of HALT if ADX is less than 20. vars: Form SBForm( Null ), Label SBLabel1(Null), Label SBLabel2(Null ), Label SBLabel3(Null), Label SBLabel4(Null), Label SBLabel5(Null), Font SBTitle(Null); method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args ) var: string tempstr; begin { Define "If" Statements } If Getappinfo(aiOptimizing) = 0 then begin SBForm = form.create("StrategyBuilder", 1080, 105); SBLabel1 = Label.Create("Strategy Builder (Long Entry Only)", 720, 18); SBLabel1.Location( 1,1 ); SBTitle = Font.Create("",8,fontstyle.bold); SBLabel1.Font = SBTitle; SBLabel2 = Label.Create("", 720, 18); tempstr = "Current Input Settings:( Filter Criteria = " + numtostr(FilterCriteria,0) + " / Trigger Criteria = " + numtostr(TriggerCriteria,0) + " / Exit Criteria = " + numtostr(ExitCriteria,0) + " )"; SBLabel2.Text = tempstr; SBLabel2.Location( 5,19 ); SBLabel2.Font = SBTitle; tempstr = "Filter Inputs: 0 = No Filter, " + "1 = " + numtostr(FC1_MaLen1,0) + " MovAvg > " + numtostr(FC1_MaLen2,0) + " MovAvg, " + "2 = " + numtostr(FC2_PctRLen,0) + " %R > " + numtostr(FC2_PctRTreshold,0) + ", " + "3 = " + numtostr(FC3_DMILen,0) + " DMI+ > " + numtostr(FC3_DMILen,0) + " DMI-"; SBLabel3 = Label.Create("", 720, 18); SBLabel3.Text = tempstr; SBLabel3.Location( 10,38 ); tempstr = "Trigger Inputs: 0 = Bar Close, " + "1 = " + numtostr(TC1_MaLen1,0) + " MovAvg Xabove " + numtostr(TC1_MaLen2,0) + " MovAvg, " + "2 = Low Xabove " + numtostr(TC2_MaLen,0) + " MovAvg ofHighs, " + "3 = " + numtostr(TC3_MOLen,0) + " MomentumAvg Xabove 0"; SBLabel4 = Label.Create("", 720, 18); SBLabel4.Text = tempstr; SBLabel4.Location( 10,57 ); tempstr = "Exit Inputs: 0 = " + numtostr(XC0_BSE,0) + " BarsSinceEntry " + "1 = " + numtostr(XC1_ATRLen,0) + " ATR Trails " + numtostr(XC1_ATRs,0) + " ATRs, " + "2 = High Xbelow " + numtostr(XC2_MALen,0) + " MovAvg ofLows, " + "3 = " + numtostr(XC3_MOLen,0) + " MomentumAvg Xbelow 0"; SBLabel5 = Label.Create("", 720, 18); SBLabel5.Text = tempstr; SBLabel5.Location( 10,76 ); SBForm.AddControl(SBLabel1); SBForm.AddControl(SBLabel2); SBForm.AddControl(SBLabel3); SBForm.AddControl(SBLabel4); SBForm.AddControl(SBLabel5); SBForm.Dock = DockStyle.bottom; SBForm.show(); end; end; ADXOK = ADX(ADXLength) >= MinADX; //ADX Calculation, Part of HALT if ADX is less than 20. If FilterCriteria = 1 then begin FC1_MaVal1 = Average(Close, FC1_MaLen1); FC1_MaVal2 = Average(Close, FC1_MaLen2); end; If FilterCriteria = 2 then FC2_PctRVal = PercentR(FC2_PctRLen); If FilterCriteria = 3 then begin FC3_DMIPlus = DMIPLus(FC3_DMILen); FC3_DMIMinus = DMIMinus(FC3_DMILen); end; If TriggerCriteria = 1 then begin TC1_MaVal1 = Average(Close, TC1_MaLen1); TC1_MaVal2 = Average(Close, TC1_MaLen2); end; If TriggerCriteria = 2 then TC2_MaVal = Average(Close, TC2_MaLen); If TriggerCriteria = 3 then TC3_MOVal = Average(Momentum(Close, TC3_MOLen),3); If ExitCriteria = 1 then begin XC1_ATR = AvgTrueRange(XC1_ATRLen); XC1_ATRVal = XC1_ATR * XC1_ATRs; end; If ExitCriteria = 2 then XC2_MAVal = Average(Close, XC2_MALen); If ExitCriteria = 3 then XC3_MOVal = Average(Momentum(Close, XC3_MOLen),3); SetStopShare; MP = MarketPosition; Switch(FilterCriteria) Begin Case 0: FCCond = TRUE; Case 1: FCCond = FC1_MaVal1 > FC1_MaVal2; Case 2: FCCond = FC2_PctRVal > FC2_PctRTreshold; Case 3: FCCond = FC3_DMIPlus > FC3_DMIMinus; Default: FCCond = FALSE; end; { Define "Switch" Statements } Switch(TriggerCriteria) Begin Case 0: if MP = 0 AND FCCond and ADXOK then Buy("LE") this bar on Close; //HALT if ADX is less than 20. Case 1: if MP = 0 AND FCCond and ADXOK AND TC1_MaVal1 > TC1_MaVal2 then Buy("Avgx LE") this bar on Close; Case 2: if MP = 0 AND FCCond and ADXOK AND Low > TC2_MaVal then Buy("Lx LE") this bar on Close; Case 3: if MP = 0 AND FCCond and ADXOK AND TC3_MOVal > 0 then Buy("Mox LE") this bar on Close; Default: FCCond = FALSE; end; Switch(ExitCriteria) Begin Case 0: If MP = 1 AND BarsSinceEntry >= XC0_BSE then Sell("BSE LX") this bar on Close; Case 1: If MP = 1 then Setdollartrailing(XC1_ATRVal * BigPointValue); Case 2: If MP = 1 AND High Crosses Below XC2_MAVal then Sell("Hx LX") this bar on Close; Case 3: If MP = 1 AND XC3_MOVal Crosses Below 0 then Sell("Mox LX") this bar on Close; Default: SetExitonClose; end;