dr.B Trad Start Filter.cs by dr.B

4124 downloads / 4465 views / Created: 20.06.2013
 Average Rating: 5

Indicator Description

My tiny contribution to this great project:
This is a tool to compare FST and FSB results. If you have some FST real data and want to compare it to predicted FSB numbers, than ideally you want to start running a trade in FSB at same time you did so in FST. This filter lets you do just that. Since I am not a programmer, I am just a newbie, a more experienced coder might be able to improve on the code or ! ;). Any criticism or suggestions are welcome of course.
I like to give a Big Thanks to great guys like Papov, Krog and Footon they have pointed me in the right directions when I needed their help and I am sure that in future they will do it again.
Please give feedback if you like it or not. Enjoy ...

Comments

just a note, if it appears too look "funky" it's likly that you have a setup with multiple logic groups. in that case make sure you set the filter to "All" :)
ps thanks for the rating whoever didit =)
dr.B
//============================================================== // Forex Strategy Builder // Copyright © Miroslav Popov. All rights reserved. //============================================================== // THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE. //============================================================== using System; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { public class drB_TradStartFilter : Indicator { public drB_TradStartFilter() { IndicatorName = "dr.B Trad Start Filter"; PossibleSlots = SlotTypes.OpenFilter; IsGeneratable = false; if (IsBacktester) WarningMessage = "This indicator is designed to be used in FSB only. It has no relevance in the FST."; IndicatorAuthor = "dr.B; dr.bartnik@gmail.com"; IndicatorVersion = "2.0"; IndicatorDescription = "Compares FST and FSB Results for specified time: it is for FSB."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // Setting up the indicator parameters IndParam.IndicatorType = TypeOfIndicator.DateTime; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new string[] { "Do not open positions before", "Do not open positions after" }; IndParam.ListParam[0].Index = 0; IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index]; IndParam.ListParam[0].Enabled = true; IndParam.ListParam[0].ToolTip = "Logic of application of the indicator."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "Year"; IndParam.NumParam[0].Value = 2013; IndParam.NumParam[0].Min = 1950; IndParam.NumParam[0].Max = 2100; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "The Year."; IndParam.NumParam[1].Caption = "Month"; IndParam.NumParam[1].Value = 1; IndParam.NumParam[1].Min = 1; IndParam.NumParam[1].Max = 12; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "The Month."; IndParam.NumParam[2].Caption = "Day"; IndParam.NumParam[2].Value = 1; IndParam.NumParam[2].Min = 1; IndParam.NumParam[2].Max = 31; IndParam.NumParam[2].Enabled = true; IndParam.NumParam[2].ToolTip = "The Day. The days outside the month are converted (eg, Feb 31 becomes Feb 28)"; IndParam.NumParam[4].Caption = "Hour"; IndParam.NumParam[4].Value = 0; IndParam.NumParam[4].Min = 0; IndParam.NumParam[4].Max = 23; IndParam.NumParam[4].Enabled = true; IndParam.NumParam[4].ToolTip = "The Hour.\a 24 Hour Clock"; IndParam.NumParam[5].Caption = "Minute"; IndParam.NumParam[5].Value = 0; IndParam.NumParam[5].Min = 0; IndParam.NumParam[5].Max = 59; IndParam.NumParam[5].Enabled = true; IndParam.NumParam[5].ToolTip = "The Minute."; // The CheckBox parameters IndParam.CheckParam[0].Caption = "Check to Only Display the Tradig Period "; IndParam.CheckParam[0].Enabled = true; IndParam.CheckParam[0].ToolTip = "If Checked, Will Show Only the Period Selected Above. (with 10 Bars Min.)"; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var year = (int) IndParam.NumParam[0].Value; var month = (int) IndParam.NumParam[1].Value; // if ((int) IndParam.NumParam[2].Value >= 29) {if ((int) IndParam.NumParam[1].Value == 2) IndParam.NumParam[2].Value = 28; IndParam.NumParam[2].Max = 28; } else if ((int) IndParam.NumParam[2].Value >= 30) { if( (IndParam.NumParam[1].Value == 4)||(IndParam.NumParam[1].Value == 6)||(IndParam.NumParam[1].Value == 9)||(IndParam.NumParam[1].Value == 11)) IndParam.NumParam[2].Value = 30; IndParam.NumParam[2].Max = 30; } var day = (int) IndParam.NumParam[2].Value; var hour = (int)IndParam.NumParam[4].Value; var minute = (int)IndParam.NumParam[5].Value; // alows for the trade to start at the time specified instead of one bar after if (minute == 0) { minute = 60; if (hour == 0) hour=24; hour =hour -1; } if(minute != 0) minute = (minute-1); var keyDate = new DateTime(year, month, day, hour, minute, 0); int chview = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = 0; var values = new double[Bars]; // Calculation of the logic. if (IsBacktester) { if(chview !=0) { switch (IndParam.ListParam[0].Text) { case "Do not open positions after": for (int bar = firstBar; bar < Bars; bar++) if (Time[bar] < keyDate) values[bar] = 1; break; case "Do not open positions before": for (int bar = firstBar; bar < Bars; bar++) if (Time[bar] >= keyDate) { firstBar = bar; break; } firstBar = Math.Min(firstBar, Bars - 10); for (int bar = firstBar; bar < Bars; bar++) values[bar] = 1; break; } } else if (chview ==0) { switch (IndParam.ListParam[0].Text) { case "Do not open positions after": for (int bar = firstBar; bar < Bars; bar++) if (Time[bar] < keyDate) values[bar] = 1; break; case "Do not open positions before": int startBar =Bars; for (int bar = firstBar; bar < Bars; bar++) if (Time[bar] >= keyDate) { startBar = bar; break; } for (int bar = startBar; bar < Bars; bar++) values[bar] = 1; break; } } } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Open Long Allowed ", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = values }; Component[1] = new IndicatorComp { CompName = "Open Short Allowed ", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = values }; } public override void SetDescription() { if (!IsBacktester) { EntryFilterLongDescription = "A back tester limitation. It hasn't effect on the trade."; EntryFilterShortDescription = "A back tester limitation. It hasn't effect on the trade."; return; } var year = (int) IndParam.NumParam[0].Value; var month = (int) IndParam.NumParam[1].Value; var day = (int) IndParam.NumParam[2].Value; var hour = (int) IndParam.NumParam[4].Value; var minute = (int) IndParam.NumParam[5].Value; var keyDate = new DateTime(year, month, day, hour, minute, 0); EntryFilterLongDescription = "(a back tester limitation) Do not open positions "; EntryFilterShortDescription = "(a back tester limitation) Do not open positions "; switch (IndParam.ListParam[0].Text) { case "Do not open positions before": EntryFilterLongDescription += "before " + keyDate.ToLongDateString(); EntryFilterShortDescription += "before " + keyDate.ToLongDateString(); break; case "Do not open positions after": EntryFilterLongDescription += "after " + keyDate.ToLongDateString(); EntryFilterShortDescription += "after " + keyDate.ToLongDateString(); break; } } public override string ToString() { return IndicatorName; } } }
Risk warning: Forex, spread bets and CFD are leveraged products. They may not be suitable for you as they carry a high degree of risk to your capital and you can lose more than your initial investment. You should ensure you understand all of the risks.
Copyright © 2006 - 2024, Forex Software Ltd.;