Spud Fibo v3 by footon

4514 downloads / 5546 views / Created: 24.05.2013
 Average Rating: 5

Indicator Description

Spud Fibo v3

Forum link: Footon's indi corner

Comments

Thanks for all the hard work you put in. Any chance of getting the MQL code for this wonderful indi? Cheers
//============================================================== // Forex Strategy Builder // Copyright (c) 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 System.Drawing; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { public class SpudFibo : Indicator { public SpudFibo() { IndicatorName = "Spud Fibo v3"; PossibleSlots = SlotTypes.Open | SlotTypes.Close; IndicatorAuthor = "Footon"; IndicatorVersion = "2.0"; IndicatorDescription = "Footon's indi corner: custom indicators for FSB and FST."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; IndParam.IndicatorType = TypeOfIndicator.Additional; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; if (SlotType == SlotTypes.Open) IndParam.ListParam[0].ItemList = new string[] { "Enter long at Fibo0 (short at Fibo100)", "Enter long at Fibo236 (short at Fibo764)", "Enter long at Fibo382 (short at Fibo618)", "Enter the market at the Fibo50", "Enter long at Fibo618 (short at Fibo382)", "Enter long at Fibo764 (short at Fibo236)", "Enter long at Fibo100 (short at Fibo0)", }; else if (SlotType == SlotTypes.Close) IndParam.ListParam[0].ItemList = new string[] { "Exit long at Fibo0 (short at Fibo100)", "Exit long at Fibo236 (short at Fibo764)", "Exit long at Fibo382 (short at Fibo618)", "Exit the market at the Fibo50", "Exit long at Fibo618 (short at Fibo382)", "Exit long at Fibo764 (short at Fibo236)", "Exit long at Fibo100 (short at Fibo0)", }; else IndParam.ListParam[0].ItemList = new string[] { "Not Defined" }; 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."; IndParam.ListParam[1].Caption = "Base price"; IndParam.ListParam[1].ItemList = new string[] { "One day", "One bar" }; IndParam.ListParam[1].Index = 0; IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index]; IndParam.ListParam[1].Enabled = true; IndParam.ListParam[1].ToolTip = "Base price"; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "Vertical shift"; IndParam.NumParam[0].Value = 0; IndParam.NumParam[0].Max = +2000; IndParam.NumParam[0].Min = -2000; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "A vertical shift above the Resistance and below the Support levels."; // The CheckBox parameters IndParam.CheckParam[0].Caption = "Use previous bar value"; IndParam.CheckParam[0].Enabled = true; IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar."; return; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters double dShift = IndParam.NumParam[0].Value * Point; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = 1; double[] adFibo0 = new double[Bars]; double[] adFibo236 = new double[Bars]; double[] adFibo382 = new double[Bars]; double[] adFibo50 = new double[Bars]; double[] adFibo618 = new double[Bars]; double[] adFibo764 = new double[Bars]; double[] adFibo100 = new double[Bars]; double[] adH = new double[Bars]; double[] adL = new double[Bars]; if (IndParam.ListParam[1].Text == "One bar" || Period == DataPeriod.D1 || Period == DataPeriod.W1) { adH = High; adL = Low; } else { iPrvs = 0; adH[0] = 0; adL[0] = 0; double dTop = double.MinValue; double dBottom = double.MaxValue; for (int iBar = 1; iBar < Bars; iBar++) { if (High[iBar - 1] > dTop) dTop = High[iBar - 1]; if (Low[iBar - 1] < dBottom) dBottom = Low[iBar - 1]; if (Time[iBar].Day != Time[iBar - 1].Day) { adH[iBar] = dTop; adL[iBar] = dBottom; dTop = double.MinValue; dBottom = double.MaxValue; } else { adH[iBar] = adH[iBar - 1]; adL[iBar] = adL[iBar - 1]; } } // first Bar for (int iBar = 1; iBar < Bars; iBar++) { if (Time[iBar].Day != Time[iBar - 1].Day) { iFirstBar = iBar; break; } } } for (int iBar = iFirstBar; iBar < Bars; iBar++) { adFibo0 [iBar] = adH[iBar]; adFibo236[iBar] = adH[iBar] - (adH[iBar] - adL[iBar]) * 0.236; adFibo382[iBar] = adH[iBar] - (adH[iBar] - adL[iBar]) * 0.382; adFibo50 [iBar] = adH[iBar] - (adH[iBar] - adL[iBar]) * 0.500; adFibo618[iBar] = adH[iBar] - (adH[iBar] - adL[iBar]) * 0.618; adFibo764[iBar] = adH[iBar] - (adH[iBar] - adL[iBar]) * 0.764; adFibo100[iBar] = adL[iBar]; } Component = new IndicatorComp[9]; for (int iComp = 0; iComp < 7; iComp++) { Component[iComp] = new IndicatorComp(); Component[iComp].ChartType = IndChartType.Dot; Component[iComp].ChartColor = Color.Violet; Component[iComp].DataType = IndComponentType.IndicatorValue; Component[iComp].FirstBar = iFirstBar; } Component[3].ChartColor = Color.Blue; Component[0].Value = adFibo0; Component[1].Value = adFibo236; Component[2].Value = adFibo382; Component[3].Value = adFibo50; Component[4].Value = adFibo618; Component[5].Value = adFibo764; Component[6].Value = adFibo100; Component[0].CompName = "Fibo0"; Component[1].CompName = "Fibo236"; Component[2].CompName = "Fibo382"; Component[3].CompName = "Fibo50"; Component[4].CompName = "Fibo618"; Component[5].CompName = "Fibo764"; Component[6].CompName = "Fibo100"; Component[7] = new IndicatorComp(); Component[7].ChartType = IndChartType.NoChart; Component[7].FirstBar = iFirstBar; Component[7].Value = new double[Bars]; Component[8] = new IndicatorComp(); Component[8].ChartType = IndChartType.NoChart; Component[8].FirstBar = iFirstBar; Component[8].Value = new double[Bars]; if (SlotType == SlotTypes.Open) { Component[7].CompName = "Long position entry price"; Component[7].DataType = IndComponentType.OpenLongPrice; Component[8].CompName = "Short position entry price"; Component[8].DataType = IndComponentType.OpenShortPrice; } else if (SlotType == SlotTypes.Close) { Component[7].CompName = "Long position closing price"; Component[7].DataType = IndComponentType.CloseLongPrice; Component[8].CompName = "Short position closing price"; Component[8].DataType = IndComponentType.CloseShortPrice; } switch (IndParam.ListParam[0].Text) { case "Enter long at Fibo0 (short at Fibo100)": case "Exit long at Fibo0 (short at Fibo100)": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[7].Value[iBar] = adFibo0[iBar - iPrvs] + dShift; Component[8].Value[iBar] = adFibo100[iBar - iPrvs] - dShift; } break; case "Enter long at Fibo236 (short at Fibo764)": case "Exit long at Fibo236 (short at Fibo764)": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[7].Value[iBar] = adFibo236[iBar - iPrvs] + dShift; Component[8].Value[iBar] = adFibo764[iBar - iPrvs] - dShift; } break; case "Enter long at Fibo382 (short at Fibo618)": case "Exit long at Fibo382 (short at Fibo618)": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[7].Value[iBar] = adFibo382[iBar - iPrvs] + dShift; Component[8].Value[iBar] = adFibo618[iBar - iPrvs] - dShift; } break; //--------------------------------------------------------------------- case "Enter the market at the Fibo50": case "Exit the market at the Fibo50": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[7].Value[iBar] = adFibo50[iBar - iPrvs] + dShift; Component[8].Value[iBar] = adFibo50[iBar - iPrvs] - dShift; } break; //--------------------------------------------------------------------- case "Enter long at Fibo618 (short at Fibo382)": case "Exit long at Fibo618 (short at Fibo382)": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[7].Value[iBar] = adFibo618[iBar - iPrvs] - dShift; Component[8].Value[iBar] = adFibo382[iBar - iPrvs] + dShift; } break; case "Enter long at Fibo764 (short at Fibo236)": case "Exit long at Fibo764 (short at Fibo236)": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[7].Value[iBar] = adFibo764[iBar - iPrvs] - dShift; Component[8].Value[iBar] = adFibo236[iBar - iPrvs] + dShift; } break; case "Enter long at Fibo100 (short at Fibo0)": case "Exit long at Fibo100 (short at Fibo0)": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[7].Value[iBar] = adFibo100[iBar - iPrvs] - dShift; Component[8].Value[iBar] = adFibo0[iBar - iPrvs] + dShift; } break; default: break; } return; } /// /// Sets the indicator logic description /// public override void SetDescription() { int iShift = (int)IndParam.NumParam[0].Value; string sUpperTrade; string sLowerTrade; if (iShift > 0) { sUpperTrade = iShift + " pips above the "; sLowerTrade = iShift + " pips below the "; } else if (iShift == 0) { sUpperTrade = "at the "; sLowerTrade = "at the "; } else { sUpperTrade = -iShift + " pips below the "; sLowerTrade = -iShift + " pips above the "; } switch (IndParam.ListParam[0].Text) { case "Enter long at Fibo0 (short at Fibo100)": EntryPointLongDescription = sUpperTrade + "Fibo level"; EntryPointShortDescription = sLowerTrade + "Fibo level"; break; case "Exit long at Fibo0 (short at Fibo100)": ExitPointLongDescription = sUpperTrade + "Fibo level"; ExitPointShortDescription = sLowerTrade + "Fibo level"; break; case "Enter long at Fibo236 (short at Fibo764)": EntryPointLongDescription = sUpperTrade + "Fibo level"; EntryPointShortDescription = sLowerTrade + "Fibo level"; break; case "Exit long at Fibo236 (short at Fibo764)": ExitPointLongDescription = sUpperTrade + "Fibo level"; ExitPointShortDescription = sLowerTrade + "Fibo level"; break; case "Enter long at Fibo382 (short at Fibo618)": EntryPointLongDescription = sUpperTrade + "Fibo level"; EntryPointShortDescription = sLowerTrade + "Fibo level"; break; case "Exit long at Fibo382 (short at Fibo618)": ExitPointLongDescription = sUpperTrade + "Fibo level"; ExitPointShortDescription = sLowerTrade + "Fibo level"; break; //--------------------------------------------------------------------- case "Enter the market at the Fibo50": EntryPointLongDescription = sUpperTrade + "Fibo"; EntryPointShortDescription = sLowerTrade + "Fibo"; break; case "Exit the market at the Fibo50": ExitPointLongDescription = sUpperTrade + "Fibo"; ExitPointShortDescription = sLowerTrade + "Fibo"; break; //--------------------------------------------------------------------- case "Enter long at Fibo618 (short at Fibo382)": EntryPointLongDescription = sLowerTrade + "Fibo level"; EntryPointShortDescription = sUpperTrade + "Fibo level"; break; case "Exit long at Fibo618 (short at Fibo382)": ExitPointLongDescription = sLowerTrade + "Fibo level"; ExitPointShortDescription = sUpperTrade + "Fibo level"; break; case "Enter long at Fibo764 (short at Fibo236)": EntryPointLongDescription = sLowerTrade + "Fibo level"; EntryPointShortDescription = sUpperTrade + "Fibo level"; break; case "Exit long at Fibo764 (short at Fibo236)": ExitPointLongDescription = sLowerTrade + "Fibo level"; ExitPointShortDescription = sUpperTrade + "Fibo level"; break; case "Enter long at Fibo100 (short at Fibo0)": EntryPointLongDescription = sLowerTrade + "Fibo level"; EntryPointShortDescription = sUpperTrade + "Fibo level"; break; case "Exit long at Fibo100 (short at Fibo0)": ExitPointLongDescription = sLowerTrade + "Fibo level"; ExitPointShortDescription = sUpperTrade + "Fibo level"; break; default: break; } return; } /// /// Indicator to string /// public override string ToString() { string sString = IndicatorName + (IndParam.CheckParam[0].Checked ? "*" : ""); if (IndParam.ListParam[1].Text == "Previous day") sString += "(Daily)"; return sString; } } }
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.;