RecentSwingHighLowXStepped by Naya
452 downloads / 241 views / Created: 08.06.2025




Average Rating: 0
Indicator Description
A version of RecentSwingHighLowX with numerical parameters expressed in list parameter steps.
Comments
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 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
using System;
using System.Drawing;
using ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Store
{
public class RecentSwingHighLowXstepped : Indicator
{
public RecentSwingHighLowXstepped()
{
IndicatorName = "Recent Swing High Low X Stepped";
PossibleSlots = SlotTypes.Open | SlotTypes.OpenFilter | SlotTypes.Close | SlotTypes.CloseFilter;
IndicatorAuthor = "NAYA,+237674724684";
IndicatorVersion = "1.0";
IndicatorDescription = "Custom with unified bars, bar shift, and new swing rise/fall logics with stepped vertical shift - All List Parameters";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
if (slotType == SlotTypes.Open)
IndParam.ListParam[0].ItemList = new[]
{
"Enter long at swing high",
"Enter long at swing low"
};
else if (slotType == SlotTypes.OpenFilter)
IndParam.ListParam[0].ItemList = new[]
{
"The bar opens below swing high",
"The bar opens above swing high",
"The bar opens below swing low",
"The bar opens above swing low",
"The bar opens below swing high after opening above it",
"The bar opens above swing high after opening below it",
"The bar opens below swing low after opening above it",
"The bar opens above swing low after opening below it",
"Swing high rises",
"Swing high falls",
"Swing low rises",
"Swing low falls"
};
else if (slotType == SlotTypes.Close)
IndParam.ListParam[0].ItemList = new[]
{
"Exit long at swing high",
"Exit long at swing low"
};
else if (slotType == SlotTypes.CloseFilter)
IndParam.ListParam[0].ItemList = new[]
{
"The bar closes below swing high",
"The bar closes above swing high",
"The bar closes below swing low",
"The bar closes above swing low",
"Swing high rises",
"Swing high falls",
"Swing low rises",
"Swing low falls"
};
else
IndParam.ListParam[0].ItemList = new[]
{
"Not Defined"
};
IndParam.ListParam[0].Index = 0;
IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[0];
IndParam.ListParam[0].Enabled = true;
IndParam.ListParam[0].ToolTip = "Logic of application of the indicator";
// Vertical Shift as List Parameter
IndParam.ListParam[1].Caption = "Vertical Shift";
var verticalShift = new System.Collections.Generic.List();
for (int i = -2000; i <= 2000; i += 100)
verticalShift.Add(i.ToString());
IndParam.ListParam[1].ItemList = verticalShift.ToArray();
IndParam.ListParam[1].Index = 20; // Default to 0 (index 20 in -2000 to 2000 range)
IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
IndParam.ListParam[1].Enabled = true;
IndParam.ListParam[1].ToolTip = "The vertical shift in steps of 100 points.";
// Bars as List Parameter
IndParam.ListParam[2].Caption = "Bars";
var barsList = new System.Collections.Generic.List();
for (int i = 1; i <= 50; i += 1)
barsList.Add(i.ToString());
IndParam.ListParam[2].ItemList = barsList.ToArray();
IndParam.ListParam[2].Index = 1; // Default to 2 bars (index 1)
IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
IndParam.ListParam[2].Enabled = true;
IndParam.ListParam[2].ToolTip = "Number of bars to the left and right to confirm a swing.";
// Bar Shift as List Parameter
IndParam.ListParam[3].Caption = "Bar Shift";
var barShiftList = new System.Collections.Generic.List();
for (int i = 0; i <= 100; i += 2)
barShiftList.Add(i.ToString());
IndParam.ListParam[3].ItemList = barShiftList.ToArray();
IndParam.ListParam[3].Index = 0; // Default to 0 shift
IndParam.ListParam[3].Text = IndParam.ListParam[3].ItemList[IndParam.ListParam[3].Index];
IndParam.ListParam[3].Enabled = true;
IndParam.ListParam[3].ToolTip = "How many bars to shift the swing levels forward.";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
int previous = 0;
double shiftPrice = int.Parse(IndParam.ListParam[1].Text) * Point;
int bars = int.Parse(IndParam.ListParam[2].Text);
int barShift = int.Parse(IndParam.ListParam[3].Text);
// Compute raw swing arrays
double[] upperRaw = new double[Bars];
double[] lowerRaw = new double[Bars];
int firstRaw = 2 * bars + 1;
for (int bar = firstRaw; bar < Bars; bar++)
{
int candidate = bar - (bars + 1);
bool isHigh = true;
bool isLow = true;
// Left side check
for (int i = 1; i <= bars; i++)
{
if (High[candidate] < High[candidate - i]) isHigh = false;
if (Low[candidate] > Low[candidate - i]) isLow = false;
}
// Right side check
for (int i = 1; i <= bars; i++)
{
if (High[candidate] <= High[candidate + i]) isHigh = false;
if (Low[candidate] >= Low[candidate + i]) isLow = false;
}
if (isHigh)
upperRaw[bar] = High[candidate] + shiftPrice;
else
upperRaw[bar] = upperRaw[bar - 1];
if (isLow)
lowerRaw[bar] = Low[candidate] + shiftPrice;
else
lowerRaw[bar] = lowerRaw[bar - 1];
}
// Build shifted arrays
double[] upperShifted = new double[Bars];
double[] lowerShifted = new double[Bars];
// Initialize by carrying forward prior values
for (int i = 0; i < Bars; i++)
{
if (i == 0)
{
upperShifted[i] = 0.0;
lowerShifted[i] = 0.0;
}
else
{
upperShifted[i] = upperShifted[i - 1];
lowerShifted[i] = lowerShifted[i - 1];
}
}
int firstShifted = firstRaw + barShift;
for (int bar = firstRaw; bar < Bars; bar++)
{
int target = bar + barShift;
if (target < Bars)
{
upperShifted[target] = upperRaw[bar];
lowerShifted[target] = lowerRaw[bar];
}
}
// Propagate over any gaps after shift
for (int i = 1; i < Bars; i++)
{
if (upperShifted[i] == 0.0 && i > firstShifted)
upperShifted[i] = upperShifted[i - 1];
if (lowerShifted[i] == 0.0 && i > firstShifted)
lowerShifted[i] = lowerShifted[i - 1];
}
// Create components array
Component = new IndicatorComp[4];
// Component[0]: Swing high
Component[0] = new IndicatorComp
{
CompName = "Swing high",
DataType = IndComponentType.IndicatorValue,
ChartType = IndChartType.Level,
ChartColor = Color.Blue,
FirstBar = firstShifted,
Value = upperShifted
};
// Component[1]: Swing low
Component[1] = new IndicatorComp
{
CompName = "Swing low",
DataType = IndComponentType.IndicatorValue,
ChartType = IndChartType.Level,
ChartColor = Color.Red,
FirstBar = firstShifted,
Value = lowerShifted
};
// Component[2] & [3] placeholders
Component[2] = new IndicatorComp
{
ChartType = IndChartType.NoChart,
FirstBar = firstShifted,
Value = new double[Bars]
};
Component[3] = new IndicatorComp
{
ChartType = IndChartType.NoChart,
FirstBar = firstShifted,
Value = new double[Bars]
};
// Assign data types based on slot
switch (SlotType)
{
case SlotTypes.Open:
Component[2].DataType = IndComponentType.OpenLongPrice;
Component[2].CompName = "Long position entry price";
Component[3].DataType = IndComponentType.OpenShortPrice;
Component[3].CompName = "Short position entry price";
break;
case SlotTypes.OpenFilter:
Component[2].DataType = IndComponentType.AllowOpenLong;
Component[2].CompName = "Is long entry allowed";
Component[3].DataType = IndComponentType.AllowOpenShort;
Component[3].CompName = "Is short entry allowed";
break;
case SlotTypes.Close:
Component[2].DataType = IndComponentType.CloseLongPrice;
Component[2].CompName = "Long position closing price";
Component[3].DataType = IndComponentType.CloseShortPrice;
Component[3].CompName = "Short position closing price";
break;
case SlotTypes.CloseFilter:
Component[2].DataType = IndComponentType.ForceCloseLong;
Component[2].CompName = "Close out long position";
Component[3].DataType = IndComponentType.ForceCloseShort;
Component[3].CompName = "Close out short position";
break;
}
// Fill entry/exit or filter logic
if (SlotType == SlotTypes.Open || SlotType == SlotTypes.Close)
{
for (int bar = firstShifted; bar < Bars; bar++)
{
if (IndParam.ListParam[0].Text == "Enter long at swing high" ||
IndParam.ListParam[0].Text == "Exit long at swing high")
{
Component[2].Value[bar] = upperShifted[bar - previous];
Component[3].Value[bar] = lowerShifted[bar - previous];
}
else
{
Component[2].Value[bar] = lowerShifted[bar - previous];
Component[3].Value[bar] = upperShifted[bar - previous];
}
}
}
else
{
// OpenFilter or CloseFilter
string logic = IndParam.ListParam[0].Text;
switch (logic)
{
case "The bar opens below swing high":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_opens_below_the_Upper_Band);
break;
case "The bar opens above swing high":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_opens_above_the_Upper_Band);
break;
case "The bar opens below swing low":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_opens_below_the_Lower_Band);
break;
case "The bar opens above swing low":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_opens_above_the_Lower_Band);
break;
case "The bar opens below swing high after opening above it":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it);
break;
case "The bar opens above swing high after opening below it":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it);
break;
case "The bar opens below swing low after opening above it":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it);
break;
case "The bar opens above swing low after opening below it":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it);
break;
case "The bar closes below swing high":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_closes_below_the_Upper_Band);
break;
case "The bar closes above swing high":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_closes_above_the_Upper_Band);
break;
case "The bar closes below swing low":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_closes_below_the_Lower_Band);
break;
case "The bar closes above swing low":
BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted,
ref Component[2], ref Component[3],
BandIndLogic.The_bar_closes_above_the_Lower_Band);
break;
case "Swing high rises":
IndicatorRisesLogic(firstShifted, previous, upperShifted,
ref Component[2], ref Component[3]);
break;
case "Swing high falls":
IndicatorFallsLogic(firstShifted, previous, upperShifted,
ref Component[2], ref Component[3]);
break;
case "Swing low rises":
IndicatorRisesLogic(firstShifted, previous, lowerShifted,
ref Component[2], ref Component[3]);
break;
case "Swing low falls":
IndicatorFallsLogic(firstShifted, previous, lowerShifted,
ref Component[2], ref Component[3]);
break;
}
}
}
public override void SetDescription()
{
string paramDescr = string.Format("{0} bars, shift {1}, vertShift {2} pts",
IndParam.ListParam[2].Text,
IndParam.ListParam[3].Text,
IndParam.ListParam[1].Text);
switch (IndParam.ListParam[0].Text)
{
case "Enter long at swing high":
EntryPointLongDescription = "at swing high (" + paramDescr + ")";
EntryPointShortDescription = "at swing low (" + paramDescr + ")";
break;
case "Enter long at swing low":
EntryPointLongDescription = "at swing low (" + paramDescr + ")";
EntryPointShortDescription = "at swing high (" + paramDescr + ")";
break;
case "Exit long at swing high":
ExitPointLongDescription = "at swing high (" + paramDescr + ")";
ExitPointShortDescription = "at swing low (" + paramDescr + ")";
break;
case "Exit long at swing low":
ExitPointLongDescription = "at swing low (" + paramDescr + ")";
ExitPointShortDescription = "at swing high (" + paramDescr + ")";
break;
case "The bar opens below swing high":
EntryFilterLongDescription = "the bar opens below swing high (" + paramDescr + ")";
EntryFilterShortDescription = "the bar opens above swing low (" + paramDescr + ")";
break;
case "The bar opens above swing high":
EntryFilterLongDescription = "the bar opens above swing high (" + paramDescr + ")";
EntryFilterShortDescription = "the bar opens below swing low (" + paramDescr + ")";
break;
case "The bar opens below swing low":
EntryFilterLongDescription = "the bar opens below swing low (" + paramDescr + ")";
EntryFilterShortDescription = "the bar opens above swing high (" + paramDescr + ")";
break;
case "The bar opens above swing low":
EntryFilterLongDescription = "the bar opens above swing low (" + paramDescr + ")";
EntryFilterShortDescription = "the bar opens below swing high (" + paramDescr + ")";
break;
case "The bar opens below swing high after opening above it":
EntryFilterLongDescription = "the bar opens below swing high (" + paramDescr + ") after the previous bar opened above it";
EntryFilterShortDescription = "the bar opens above swing low (" + paramDescr + ") after the previous bar opened below it";
break;
case "The bar opens above swing high after opening below it":
EntryFilterLongDescription = "the bar opens above swing high (" + paramDescr + ") after the previous bar opened below it";
EntryFilterShortDescription = "the bar opens below swing low (" + paramDescr + ") after the previous bar opened above it";
break;
case "The bar opens below swing low after opening above it":
EntryFilterLongDescription = "the bar opens below swing low (" + paramDescr + ") after the previous bar opened above it";
EntryFilterShortDescription = "the bar opens above swing high (" + paramDescr + ") after the previous bar opened below it";
break;
case "The bar opens above swing low after opening below it":
EntryFilterLongDescription = "the bar opens above swing low (" + paramDescr + ") after the previous bar opened below it";
EntryFilterShortDescription = "the bar opens below swing high (" + paramDescr + ") after the previous bar opened above it";
break;
case "The bar closes below swing high":
ExitFilterLongDescription = "the bar closes below swing high (" + paramDescr + ")";
ExitFilterShortDescription = "the bar closes above swing low (" + paramDescr + ")";
break;
case "The bar closes above swing high":
ExitFilterLongDescription = "the bar closes above swing high (" + paramDescr + ")";
ExitFilterShortDescription = "the bar closes below swing low (" + paramDescr + ")";
break;
case "The bar closes below swing low":
ExitFilterLongDescription = "the bar closes below swing low (" + paramDescr + ")";
ExitFilterShortDescription = "the bar closes above swing high (" + paramDescr + ")";
break;
case "The bar closes above swing low":
ExitFilterLongDescription = "the bar closes above swing low (" + paramDescr + ")";
ExitFilterShortDescription = "the bar closes below swing high (" + paramDescr + ")";
break;
case "Swing high rises":
EntryFilterLongDescription = "swing high rises (" + paramDescr + ")";
EntryFilterShortDescription = "swing low falls (" + paramDescr + ")";
ExitFilterLongDescription = "swing high rises (" + paramDescr + ")";
ExitFilterShortDescription = "swing low falls (" + paramDescr + ")";
break;
case "Swing high falls":
EntryFilterLongDescription = "swing high falls (" + paramDescr + ")";
EntryFilterShortDescription = "swing low rises (" + paramDescr + ")";
ExitFilterLongDescription = "swing high falls (" + paramDescr + ")";
ExitFilterShortDescription = "swing low rises (" + paramDescr + ")";
break;
case "Swing low rises":
EntryFilterLongDescription = "swing low rises (" + paramDescr + ")";
EntryFilterShortDescription = "swing high falls (" + paramDescr + ")";
ExitFilterLongDescription = "swing low rises (" + paramDescr + ")";
ExitFilterShortDescription = "swing high falls (" + paramDescr + ")";
break;
case "Swing low falls":
EntryFilterLongDescription = "swing low falls (" + paramDescr + ")";
EntryFilterShortDescription = "swing high rises (" + paramDescr + ")";
ExitFilterLongDescription = "swing low falls (" + paramDescr + ")";
ExitFilterShortDescription = "swing high rises (" + paramDescr + ")";
break;
}
}
public override string ToString()
{
return string.Format("{0}({1} bars, shift {2}, vertShift {3} pts)",
IndicatorName,
IndParam.ListParam[2].Text,
IndParam.ListParam[3].Text,
IndParam.ListParam[1].Text);
}
}
}
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//+------------------------------------------------------------------+ //| RecentSwingHighLowXStepped.mqh | //| Copyright (C) 2025 NAYA +237674724684 | //| NAYA +237674724684 | //+------------------------------------------------------------------+ #property copyright "Copyright © 2025, ChatGPT" #property link "http://forexsb.com" #property version "1.00" #property strict #include <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class RecentSwingHighLowXStepped : public Indicator { public: RecentSwingHighLowXStepped(SlotTypes slotType); virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ RecentSwingHighLowXStepped::RecentSwingHighLowXStepped(SlotTypes slotType) { SlotType = slotType; IndicatorName = "Recent Swing High Low X Stepped"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = false; } //+------------------------------------------------------------------+ //| Calculate method | //+------------------------------------------------------------------+ void RecentSwingHighLowXStepped::Calculate(DataSet &dataSet) { Data = GetPointer(dataSet); // Check if we have enough parameters if(ArraySize(ListParam) < 4) { Print(IndicatorName + ": Not enough parameters!"); return; } // Read parameters int previous = 0; double shiftPrice = StringToDouble(ListParam[1].Text) * Data.Point; int bars = StringToInteger(ListParam[2].Text); int barShift = StringToInteger(ListParam[3].Text); int totalBars = Data.Bars; // Allocate raw swing arrays double upperRaw[]; ArrayResize(upperRaw, totalBars); ArrayInitialize(upperRaw, 0); double lowerRaw[]; ArrayResize(lowerRaw, totalBars); ArrayInitialize(lowerRaw, 0); int firstRaw = 2 * bars + 1; // Compute raw swings for(int bar = firstRaw; bar < totalBars; bar++) { int candidate = bar - (bars + 1); bool isHigh = true; bool isLow = true; // Check left side for(int i = 1; i <= bars; i++) { if(Data.High[candidate] < Data.High[candidate - i]) isHigh = false; if(Data.Low[candidate] > Data.Low[candidate - i]) isLow = false; } // Check right side for(int i = 1; i <= bars; i++) { if(Data.High[candidate] <= Data.High[candidate + i]) isHigh = false; if(Data.Low[candidate] >= Data.Low[candidate + i]) isLow = false; } if(isHigh) upperRaw[bar] = Data.High[candidate] + shiftPrice; else upperRaw[bar] = upperRaw[bar - 1]; if(isLow) lowerRaw[bar] = Data.Low[candidate] + shiftPrice; else lowerRaw[bar] = lowerRaw[bar - 1]; } // Allocate shifted arrays double upperShifted[]; ArrayResize(upperShifted, totalBars); ArrayInitialize(upperShifted, 0); double lowerShifted[]; ArrayResize(lowerShifted, totalBars); ArrayInitialize(lowerShifted, 0); // Initialize shifted arrays by carrying forward for(int i = 1; i < totalBars; i++) { upperShifted[i] = upperShifted[i - 1]; lowerShifted[i] = lowerShifted[i - 1]; } int firstShifted = firstRaw + barShift; // Shift raw into shifted arrays for(int bar = firstRaw; bar < totalBars; bar++) { int target = bar + barShift; if(target < totalBars) { upperShifted[target] = upperRaw[bar]; lowerShifted[target] = lowerRaw[bar]; } } // Propagate over gaps after shift for(int i = firstShifted + 1; i < totalBars; i++) { if(upperShifted[i] == 0.0) upperShifted[i] = upperShifted[i - 1]; if(lowerShifted[i] == 0.0) lowerShifted[i] = lowerShifted[i - 1]; } // Create components array ArrayResize(Component, 4); // Component[0]: Swing high ArrayResize(Component[0].Value, totalBars); Component[0].CompName = "Swing high"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = firstShifted; ArrayCopy(Component[0].Value, upperShifted); // Component[1]: Swing low ArrayResize(Component[1].Value, totalBars); Component[1].CompName = "Swing low"; Component[1].DataType = IndComponentType_IndicatorValue; Component[1].FirstBar = firstShifted; ArrayCopy(Component[1].Value, lowerShifted); // Component[2] & Component[3]: placeholders for entry/exit or filter logic ArrayResize(Component[2].Value, totalBars); ArrayInitialize(Component[2].Value, 0); Component[2].FirstBar = firstShifted; ArrayResize(Component[3].Value, totalBars); ArrayInitialize(Component[3].Value, 0); Component[3].FirstBar = firstShifted; // Assign data types based on slot if(SlotType == SlotTypes_Open) { Component[2].DataType = IndComponentType_OpenLongPrice; Component[2].CompName = "Long position entry price"; Component[3].DataType = IndComponentType_OpenShortPrice; Component[3].CompName = "Short position entry price"; } else if(SlotType == SlotTypes_OpenFilter) { Component[2].DataType = IndComponentType_AllowOpenLong; Component[2].CompName = "Is long entry allowed"; Component[3].DataType = IndComponentType_AllowOpenShort; Component[3].CompName = "Is short entry allowed"; } else if(SlotType == SlotTypes_Close) { Component[2].DataType = IndComponentType_CloseLongPrice; Component[2].CompName = "Long position closing price"; Component[3].DataType = IndComponentType_CloseShortPrice; Component[3].CompName = "Short position closing price"; } else if(SlotType == SlotTypes_CloseFilter) { Component[2].DataType = IndComponentType_ForceCloseLong; Component[2].CompName = "Close out long position"; Component[3].DataType = IndComponentType_ForceCloseShort; Component[3].CompName = "Close out short position"; } // Fill entry/exit or filter logic if(SlotType == SlotTypes_Open || SlotType == SlotTypes_Close) { for(int bar = firstShifted; bar < totalBars; bar++) { string logic = ListParam[0].Text; if(logic == "Enter long at swing high" || logic == "Exit long at swing high") { Component[2].Value[bar] = upperShifted[bar - previous]; Component[3].Value[bar] = lowerShifted[bar - previous]; } else { Component[2].Value[bar] = lowerShifted[bar - previous]; Component[3].Value[bar] = upperShifted[bar - previous]; } } } else { string logic = ListParam[0].Text; if(logic == "The bar opens below swing high") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_opens_below_the_Upper_Band); else if(logic == "The bar opens above swing high") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_opens_above_the_Upper_Band); else if(logic == "The bar opens below swing low") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_opens_below_the_Lower_Band); else if(logic == "The bar opens above swing low") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_opens_above_the_Lower_Band); else if(logic == "The bar opens below swing high after opening above it") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_opens_below_Upper_Band_after_above); else if(logic == "The bar opens above swing high after opening below it") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_opens_above_Upper_Band_after_below); else if(logic == "The bar opens below swing low after opening above it") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_opens_below_Lower_Band_after_above); else if(logic == "The bar opens above swing low after opening below it") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_opens_above_Lower_Band_after_below); else if(logic == "The bar closes below swing high") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_closes_below_the_Upper_Band); else if(logic == "The bar closes above swing high") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_closes_above_the_Upper_Band); else if(logic == "The bar closes below swing low") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_closes_below_the_Lower_Band); else if(logic == "The bar closes above swing low") BandIndicatorLogic(firstShifted, previous, upperShifted, lowerShifted, Component[2], Component[3], BandIndLogic_The_bar_closes_above_the_Lower_Band); else if(logic == "Swing high rises") IndicatorRisesLogic(firstShifted, previous, upperShifted, Component[2], Component[3]); else if(logic == "Swing high falls") IndicatorFallsLogic(firstShifted, previous, upperShifted, Component[2], Component[3]); else if(logic == "Swing low rises") IndicatorRisesLogic(firstShifted, previous, lowerShifted, Component[2], Component[3]); else if(logic == "Swing low falls") IndicatorFallsLogic(firstShifted, previous, lowerShifted, Component[2], Component[3]); } } //+------------------------------------------------------------------+
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.;