Spud Fibo v3 by footon
4643 downloads / 5689 views / Created: 24.05.2013




Average Rating: 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
//==============================================================
// 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 - 2025, Forex Software Ltd.;
Copyright © 2006 - 2025, Forex Software Ltd.;