Fun with Cycles (a cycle simulator)

Questions about MultiCharts and user contributed studies.
hendrix
Posts: 54
Joined: 27 Dec 2013
Has thanked: 21 times
Been thanked: 5 times

Fun with Cycles (a cycle simulator)

Postby hendrix » 27 Jan 2015

Hi all

I would know if it is possible to adapte this code from TS (9.1) to Multichart :

Image

Code: Select all

Using elsystem;
using elsystem.windows.forms;
Using elsystem.drawing;
using elsystem.drawingobjects;
using elsystem.collections;

{ revision history
2014-12-27 - v1.0 - Initial release
2014-12-28 - v1.1 - Add Candlestick control, Cycle squeeze, ShoBars
Replace BarsPerCycle with BarSeparation
Remember control panel placement during "Restore Defaults"
scale it so its visible on any instrument
}

var: Docking("");
var: Candlewid(0);

Method bool StringContains(string ss, string targ) begin return instr(ss,targ) <> 0; end;
Method double oo_iff( bool q, double valu1, double valu2 ) begin if q then return valu1 else return valu2; end;
Method Color xcolor(int colr) begin return color.FromArgb(getRvalue(colr),getGvalue(colr),getBvalue(colr) ); end;

{ COLORS }

var: orange(rgb(255, 65, 0));
var: skyblue(rgb(75, 206, 250));
var: gold(rgb(255, 180, 40));
var: pink(rgb(255, 165, 255));

method override void InitializeComponent()
begin
self.uninitialized += analysistechnique_uninitialized;
end;

var: PinkFac(0), GoldFac(0), BlueFac(0), OrangeFac(0), CyanFac(0);
var: freqPink(0), freqGold(0), freqBlue(0), freqOrange(0), freqCyan(0);
var: ampPink(0), ampGold(0), ampBlue(0), ampOrange(0), ampCyan(0);

var: ok2recalc(false);
var:
Button btnRestore(null),
Form frmMain(Null);

var: Label lblPink(null), Label lblGold(null), Label lblBlue(null), Label lblOrange(null), Label lblCyan(null);
var: Label lblCalcCycle(null), checkbox chkCalcCyclePink(null), checkbox chkCalcCycleGold(null), checkbox chkCalcCycleBlue(null), checkbox chkCalcCycleOrange(null), checkbox chkCalcCycleCyan(null);
var: Label lblShoCycle(null), checkbox chkShoCyclePink(null), checkbox chkShoCycleGold(null), checkbox chkShoCycleBlue(null), checkbox chkShoCycleOrange(null), checkbox chkShoCycleCyan(null);
var: Label lblShoObos(null), checkbox chkShoObosPink(null), checkbox chkShoObosGold(null), checkbox chkShoObosBlue(null), checkbox chkShoObosOrange(null), checkbox chkShoObosCyan(null);
var: Label lblShoHHLL(null), checkbox chkShoHHLLPink(null), checkbox chkShoHHLLGold(null), checkbox chkShoHHLLBlue(null), checkbox chkShoHHLLOrange(null), checkbox chkShoHHLLCyan(null);
var: Label lblCycleSqueeze(null), NumericUpDown spnCycleSqueeze(null);
var: Label lblBarSeparation(null), NumericUpDown spnBarSeparation(null);
var: Label lblBarRange(null), NumericUpDown spnBarRange(null);
var: label lblAmplitude(null), NumericUpDown spnAmpPink(null), NumericUpDown spnAmpGold(null), NumericUpDown spnAmpBlue(null), NumericUpDown spnAmpOrange(null), NumericUpDown spnAmpCyan(null);
var: label lblFactor(null), NumericUpDown spnFactorPink(null), NumericUpDown spnFactorGold(null), NumericUpDown spnFactorBlue(null), NumericUpDown spnFactorOrange(null), NumericUpDown spnFactorCyan(null);
var: label lblBarType(null), Panel pnlBars(null), RadioButton rdoNone(null), RadioButton rdoHLC(null), RadioButton rdoCandlesticks(null);

const:
frm.width( 400 ), frm.height( 600 ),
btn.width( 60 ), btn.height( 20 ),
lbl.width( 30 ), lbl.height( 15 ),
txt.width( 60 ), txt.height( 15 ), widetxt.width( 180 ),
cbo.width( 80 ), cbo.height( 30 ),
chk.width( 20 ), chk.height( 20 ), widechk.width( 120 ),
rdo.width( 80 ), rdo.height( 15 ),
spn.width( 33 ), spn.height( 30 ),
widelbl.width( 60 ), widelbl.height( 30 ),
bigbtn.width( 80 ), bigbtn.height( 30 ),
spacer( 3 ),
columnwidth( 100 );

Const: lblwidfac(1.1);
const: chkAdjust(3), spnAdjust(0);
method void BuildForm()
Vars: int hz, int vt, int vtsave1, int hzsave1;
begin
frmMain = form.create( "Fun with Cycles", 280, 400);
frmMain.BackColor = color.black;

vt = 10;
hz = 10;

btnRestore = button.Create("Restore Defaults",btn.width,2*btn.height);
btnRestore.Location(hz,vt);
btnRestore.Click += btnRestore_Clicked;
btnRestore.BackColor = color.darkblue;
btnRestore.ForeColor = color.white;
vt += btnRestore.Height + spacer;
frmMain.AddControl(btnRestore);

// Column Headings
lblPink = Label.Create( "Pink", lblwidfac*lbl.width, lbl.height );
lblPink.font = Font.Create("Arial", 8, fontstyle.bold);
lblPink.FlatStyle = FlatStyle.standard;
lblPink.ForeColor = xcolor(pink);
frmMain.AddControl(lblPink);

lblGold = Label.Create( "Gold", lblwidfac*lbl.width, lbl.height );
lblGold.font = Font.Create("Arial", 8, fontstyle.bold);
lblGold.FlatStyle = FlatStyle.standard;
lblGold.ForeColor = xcolor(Gold);
frmMain.AddControl(lblGold);

lblBlue = Label.Create( "Blue", lblwidfac*lbl.width, lbl.height );
lblBlue.font = Font.Create("Arial", 8, fontstyle.bold);
lblBlue.FlatStyle = FlatStyle.standard;
lblBlue.ForeColor = xcolor(skyBlue);
frmMain.AddControl(lblBlue);

lblOrange = Label.Create( "Orange", 1.5*lbl.width, lbl.height );
lblOrange.font = Font.Create("Arial", 8, fontstyle.bold);
lblOrange.FlatStyle = FlatStyle.standard;
lblOrange.ForeColor = xcolor(Orange);
frmMain.AddControl(lblOrange);

lblCyan = Label.Create( "Cyan", lblwidfac*lbl.width, lbl.height );
lblCyan.font = Font.Create("Arial", 8, fontstyle.bold);
lblCyan.FlatStyle = FlatStyle.standard;
lblCyan.ForeColor = xcolor(darkCyan);
frmMain.AddControl(lblCyan);


// CalcCycle
lblCalcCycle = Label.Create( "Calc Cycle", 2.5*lbl.width, lbl.height );
lblCalcCycle.font = Font.Create("Arial", 8, fontstyle.bold);
lblCalcCycle.FlatStyle = FlatStyle.standard;
lblCalcCycle.ForeColor = color.white;
frmMain.AddControl(lblCalcCycle);

chkCalcCyclePink = CheckBox.Create( "", chk.width, chk.height );
chkCalcCyclePink.Click += btnRecalc_Clicked;
frmMain.AddControl( chkCalcCyclePink );
chkCalcCycleGold = CheckBox.Create( "", chk.width, chk.height );
chkCalcCycleGold.Click += btnRecalc_Clicked;
frmMain.AddControl( chkCalcCycleGold );
chkCalcCycleBlue = CheckBox.Create( "", chk.width, chk.height );
chkCalcCycleBlue.Click += btnRecalc_Clicked;
frmMain.AddControl( chkCalcCycleBlue );
chkCalcCycleOrange = CheckBox.Create( "", chk.width, chk.height );
chkCalcCycleOrange.Click += btnRecalc_Clicked;
frmMain.AddControl( chkCalcCycleOrange );
chkCalcCycleCyan = CheckBox.Create( "", chk.width, chk.height );
chkCalcCycleCyan.Click += btnRecalc_Clicked;
frmMain.AddControl( chkCalcCycleCyan );

// ShoCycle
lblShoCycle = Label.Create( "Show Cycle", 2.5*lbl.width, lbl.height );
lblShoCycle.font = Font.Create("Arial", 8, fontstyle.bold);
lblShoCycle.FlatStyle = FlatStyle.standard;
lblShoCycle.ForeColor = color.white;
frmMain.AddControl(lblShoCycle);

chkShoCyclePink = CheckBox.Create( "", chk.width, chk.height );
chkShoCyclePink.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoCyclePink );

chkShoCycleGold = CheckBox.Create( "", chk.width, chk.height );
chkShoCycleGold.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoCycleGold );

chkShoCycleBlue = CheckBox.Create( "", chk.width, chk.height );
chkShoCycleBlue.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoCycleBlue );

chkShoCycleOrange = CheckBox.Create( "", chk.width, chk.height );
chkShoCycleOrange.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoCycleOrange );

chkShoCycleCyan = CheckBox.Create( "", chk.width, chk.height );
chkShoCycleCyan.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoCycleCyan );

// ShoObos
lblShoObos = Label.Create( "Show OB/OS", 2.5*lbl.width, lbl.height );
lblShoObos.font = Font.Create("Arial", 8, fontstyle.bold);
lblShoObos.FlatStyle = FlatStyle.standard;
lblShoObos.ForeColor = color.white;
frmMain.AddControl(lblShoObos);

chkShoObosPink = CheckBox.Create( "", chk.width, chk.height );
chkShoObosPink.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoObosPink );

chkShoObosGold = CheckBox.Create( "", chk.width, chk.height );
chkShoObosGold.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoObosGold );

chkShoObosBlue = CheckBox.Create( "", chk.width, chk.height );
chkShoObosBlue.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoObosBlue );

chkShoObosOrange = CheckBox.Create( "", chk.width, chk.height );
chkShoObosOrange.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoObosOrange );

chkShoObosCyan = CheckBox.Create( "", chk.width, chk.height );
chkShoObosCyan.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoObosCyan );

// ShoHHLL
lblShoHHLL = Label.Create( "Show HH/LL", 2.5*lbl.width, lbl.height );
lblShoHHLL.font = Font.Create("Arial", 8, fontstyle.bold);
lblShoHHLL.FlatStyle = FlatStyle.standard;
lblShoHHLL.ForeColor = color.white;
frmMain.AddControl(lblShoHHLL);

chkShoHHLLPink = CheckBox.Create( "", chk.width, chk.height );
chkShoHHLLPink.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoHHLLPink );

chkShoHHLLGold = CheckBox.Create( "", chk.width, chk.height );
chkShoHHLLGold.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoHHLLGold );

chkShoHHLLBlue = CheckBox.Create( "", chk.width, chk.height );
chkShoHHLLBlue.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoHHLLBlue );

chkShoHHLLOrange = CheckBox.Create( "", chk.width, chk.height );
chkShoHHLLOrange.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoHHLLOrange );

chkShoHHLLCyan = CheckBox.Create( "", chk.width, chk.height );
chkShoHHLLCyan.Click += btnRecalc_Clicked;
frmMain.AddControl( chkShoHHLLCyan );

lblAmplitude = Label.Create( "Amplitude", 2.5*lbl.width, lbl.height );
lblAmplitude.font = Font.Create("Arial", 8, fontstyle.bold);
lblAmplitude.FlatStyle = FlatStyle.standard;
lblAmplitude.ForeColor = color.white;
frmMain.AddControl( lblAmplitude );

spnAmpPink = NumericUpDown.Create( spn.width, spn.height );
spnAmpPink.Location(hz, vt);
spnAmpPink.Minimum = 1;
spnAmpPink.Maximum = 10;
spnAmpPink.Increment = 1;
spnAmpPink.ValueChanged += spnValueChanged;
spnAmpPink.Tag = "spnAmpPink.value" astype string;
frmMain.AddControl(spnAmpPink);

spnAmpGold = NumericUpDown.Create( spn.width, spn.height );
spnAmpGold.Location(hz, vt);
spnAmpGold.Minimum = 1;
spnAmpGold.Maximum = 10;
spnAmpGold.Increment = 1;
spnAmpGold.ValueChanged += spnValueChanged;
spnAmpGold.Tag = "spnAmpGold.value" astype string;
frmMain.AddControl(spnAmpGold);

spnAmpBlue = NumericUpDown.Create( spn.width, spn.height );
spnAmpBlue.Location(hz, vt);
spnAmpBlue.Minimum = 1;
spnAmpBlue.Maximum = 10;
spnAmpBlue.Increment = 1;
spnAmpBlue.ValueChanged += spnValueChanged;
spnAmpBlue.Tag = "spnAmpBlue.value" astype string;
frmMain.AddControl(spnAmpBlue);

spnAmpOrange = NumericUpDown.Create( spn.width, spn.height );
spnAmpOrange.Location(hz, vt);
spnAmpOrange.Minimum = 1;
spnAmpOrange.Maximum = 10;
spnAmpOrange.Increment = 1;
spnAmpOrange.ValueChanged += spnValueChanged;
spnAmpOrange.Tag = "spnAmpOrange.value" astype string;
frmMain.AddControl(spnAmpOrange);

spnAmpCyan = NumericUpDown.Create( spn.width, spn.height );
spnAmpCyan.Location(hz, vt);
spnAmpCyan.Minimum = 1;
spnAmpCyan.Maximum = 10;
spnAmpCyan.Increment = 1;
spnAmpCyan.ValueChanged += spnValueChanged;
spnAmpCyan.Tag = "spnAmpCyan.value" astype string;
frmMain.AddControl(spnAmpCyan);

lblFactor = Label.Create( "# Legs", 2.5*lbl.width, lbl.height );
lblFactor.font = Font.Create("Arial", 8, fontstyle.bold);
lblFactor.FlatStyle = FlatStyle.standard;
lblFactor.ForeColor = color.white;
frmMain.AddControl( lblFactor );

spnFactorPink = NumericUpDown.Create( spn.width, spn.height );
spnFactorPink.Location(hz, vt);
spnFactorPink.Minimum = 3;
spnFactorPink.Maximum = 5;
spnFactorPink.Increment = 1;
spnFactorPink.ValueChanged += spnValueChanged;
spnFactorPink.Tag = "spnFactorPink.value" astype string;
frmMain.AddControl(spnFactorPink);

spnFactorGold = NumericUpDown.Create( spn.width, spn.height );
spnFactorGold.Location(hz, vt);
spnFactorGold.Minimum = 3;
spnFactorGold.Maximum = 5;
spnFactorGold.Increment = 1;
spnFactorGold.ValueChanged += spnValueChanged;
spnFactorGold.Tag = "spnFactorGold.value" astype string;
frmMain.AddControl(spnFactorGold);

spnFactorBlue = NumericUpDown.Create( spn.width, spn.height );
spnFactorBlue.Location(hz, vt);
spnFactorBlue.Minimum = 3;
spnFactorBlue.Maximum = 5;
spnFactorBlue.Increment = 1;
spnFactorBlue.ValueChanged += spnValueChanged;
spnFactorBlue.Tag = "spnFactorBlue.value" astype string;
frmMain.AddControl(spnFactorBlue);

spnFactorOrange = NumericUpDown.Create( spn.width, spn.height );
spnFactorOrange.Location(hz, vt);
spnFactorOrange.Minimum = 3;
spnFactorOrange.Maximum = 5;
spnFactorOrange.Increment = 1;
spnFactorOrange.ValueChanged += spnValueChanged;
spnFactorOrange.Tag = "spnFactorOrange.value" astype string;
frmMain.AddControl(spnFactorOrange);

spnFactorCyan = NumericUpDown.Create( spn.width, spn.height );
spnFactorCyan.Location(hz, vt);
spnFactorCyan.Minimum = 3;
spnFactorCyan.Maximum = 5;
spnFactorCyan.Increment = 1;
spnFactorCyan.ValueChanged += spnValueChanged;
spnFactorCyan.Tag = "spnFactorCyan.value" astype string;
//frmMain.AddControl(spnFactorCyan);

//var: Label lblBarSeparation(null), NumericUpDown spnBarSeparation(null);
//var: Label lblBarRange(null), NumericUpDown spnBarRange(null);

lblCycleSqueeze = Label.Create( "Cycle Squeeze", 3*lbl.width, lbl.height );
lblCycleSqueeze.font = Font.Create("Arial", 8, fontstyle.bold);
lblCycleSqueeze.FlatStyle = FlatStyle.standard;
lblCycleSqueeze.ForeColor = color.white;
frmMain.AddControl(lblCycleSqueeze);
spnCycleSqueeze = NumericUpDown.Create( spn.width, spn.height );
spnCycleSqueeze.Location(hz, vt);
spnCycleSqueeze.Minimum = 1;
spnCycleSqueeze.Maximum = 20;
spnCycleSqueeze.Increment = 1;
spnCycleSqueeze.ValueChanged += spnValueChanged;
spnCycleSqueeze.Tag = "spnCycleSqueeze.value" astype string;
frmMain.AddControl(spnCycleSqueeze);

lblBarSeparation = Label.Create( "Bar Separation", 3*lbl.width, lbl.height );
lblBarSeparation.font = Font.Create("Arial", 8, fontstyle.bold);
lblBarSeparation.FlatStyle = FlatStyle.standard;
lblBarSeparation.ForeColor = color.white;
frmMain.AddControl(lblBarSeparation);
spnBarSeparation = NumericUpDown.Create( spn.width, spn.height );
spnBarSeparation.Location(hz, vt);
spnBarSeparation.Minimum = 1;
spnBarSeparation.Maximum = 100;
spnBarSeparation.Increment = 1;
spnBarSeparation.ValueChanged += spnValueChanged;
spnBarSeparation.Tag = "spnBarSeparation.value" astype string;
frmMain.AddControl(spnBarSeparation);

lblBarRange = Label.Create( "Bar Range", 3*lbl.width, lbl.height );
lblBarRange.font = Font.Create("Arial", 8, fontstyle.bold);
lblBarRange.FlatStyle = FlatStyle.standard;
lblBarRange.ForeColor = color.white;
frmMain.AddControl(lblBarRange);
spnBarRange = NumericUpDown.Create( spn.width, spn.height );
spnBarRange.Location(hz, vt);
spnBarRange.Minimum = 2;
spnBarRange.Maximum = 30;
spnBarRange.Increment = 2;
spnBarRange.ValueChanged += spnValueChanged;
spnBarRange.Tag = "spnBarRange.value" astype string;
frmMain.AddControl(spnBarRange);

// Panel pnlBars(null), RadioButton rdoNone(null), RadioButton rdoHLC(null), RadioButton rdoCandlesticks(null);

lblBarType = Label.Create( "Bar Type", 1.6*lblwidfac*lbl.width, lbl.height );
lblBarType.font = Font.Create("Arial", 8, fontstyle.bold);
lblBarType.FlatStyle = FlatStyle.standard;
lblBarType.ForeColor = color.white;
frmMain.AddControl(lblBarType);

pnlBars = panel.Create(100,30);
pnlBars.BorderStyle = BorderStyle.fixedsingle;
frmMain.AddControl(pnlBars);
rdoNone = RadioButton.Create("None",rdo.width,rdo.height);
rdoNone.ForeColor = color.white;
rdoNone.Click += btnRecalc_Clicked;
pnlBars.AddControl(rdoNone);
rdoHLC = RadioButton.Create("HLC",rdo.width,rdo.height);
rdoHLC.ForeColor = color.white;
rdoHLC.Click += btnRecalc_Clicked;
pnlBars.AddControl(rdoHLC);
rdoCandlesticks = RadioButton.Create("Candles",rdo.width,rdo.height);
rdoCandlesticks.ForeColor = color.white;
rdoCandlesticks.Click += btnRecalc_Clicked;
pnlBars.AddControl(rdoCandlesticks);

// POSITION ELEMENTS
vt += spacer;
vt += spacer;
vt += spacer;

hz = lblCalcCycle.width + spacer;
lblPink.Location(hz,vt); hz += lblPink.Width + spacer;
lblGold.Location(hz,vt); hz += lblGold.Width + spacer;
lblBlue.Location(hz,vt); hz += lblBlue.Width + spacer;
lblOrange.Location(hz-6,vt); hz += lblBlue.Width + spacer;
lblCyan.Location(hz,vt); hz += lblCyan.Width + spacer;
vt += lblPink.Height + spacer;


hz = spacer;
vt += spacer;
lblCalcCycle.Location(hz,vt); hz += lblCalcCycle.Width + spacer;
hz += 3;
chkCalcCyclePink.Location(hz,vt-chkAdjust); hz += lblPink.width + spacer;
chkCalcCycleGold.Location(hz,vt-chkAdjust); hz += lblGold.width + spacer;
chkCalcCycleBlue.Location(hz,vt-chkAdjust); hz += lblBlue.width + spacer;
chkCalcCycleOrange.Location(hz,vt-chkAdjust); hz += lblBlue.width + spacer;
chkCalcCycleCyan.Location(hz,vt-chkAdjust); hz += lblCyan.width + spacer;
vt += lblCalcCycle.Height + spacer;

hz = spacer;
vt += spacer;
lblShoCycle.Location(hz,vt); hz += lblShoCycle.Width + spacer;
hz += 3;
chkShoCyclePink.Location(hz,vt-chkAdjust); hz += lblPink.width + spacer;
chkShoCycleGold.Location(hz,vt-chkAdjust); hz += lblGold.width + spacer;
chkShoCycleBlue.Location(hz,vt-chkAdjust); hz += lblBlue.width + spacer;
chkShoCycleOrange.Location(hz,vt-chkAdjust); hz += lblBlue.width + spacer;
chkShoCycleCyan.Location(hz,vt-chkAdjust); hz += lblCyan.width + spacer;
vt += lblCalcCycle.Height + spacer;

hz = spacer;
vt += spacer;
lblShoObos.Location(hz,vt); hz += lblShoObos.Width + spacer;
hz += 3;
chkShoObosPink.Location(hz,vt-chkAdjust); hz += lblPink.width + spacer;
chkShoObosGold.Location(hz,vt-chkAdjust); hz += lblGold.width + spacer;
chkShoObosBlue.Location(hz,vt-chkAdjust); hz += lblBlue.width + spacer;
chkShoObosOrange.Location(hz,vt-chkAdjust); hz += lblBlue.width + spacer;
chkShoObosCyan.Location(hz,vt-chkAdjust); hz += lblCyan.width + spacer;
vt += lblShoObos.Height + spacer;

hz = spacer;
vt += spacer;
lblShoHHLL.Location(hz,vt); hz += lblShoHHLL.Width + spacer;
hz += 3;
chkShoHHLLPink.Location(hz,vt-chkAdjust); hz += lblPink.width + spacer;
chkShoHHLLGold.Location(hz,vt-chkAdjust); hz += lblGold.width + spacer;
chkShoHHLLBlue.Location(hz,vt-chkAdjust); hz += lblBlue.width + spacer;
chkShoHHLLOrange.Location(hz,vt-chkAdjust); hz += lblBlue.width + spacer;
chkShoHHLLCyan.Location(hz,vt-chkAdjust); hz += lblCyan.width + spacer;
vt += lblShoHHLL.Height + spacer;

vt += spacer;
vt += spacer;
hz = spacer;
lblAmplitude.Location(hz,vt); hz += lblAmplitude.Width + spacer;
spnAmpPink.Location(hz-spnAdjust,vt); hz += spnAmpPink.Width + spacer;
spnAmpGold.Location(hz-spnAdjust,vt); hz += spnAmpGold.Width + spacer;
spnAmpBlue.Location(hz-spnAdjust,vt); hz += spnAmpBlue.Width + spacer;
spnAmpOrange.Location(hz-spnAdjust,vt); hz += spnAmpOrange.Width + spacer;
spnAmpCyan.Location(hz-spnAdjust,vt); hz += spnAmpCyan.Width + spacer;
vt += spnAmpPink.height;

vt += spacer;
vt += spacer;
hz = spacer;
lblFactor.Location(hz,vt); hz += lblFactor.Width + spacer;
spnFactorPink.Location(hz-spnAdjust,vt); hz += spnFactorPink.Width + spacer;
spnFactorGold.Location(hz-spnAdjust,vt); hz += spnFactorGold.Width + spacer;
spnFactorBlue.Location(hz-spnAdjust,vt); hz += spnFactorBlue.Width + spacer;
spnFactorOrange.Location(hz-spnAdjust,vt); hz += spnFactorOrange.Width + spacer;
spnFactorCyan.Location(hz-spnAdjust,vt); hz += spnFactorCyan.Width + spacer;
vt += spnFactorPink.height;

vt += lblFactor.Height + spacer;

vt += spacer;
vt += spacer;

//var: Label lblBarSeparation(null), NumericUpDown spnBarSeparation(null);
//var: Label lblBarRange(null), NumericUpDown spnBarRange(null);

vt += spacer;
hz = spacer;
vtsave1 = vt - chkAdjust; // save for pnlBarType
lblCycleSqueeze.Location(hz,vt); hz += lblCycleSqueeze.Width + spacer;
spnCycleSqueeze.Location(hz,vt-chkAdjust); vt += spnCycleSqueeze.height;
hzsave1 = hz + spnCycleSqueeze.Width + spacer; // save for pnlBarType
vt += spacer;
hz = spacer;
lblBarSeparation.Location(hz,vt); hz += lblBarSeparation.Width + spacer;
spnBarSeparation.Location(hz,vt-chkAdjust); vt += spnBarSeparation.height;
vt += spacer;
hz = spacer;
lblBarRange.Location(hz,vt); hz += lblBarRange.Width + spacer;
spnBarRange.Location(hz,vt-chkAdjust); vt += spnBarRange.height;

// Panel pnlBars(null), RadioButton rdoNone(null), RadioButton rdoHLC(null), RadioButton rdoCandlesticks(null);

vt += spacer;
hz = spacer;
hzsave1 += spacer * 6;
pnlBars.Location(hzSave1,vtSave1);
pnlBars.Height = spnCycleSqueeze.Height * 3 + spacer * 2;
lblBarType.Location(hzsave1+4,vtSave1-5);
vt = spacer * 3;
hz = spacer * 6;
rdoNone.Location(hz,vt); vt += rdoNone.Height + spacer;
rdoHLC.location(hz,vt); vt += rdoHLC.Height + spacer;
rdoCandlesticks.Location(hz,vt);
//pnlBars.BackColor = color.cyan;
end;

method void spnValueChanged( Object obj, EventArgs args )
var: NumericUpDown spn, int oldvalu;
begin
spn = obj astype NumericUpDown;
If AppStorage.contains(spn.tag astype string) then
oldvalu = AppStorage[spn.tag astype string] astype int
Else
oldvalu = 0;
If spn.Value <> oldvalu then begin
//print("spnValueChanged: ",obj.tostring(),", ",spn.Value:5:0,", ",spn.tag astype string,
// ", old value:",oldvalu:4:0);
AppStorage[spn.tag astype string] = spn.Value astype int;
recalc();
end;
end;
method void btnRestore_Clicked( Object obj, EventArgs btn )
begin
// Set initial values

ok2recalc = false;

AppStorage.Clear();

// preserve location
appstorage["frmMain.Dock"] = frmMain.Dock astype int;
appstorage["frmMain.Height"] = frmMain.Height astype int;
appstorage["frmMain.Width"] = frmMain.Width astype int;
appstorage["frmMain.ControlLocation.x"] = frmMain.ControlLocation.x astype int;
appstorage["frmMain.ControlLocation.y"] = frmMain.ControlLocation.y astype int;

LoadAppstorage();

// now can recalc
ok2recalc = true;
Recalc();
end;
method void btnRecalc_Clicked( Object obj, EventArgs btn )
begin
Recalc();
end;
Method void Recalc()
begin
If ok2recalc then
Throw elsystem.RecalculateException.Create("Refresh indicator") ;
end;

method void AnalysisTechnique_UnInitialized( elsystem.Object sender, elsystem.UnInitializedEventArgs args )
begin
//print(" ");
//print("AnalysisTechnique_Uninitialized: shutting down");

appstorage["frmMain.Dock"] = frmMain.Dock astype int;
appstorage["frmMain.Height"] = frmMain.Height astype int;
appstorage["frmMain.Width"] = frmMain.Width astype int;

appstorage["frmMain.ControlLocation.x"] = frmMain.ControlLocation.x astype int;
appstorage["frmMain.ControlLocation.y"] = frmMain.ControlLocation.y astype int;

appstorage["chkCalcCyclePink.checked"] = chkCalcCyclePink.checked astype bool;
appstorage["chkCalcCycleGold.checked"] = chkCalcCycleGold.checked astype bool;
appstorage["chkCalcCycleBlue.checked"] = chkCalcCycleBlue.checked astype bool;
appstorage["chkCalcCycleOrange.checked"] = chkCalcCycleOrange.checked astype bool;
appstorage["chkCalcCycleCyan.checked"] = chkCalcCycleCyan.checked astype bool;

appstorage["chkShoCyclePink.checked"] = chkShoCyclePink.checked astype bool;
appstorage["chkShoCycleGold.checked"] = chkShoCycleGold.checked astype bool;
appstorage["chkShoCycleBlue.checked"] = chkShoCycleBlue.checked astype bool;
appstorage["chkShoCycleOrange.checked"] = chkShoCycleOrange.checked astype bool;
appstorage["chkShoCycleCyan.checked"] = chkShoCycleCyan.checked astype bool;

appstorage["chkShoObosPink.checked"] = chkShoObosPink.checked astype bool;
appstorage["chkShoObosGold.checked"] = chkShoObosGold.checked astype bool;
appstorage["chkShoObosBlue.checked"] = chkShoObosBlue.checked astype bool;
appstorage["chkShoObosOrange.checked"] = chkShoObosOrange.checked astype bool;
appstorage["chkShoObosCyan.checked"] = chkShoObosCyan.checked astype bool;

appstorage["chkShoHHLLPink.checked"] = chkShoHHLLPink.checked astype bool;
appstorage["chkShoHHLLGold.checked"] = chkShoHHLLGold.checked astype bool;
appstorage["chkShoHHLLBlue.checked"] = chkShoHHLLBlue.checked astype bool;
appstorage["chkShoHHLLOrange.checked"] = chkShoHHLLOrange.checked astype bool;
appstorage["chkShoHHLLCyan.checked"] = chkShoHHLLCyan.checked astype bool;

appstorage["spnCycleSqueeze.value"] = spnCycleSqueeze.value astype int;
appstorage["spnBarSeparation.value"] = spnBarSeparation.value astype int;
appstorage["spnBarRange.value"] = spnBarRange.value astype int;

appstorage["rdoNone.checked"] = rdoNone.checked astype bool;
appstorage["rdoHLC.checked"] = rdoHLC.checked astype bool;
appstorage["rdoCandlesticks.checked"] = rdoCandlesticks.checked astype bool;
end;

Method void LoadAppstorage()
begin
If not appstorage.contains("chkCalcCyclePink.checked") then appstorage["chkCalcCyclePink.checked"] = true;
chkCalcCyclePink.checked = appstorage["chkCalcCyclePink.checked"] astype bool;
If not appstorage.contains("chkCalcCycleGold.checked") then appstorage["chkCalcCycleGold.checked"] = true;
chkCalcCycleGold.checked = appstorage["chkCalcCycleGold.checked"] astype bool;
If not appstorage.contains("chkCalcCycleBlue.checked") then appstorage["chkCalcCycleBlue.checked"] = true;
chkCalcCycleBlue.checked = appstorage["chkCalcCycleBlue.checked"] astype bool;
If not appstorage.contains("chkCalcCycleOrange.checked") then appstorage["chkCalcCycleOrange.checked"] = true;
chkCalcCycleOrange.checked = appstorage["chkCalcCycleOrange.checked"] astype bool;
If not appstorage.contains("chkCalcCycleCyan.checked") then appstorage["chkCalcCycleCyan.checked"] = true;
chkCalcCycleCyan.checked = appstorage["chkCalcCycleCyan.checked"] astype bool;

If not appstorage.contains("chkShoCyclePink.checked") then appstorage["chkShoCyclePink.checked"] = false;
chkShoCyclePink.checked = appstorage["chkShoCyclePink.checked"] astype bool;
If not appstorage.contains("chkShoCycleGold.checked") then appstorage["chkShoCycleGold.checked"] = false;
chkShoCycleGold.checked = appstorage["chkShoCycleGold.checked"] astype bool;
If not appstorage.contains("chkShoCycleBlue.checked") then appstorage["chkShoCycleBlue.checked"] = true;
chkShoCycleBlue.checked = appstorage["chkShoCycleBlue.checked"] astype bool;
If not appstorage.contains("chkShoCycleOrange.checked") then appstorage["chkShoCycleOrange.checked"] = true;
chkShoCycleOrange.checked = appstorage["chkShoCycleOrange.checked"] astype bool;
If not appstorage.contains("chkShoCycleCyan.checked") then appstorage["chkShoCycleCyan.checked"] = true;
chkShoCycleCyan.checked = appstorage["chkShoCycleCyan.checked"] astype bool;

If not appstorage.contains("chkShoObosPink.checked") then appstorage["chkShoObosPink.checked"] = false;
chkShoObosPink.checked = appstorage["chkShoObosPink.checked"] astype bool;
If not appstorage.contains("chkShoObosGold.checked") then appstorage["chkShoObosGold.checked"] = false;
chkShoObosGold.checked = appstorage["chkShoObosGold.checked"] astype bool;
If not appstorage.contains("chkShoObosBlue.checked") then appstorage["chkShoObosBlue.checked"] = false;
chkShoObosBlue.checked = appstorage["chkShoObosBlue.checked"] astype bool;
If not appstorage.contains("chkShoObosOrange.checked") then appstorage["chkShoObosOrange.checked"] = false;
chkShoObosOrange.checked = appstorage["chkShoObosOrange.checked"] astype bool;
If not appstorage.contains("chkShoObosCyan.checked") then appstorage["chkShoObosCyan.checked"] = false;
chkShoObosCyan.checked = appstorage["chkShoObosCyan.checked"] astype bool;

If not appstorage.contains("chkShoHHLLPink.checked") then appstorage["chkShoHHLLPink.checked"] = false;
chkShoHHLLPink.checked = appstorage["chkShoHHLLPink.checked"] astype bool;
If not appstorage.contains("chkShoHHLLGold.checked") then appstorage["chkShoHHLLGold.checked"] = false;
chkShoHHLLGold.checked = appstorage["chkShoHHLLGold.checked"] astype bool;
If not appstorage.contains("chkShoHHLLBlue.checked") then appstorage["chkShoHHLLBlue.checked"] = false;
chkShoHHLLBlue.checked = appstorage["chkShoHHLLBlue.checked"] astype bool;
If not appstorage.contains("chkShoHHLLOrange.checked") then appstorage["chkShoHHLLOrange.checked"] = false;
chkShoHHLLOrange.checked = appstorage["chkShoHHLLOrange.checked"] astype bool;
If not appstorage.contains("chkShoHHLLCyan.checked") then appstorage["chkShoHHLLCyan.checked"] = false;
chkShoHHLLCyan.checked = appstorage["chkShoHHLLCyan.checked"] astype bool;

If not appstorage.contains("spnFactorPink.value") then appstorage["spnFactorPink.value"] = 3 astype int;
spnFactorPink.value = appstorage["spnFactorPink.value"] astype int;
If not appstorage.contains("spnFactorGold.value") then appstorage["spnFactorGold.value"] = 3 astype int;
spnFactorGold.value = appstorage["spnFactorGold.value"] astype int;
If not appstorage.contains("spnFactorBlue.value") then appstorage["spnFactorBlue.value"] = 3 astype int;
spnFactorBlue.value = appstorage["spnFactorBlue.value"] astype int;
If not appstorage.contains("spnFactorOrange.value") then appstorage["spnFactorOrange.value"] = 3 astype int;
spnFactorOrange.value = appstorage["spnFactorOrange.value"] astype int;
If not appstorage.contains("spnFactorCyan.value") then appstorage["spnFactorCyan.value"] = 3 astype int;
spnFactorCyan.value = appstorage["spnFactorCyan.value"] astype int;

If not appstorage.contains("spnAmpPink.value") then appstorage["spnAmpPink.value"] = 1 astype int;
spnAmpPink.value = appstorage["spnAmpPink.value"] astype int;
If not appstorage.contains("spnAmpGold.value") then appstorage["spnAmpGold.value"] = 1 astype int;
spnAmpGold.value = appstorage["spnAmpGold.value"] astype int;
If not appstorage.contains("spnAmpBlue.value") then appstorage["spnAmpBlue.value"] = 1 astype int;
spnAmpBlue.value = appstorage["spnAmpBlue.value"] astype int;
If not appstorage.contains("spnAmpOrange.value") then appstorage["spnAmpOrange.value"] = 2 astype int;
spnAmpOrange.value = appstorage["spnAmpOrange.value"] astype int;
If not appstorage.contains("spnAmpCyan.value") then appstorage["spnAmpCyan.value"] = 3 astype int;
spnAmpCyan.value = appstorage["spnAmpCyan.value"] astype int;

if not appstorage.Contains("frmMain.Dock") then begin
// docking logic should work but doesn't. is it me or ts?
Switch docking begin
Case "right": frmMain.Dock = DockStyle.right;
Case "left": frmMain.Dock = DockStyle.left;
default: frmMain.Dock = Dockstyle.none;
end;
appstorage["frmMain.Dock"] = frmMain.Dock astype int;
end;
frmMain.Dock = appstorage["frmMain.Dock"] astype int;

if not appstorage.Contains("frmMain.Height") then appstorage["frmMain.Height"] = 400 astype int;
frmMain.Height = appstorage["frmMain.Height"] astype int;
if not appstorage.Contains("frmMain.Width") then appstorage["frmMain.Width"] = 280 astype int;
frmMain.Width = appstorage["frmMain.Width"] astype int;

if not appstorage.Contains("frmMain.ControlLocation.x") then appstorage["frmMain.ControlLocation.x"] = 10 astype int;
if not appstorage.Contains("frmMain.ControlLocation.y") then appstorage["frmMain.ControlLocation.y"] = 10 astype int;
frmMain.location(appstorage["frmMain.ControlLocation.x"] astype int,appstorage["frmMain.ControlLocation.y"] astype int);

ampPink = spnAmpPink.value astype int;
ampGold = spnAmpGold.value astype int;
ampBlue = spnAmpBlue.value astype int;
ampOrange = spnAmpOrange.value astype int;
ampCyan = spnAmpCyan.value astype int;

PinkFac = spnFactorPink.Value astype int;
GoldFac = spnFactorGold.Value astype int;
BlueFac = spnFactorBlue.Value astype int;
OrangeFac = spnFactorOrange.Value astype int;
CyanFac = spnFactorCyan.Value astype int;

If not chkCalcCyclePink.checked then begin
chkShoCyclePink.Checked = false;
chkShoObosPink.Checked = false;
chkShoHhllPink.Checked = false;
end;
If not chkCalcCycleGold.checked then begin
chkShoCycleGold.Checked = false;
chkShoObosGold.Checked = false;
chkShoHhllGold.Checked = false;
end;
If not chkCalcCycleBlue.checked then begin
chkShoCycleBlue.Checked = false;
chkShoObosBlue.Checked = false;
chkShoHhllBlue.Checked = false;
end;
If not chkCalcCycleOrange.checked then begin
chkShoCycleOrange.Checked = false;
chkShoObosOrange.Checked = false;
chkShoHhllOrange.Checked = false;
end;
If not chkCalcCycleCyan.checked then begin
chkShoCycleCyan.Checked = false;
chkShoObosCyan.Checked = false;
chkShoHhllCyan.Checked = false;
end;

If not appstorage.contains("spnCycleSqueeze.value") then appstorage["spnCycleSqueeze.value"] = 8 astype int;
spnCycleSqueeze.value = appstorage["spnCycleSqueeze.value"] astype int;
If not appstorage.contains("spnBarSeparation.value") then appstorage["spnBarSeparation.value"] = 8 astype int;
spnBarSeparation.value = appstorage["spnBarSeparation.value"] astype int;
If not appstorage.contains("spnBarRange.value") then appstorage["spnBarRange.value"] = 8 astype int;
spnBarRange.value = appstorage["spnBarRange.value"] astype int;

If not appstorage.contains("rdoNone.checked") then appstorage["rdoNone.checked"] = false;
rdoNone.checked = appstorage["rdoNone.checked"] astype bool;
If not appstorage.contains("rdoHLC.checked") then appstorage["rdoHLC.checked"] = false;
rdoHLC.checked = appstorage["rdoHLC.checked"] astype bool;
If not appstorage.contains("rdoCandlesticks.checked") then appstorage["rdoCandlesticks.checked"] = true;
rdoCandlesticks.checked = appstorage["rdoCandlesticks.checked"] astype bool;

freqPink = AppStorage["spnCycleSqueeze.value"] astype int * .1;
freqGold = freqPink*PinkFac;
freqBlue = freqGold*GoldFac;
freqOrange = freqBlue*BlueFac;
freqCyan = freqOrange*OrangeFac;

Switch spnBarSeparation.Value astype int begin
Case 1, 2: Candlewid = 1;
Case 3, 4, 5: Candlewid = 2;
Case 6, 7, 8: Candlewid = 3;
Case 9, 10, 11: Candlewid = 4;
Case 12, 13, 14: Candlewid = 5;
Case 15, 16, 17, 18: Candlewid = 5;
default: Candlewid = 6;
end;
end;

var: shiftPink(2);
var: shiftGold(shiftPink*3);
var: shiftBlue(shiftGold*3);
var: shiftOrange(shiftBlue*3);
var: shiftCyan(shiftOrange*3);

const: avgbb(8);
var: cyclewid(1); //Once If StringContains(ShoCycle,"O") or StringContains(ShoCycle,"C") then cyclewid = 0;
var: freq(0);
var: plotfac(100000); // quick and dirty way to plot on forex, es and nq

try

If chkShoCyclePink <> null then begin
var: basePink(0); basePink = cosine(freq/freqPink * (currentbar));
var: baseGold(0); baseGold = cosine(freq/freqGold * (currentbar));
var: baseBlue(0); baseBlue = cosine(freq/freqBlue * (currentbar));
var: baseOrange(0); baseOrange = cosine(freq/freqOrange * (currentbar));
var: baseCyan(0); baseCyan = cosine(freq/freqCyan * (currentbar));

var: cyclePink(0); cyclePink = baseCyan*ampCyan + baseOrange*ampOrange + Baseblue*ampBlue + baseGold*ampGold + basePink*(ampPink);
var: cycleGold(0); cycleGold = baseCyan*ampCyan + baseOrange*ampOrange + Baseblue*ampBlue + baseGold*(ampPink+ampGold);
var: cycleBlue(0); cycleBlue = baseCyan*ampCyan + baseOrange*ampOrange + baseblue*(ampPink+ampGold+ampBlue);
var: cycleOrange(0); cycleOrange = baseCyan*ampCyan + baseorange*(ampPink+ampGold+ampBlue+ampOrange);
var: cycleCyan(0); cycleCyan = baseCyan*(ampPink+ampGold+ampBlue+ampOrange+ampCyan);

If chkShoCyclePink.Checked then begin
plot11(plotfac*cyclePink,"p11",pink,default,cyclewid);
If chkShoObosPink.checked then begin
If basePink > .85 and basePink > basePink[1] then
plot11(plot11,"p11",default,default,5);
If basePink < -.85 and basePink < basePink[1] then
plot11(plot11,"p11",default,default,5);
end;
end;

If chkShoCycleGold.Checked then begin
plot12(plotfac*cycleGold[shiftGold],"p12",gold,default,cyclewid);
If chkShoObosGold.checked then begin
If baseGold[shiftGold] > .85 and baseGold[shiftGold] > baseGold[shiftGold+1] then
plot12(plot12,"p12",default,default,5);
If baseGold[shiftGold] < -.85 and baseGold[shiftGold] < baseGold[shiftGold+1] then
plot12(plot12,"p12",default,default,5);
end;
end;

If chkShoCycleBlue.Checked then begin
plot13(plotfac*cycleBlue[shiftBlue],"p13",skyblue,default,cyclewid);
If chkShoObosBlue.checked then begin
If baseBlue[shiftBlue] > .85 and baseBlue[shiftBlue] > baseBlue[shiftBlue+1] then
plot13(plot13,"p13",default,default,5);
If baseBlue[shiftBlue] < -.85 and baseBlue[shiftBlue] < baseBlue[shiftBlue+1] then
plot13(plot13,"p13",default,default,5);
end;
end;

If chkShoCycleOrange.Checked then begin
plot14(plotfac*cycleOrange[shiftOrange],"p14",orange,default,cyclewid);
If chkShoObosOrange.checked then begin
If baseOrange[shiftOrange] > .85 and baseOrange[shiftOrange] > baseOrange[shiftOrange+1] then
plot14(plot14,"p14",default,default,5);
If baseOrange[shiftOrange] < -.85 and baseOrange[shiftOrange] < baseOrange[shiftOrange+1] then
plot14(plot14,"p14",default,default,5);
end;
end;

If chkShoCycleCyan.Checked then begin
plot15(plotfac*cycleCyan[shiftCyan],"p15",darkcyan,default,cyclewid);
If chkShoObosCyan.checked then begin
If baseCyan[shiftCyan] > .75 and baseCyan[shiftCyan] > baseCyan[shiftCyan+1] then
plot15(plot15,"p15",default,default,5);
If baseCyan[shiftCyan] < -.75 and baseCyan[shiftCyan] < baseCyan[shiftCyan+1] then
plot15(plot15,"p15",default,default,5);
end;
end;

var: Vector vcc(null); Once vcc = New vector;
If not appstorage["rdoNone.checked"] astype bool then begin
var: price(0); price = baseCyan*ampCyan + baseOrange*ampOrange + Baseblue*ampBlue + baseGold*ampGold + basePink*(ampPink);
var: rng(0); Once rng = (spnBarRange.value/100)*(ampPink+ampGold+ampBlue+ampOrange+ampCyan);
If mod(currentbar,spnBarSeparation.Value) = 0 then begin
var: hh(0); hh = price+random(rng);
var: ll(0); ll = price-random(rng);
If hh < ll[1] then hh = ll[1];
If ll > hh[1] then ll = hh[1];
var: cc(0); cc = oo_iff(price>price[1],ll+.8*(hh-ll),ll+.2*(hh-ll));
plot93(plotfac*cc,"p93");
plot94(plotfac*hh,"p94");
plot95(plotfac*ll,"p95");
If appstorage["rdoCandlesticks.checked"] astype bool then begin
plot91(plotfac*cc,"p91",oo_iff(cc>cc[1],green,red),default,candlewid);
plot92(plotfac*cc[1],"p92");
end;

If False then begin
vcc.insert(0,cc);

var: avgbb2(0);
If chkCalcCycleCyan.checked then avgbb2 = freqCyan
else If chkCalcCycleOrange.checked then avgbb2 = freqOrange
else If chkCalcCycleBlue.checked then avgbb2 = freqBlue
else If chkCalcCycleGold.checked then avgbb2 = freqGold
else If chkCalcCyclePink.checked then avgbb2 = freqPink
Else avgbb2 = 1;
If vcc.count > avgbb2*9 then begin
//print("vcc.count; ",vcc.count:5:0);
//plot41(oo_hma(vcc,50),"p41",white,default,3);
plot41(plotfac*average(vcc,3*avgbb2),"p41",white,default,3);
plot42(plotfac*average(vcc,9*avgbb2),"p42",white,default,3);
end;
end;

var: Pinkdir(0), hhPink(0), vhhPink(0), llPink(0), vllPink(0);
Pinkdir = oo_iff(cyclePink>cyclePink[1],1,-1);
Switch Pinkdir begin
Case 1: If Pinkdir <> Pinkdir[1] then begin vllPink = llPink; hhPink = hh; end;
If vhhPink < hh then vhhPink = hh; If vllPink > ll then vllPink = ll;
Case -1: If Pinkdir <> Pinkdir[1] then begin vhhPink = hhPink; llPink = ll; end;
If vhhPink < hh then vhhPink = hh; If vllPink > ll then vllPink = ll;
end;
If llPink > ll then llPink = ll; If hhPink < hh then hhPink = hh;

var: Golddir(0), hhGold(0), vhhGold(0), llGold(0), vllGold(0);
Golddir = oo_iff(cycleGold>cycleGold[1],1,-1);
Switch Golddir begin
Case 1: If Golddir <> Golddir[1] then begin vllGold = llGold; hhGold = hh; end;
If vhhGold < hh then vhhGold = hh; If vllGold > ll then vllGold = ll;
Case -1: If Golddir <> Golddir[1] then begin vhhGold = hhGold; llGold = ll; end;
If vhhGold < hh then vhhGold = hh; If vllGold > ll then vllGold = ll;
end;
If llGold > ll then llGold = ll; If hhGold < hh then hhGold = hh;

var: bluedir(0), hhBlue(0), vhhBlue(0), llBlue(0), vllBlue(0);
bluedir = oo_iff(cycleBlue>cycleBlue[1],1,-1);
Switch bluedir begin
Case 1: If bluedir <> bluedir[1] then begin vllBlue = llBlue; hhBlue = hh; end;
If vhhBlue < hh then vhhBlue = hh; If vllBlue > ll then vllBlue = ll;
Case -1: If bluedir <> bluedir[1] then begin vhhBlue = hhBlue; llBlue = ll; end;
If vhhBlue < hh then vhhBlue = hh; If vllBlue > ll then vllBlue = ll;
end;
If llBlue > ll then llBlue = ll; If hhBlue < hh then hhBlue = hh;

var: Orangedir(0), hhOrange(0), vhhOrange(0), llOrange(0), vllOrange(0);
Orangedir = oo_iff(cycleOrange>cycleOrange[1],1,-1);
Switch Orangedir begin
Case 1: If Orangedir <> Orangedir[1] then begin vllOrange = llOrange; hhOrange = hh; end;
If vhhOrange < hh then vhhOrange = hh; If vllOrange > ll then vllOrange = ll;
Case -1: If Orangedir <> Orangedir[1] then begin vhhOrange = hhOrange; llOrange = ll; end;
If vhhOrange < hh then vhhOrange = hh; If vllOrange > ll then vllOrange = ll;
end;
If llOrange > ll then llOrange = ll; If hhOrange < hh then hhOrange = hh;

var: Cyandir(0), hhCyan(0), vhhCyan(0), llCyan(0), vllCyan(0);
Cyandir = oo_iff(cycleCyan>cycleCyan[1],1,-1);
Switch Cyandir begin
Case 1: If Cyandir <> Cyandir[1] then begin vllCyan = llCyan; hhCyan = hh; end;
If vhhCyan < hh then vhhCyan = hh; If vllCyan > ll then vllCyan = ll;
Case -1: If Cyandir <> Cyandir[1] then begin vhhCyan = hhCyan; llCyan = ll; end;
If vhhCyan < hh then vhhCyan = hh; If vllCyan > ll then vllCyan = ll;
end;
If llCyan > ll then llCyan = ll; If hhCyan < hh then hhCyan = hh;
end;
If chkShoHHLLPink.checked then begin
plot69(plotfac*vhhPink,"p69",Pink);
plot68(plotfac*vllPink,"p68",Pink);
end;
If chkShoHHLLGold.checked then begin
plot67(plotfac*vhhGold,"p67",Gold);
plot66(plotfac*vllGold,"p66",Gold);
end;
If chkShoHHLLBlue.checked then begin
plot65(plotfac*vhhBlue,"p65",skyblue);
plot64(plotfac*vllBlue,"p64",skyblue);
end;
If chkShoHHLLOrange.checked then begin
plot63(plotfac*vhhOrange,"p63",Orange);
plot62(plotfac*vllOrange,"p62",Orange);
end;
If chkShoHHLLCyan.checked then begin
plot61(plotfac*vhhCyan,"p61",Cyan);
plot60(plotfac*vllCyan,"p60",Cyan);
end;
end;

Plot96(c,"p96",black,default,2);
Plot97(h,"p97",black,default,0);
Plot98(l,"p98",black,default,0);

If False then begin
plot97(1.25*(ampPink+ampGold+ampBlue+ampOrange+ampCyan),"p97",black,default,cyclewid);
plot98(-1.25*(ampPink+ampGold+ampBlue+ampOrange+ampCyan),"p98",black,default,cyclewid);
end;
end;

Once Begin
BuildForm();
LoadAppstorage();

frmMain.show( );
frmMain.TopMost = true; // ts bug

If chkShoCyclePink.Checked then freq = 1;
If chkShoCycleGold.Checked then freq = 2;
If chkShoCycleBlue.Checked then freq = 4;
If chkShoCycleOrange.Checked then freq = 8;
If chkShoCycleCyan.Checked then freq = 16;

If not chkCalcCyclePink.Checked then ampPink = 0;
If not chkCalcCycleGold.Checked then ampGold = 0;
If not chkCalcCycleBlue.Checked then ampBlue = 0;
If not chkCalcCycleOrange.Checked then ampOrange = 0;
If not chkCalcCycleCyan.Checked then ampCyan = 0;

ok2recalc = true;
recalc();
end;

Catch (Exception ex);
If ex.Message <> "Refresh indicator" then
print("StandardTradingParadigm error: ",ex.Message);
end; // try

Attachments
FUN WITH CYCLES.ELD
(55.15 KiB) Downloaded 347 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Fun with Cycles (a cycle simulator)

Postby JoshM » 27 Jan 2015

I would know if it is possible to adapte this code from TS (9.1) to Multichart :
I suppose so, but not with those smooth lines nor with the 'Fun with lines' options window from the screenshot.

If you remove all code that doesn't work with MultiCharts (the method and advanced drawings), you'll end up with something like:

Code: Select all

var: Docking("");
var: Candlewid(0);

{ COLORS }

var: orange(rgb(255, 65, 0));
var: skyblue(rgb(75, 206, 250));
var: gold(rgb(255, 180, 40));
var: pink(rgb(255, 165, 255));

var: PinkFac(0), GoldFac(0), BlueFac(0), OrangeFac(0), CyanFac(0);
var: freqPink(0), freqGold(0), freqBlue(0), freqOrange(0), freqCyan(0);
var: ampPink(0), ampGold(0), ampBlue(0), ampOrange(0), ampCyan(0);

var: ok2recalc(false);
var:
Button btnRestore(null),
Form frmMain(Null);

const:
frm.width( 400 ), frm.height( 600 ),
btn.width( 60 ), btn.height( 20 ),
lbl.width( 30 ), lbl.height( 15 ),
txt.width( 60 ), txt.height( 15 ), widetxt.width( 180 ),
cbo.width( 80 ), cbo.height( 30 ),
chk.width( 20 ), chk.height( 20 ), widechk.width( 120 ),
rdo.width( 80 ), rdo.height( 15 ),
spn.width( 33 ), spn.height( 30 ),
widelbl.width( 60 ), widelbl.height( 30 ),
bigbtn.width( 80 ), bigbtn.height( 30 ),
spacer( 3 ),
columnwidth( 100 );

Const: lblwidfac(1.1);
const: chkAdjust(3), spnAdjust(0);

var: shiftPink(2);
var: shiftGold(shiftPink*3);
var: shiftBlue(shiftGold*3);
var: shiftOrange(shiftBlue*3);
var: shiftCyan(shiftOrange*3);

const: avgbb(8);
var: cyclewid(1); //Once If StringContains(ShoCycle,"O") or StringContains(ShoCycle,"C") then cyclewid = 0;
var: freq(0);
var: plotfac(100000); // quick and dirty way to plot on forex, es and nq

If chkShoCyclePink <> null then begin
var: basePink(0); basePink = cosine(freq/freqPink * (currentbar));
var: baseGold(0); baseGold = cosine(freq/freqGold * (currentbar));
var: baseBlue(0); baseBlue = cosine(freq/freqBlue * (currentbar));
var: baseOrange(0); baseOrange = cosine(freq/freqOrange * (currentbar));
var: baseCyan(0); baseCyan = cosine(freq/freqCyan * (currentbar));

var: cyclePink(0); cyclePink = baseCyan*ampCyan + baseOrange*ampOrange + Baseblue*ampBlue + baseGold*ampGold + basePink*(ampPink);
var: cycleGold(0); cycleGold = baseCyan*ampCyan + baseOrange*ampOrange + Baseblue*ampBlue + baseGold*(ampPink+ampGold);
var: cycleBlue(0); cycleBlue = baseCyan*ampCyan + baseOrange*ampOrange + baseblue*(ampPink+ampGold+ampBlue);
var: cycleOrange(0); cycleOrange = baseCyan*ampCyan + baseorange*(ampPink+ampGold+ampBlue+ampOrange);
var: cycleCyan(0); cycleCyan = baseCyan*(ampPink+ampGold+ampBlue+ampOrange+ampCyan);

If chkShoCyclePink.Checked then begin
plot11(plotfac*cyclePink,"p11",pink,default,cyclewid);
If chkShoObosPink.checked then begin
If basePink > .85 and basePink > basePink[1] then
plot11(plot11,"p11",default,default,5);
If basePink < -.85 and basePink < basePink[1] then
plot11(plot11,"p11",default,default,5);
end;
end;

If chkShoCycleGold.Checked then begin
plot12(plotfac*cycleGold[shiftGold],"p12",gold,default,cyclewid);
If chkShoObosGold.checked then begin
If baseGold[shiftGold] > .85 and baseGold[shiftGold] > baseGold[shiftGold+1] then
plot12(plot12,"p12",default,default,5);
If baseGold[shiftGold] < -.85 and baseGold[shiftGold] < baseGold[shiftGold+1] then
plot12(plot12,"p12",default,default,5);
end;
end;

If chkShoCycleBlue.Checked then begin
plot13(plotfac*cycleBlue[shiftBlue],"p13",skyblue,default,cyclewid);
If chkShoObosBlue.checked then begin
If baseBlue[shiftBlue] > .85 and baseBlue[shiftBlue] > baseBlue[shiftBlue+1] then
plot13(plot13,"p13",default,default,5);
If baseBlue[shiftBlue] < -.85 and baseBlue[shiftBlue] < baseBlue[shiftBlue+1] then
plot13(plot13,"p13",default,default,5);
end;
end;

If chkShoCycleOrange.Checked then begin
plot14(plotfac*cycleOrange[shiftOrange],"p14",orange,default,cyclewid);
If chkShoObosOrange.checked then begin
If baseOrange[shiftOrange] > .85 and baseOrange[shiftOrange] > baseOrange[shiftOrange+1] then
plot14(plot14,"p14",default,default,5);
If baseOrange[shiftOrange] < -.85 and baseOrange[shiftOrange] < baseOrange[shiftOrange+1] then
plot14(plot14,"p14",default,default,5);
end;
end;

If chkShoCycleCyan.Checked then begin
plot15(plotfac*cycleCyan[shiftCyan],"p15",darkcyan,default,cyclewid);
If chkShoObosCyan.checked then begin
If baseCyan[shiftCyan] > .75 and baseCyan[shiftCyan] > baseCyan[shiftCyan+1] then
plot15(plot15,"p15",default,default,5);
If baseCyan[shiftCyan] < -.75 and baseCyan[shiftCyan] < baseCyan[shiftCyan+1] then
plot15(plot15,"p15",default,default,5);
end;
end;

var: Vector vcc(null); Once vcc = New vector;
If not appstorage["rdoNone.checked"] astype bool then begin
var: price(0); price = baseCyan*ampCyan + baseOrange*ampOrange + Baseblue*ampBlue + baseGold*ampGold + basePink*(ampPink);
var: rng(0); Once rng = (spnBarRange.value/100)*(ampPink+ampGold+ampBlue+ampOrange+ampCyan);
If mod(currentbar,spnBarSeparation.Value) = 0 then begin
var: hh(0); hh = price+random(rng);
var: ll(0); ll = price-random(rng);
If hh < ll[1] then hh = ll[1];
If ll > hh[1] then ll = hh[1];
var: cc(0); cc = oo_iff(price>price[1],ll+.8*(hh-ll),ll+.2*(hh-ll));
plot93(plotfac*cc,"p93");
plot94(plotfac*hh,"p94");
plot95(plotfac*ll,"p95");
If appstorage["rdoCandlesticks.checked"] astype bool then begin
plot91(plotfac*cc,"p91",oo_iff(cc>cc[1],green,red),default,candlewid);
plot92(plotfac*cc[1],"p92");
end;

If False then begin
vcc.insert(0,cc);

var: avgbb2(0);
If chkCalcCycleCyan.checked then avgbb2 = freqCyan
else If chkCalcCycleOrange.checked then avgbb2 = freqOrange
else If chkCalcCycleBlue.checked then avgbb2 = freqBlue
else If chkCalcCycleGold.checked then avgbb2 = freqGold
else If chkCalcCyclePink.checked then avgbb2 = freqPink
Else avgbb2 = 1;
If vcc.count > avgbb2*9 then begin
//print("vcc.count; ",vcc.count:5:0);
//plot41(oo_hma(vcc,50),"p41",white,default,3);
plot41(plotfac*average(vcc,3*avgbb2),"p41",white,default,3);
plot42(plotfac*average(vcc,9*avgbb2),"p42",white,default,3);
end;
end;

var: Pinkdir(0), hhPink(0), vhhPink(0), llPink(0), vllPink(0);
Pinkdir = oo_iff(cyclePink>cyclePink[1],1,-1);
Switch Pinkdir begin
Case 1: If Pinkdir <> Pinkdir[1] then begin vllPink = llPink; hhPink = hh; end;
If vhhPink < hh then vhhPink = hh; If vllPink > ll then vllPink = ll;
Case -1: If Pinkdir <> Pinkdir[1] then begin vhhPink = hhPink; llPink = ll; end;
If vhhPink < hh then vhhPink = hh; If vllPink > ll then vllPink = ll;
end;
If llPink > ll then llPink = ll; If hhPink < hh then hhPink = hh;

var: Golddir(0), hhGold(0), vhhGold(0), llGold(0), vllGold(0);
Golddir = oo_iff(cycleGold>cycleGold[1],1,-1);
Switch Golddir begin
Case 1: If Golddir <> Golddir[1] then begin vllGold = llGold; hhGold = hh; end;
If vhhGold < hh then vhhGold = hh; If vllGold > ll then vllGold = ll;
Case -1: If Golddir <> Golddir[1] then begin vhhGold = hhGold; llGold = ll; end;
If vhhGold < hh then vhhGold = hh; If vllGold > ll then vllGold = ll;
end;
If llGold > ll then llGold = ll; If hhGold < hh then hhGold = hh;

var: bluedir(0), hhBlue(0), vhhBlue(0), llBlue(0), vllBlue(0);
bluedir = oo_iff(cycleBlue>cycleBlue[1],1,-1);
Switch bluedir begin
Case 1: If bluedir <> bluedir[1] then begin vllBlue = llBlue; hhBlue = hh; end;
If vhhBlue < hh then vhhBlue = hh; If vllBlue > ll then vllBlue = ll;
Case -1: If bluedir <> bluedir[1] then begin vhhBlue = hhBlue; llBlue = ll; end;
If vhhBlue < hh then vhhBlue = hh; If vllBlue > ll then vllBlue = ll;
end;
If llBlue > ll then llBlue = ll; If hhBlue < hh then hhBlue = hh;

var: Orangedir(0), hhOrange(0), vhhOrange(0), llOrange(0), vllOrange(0);
Orangedir = oo_iff(cycleOrange>cycleOrange[1],1,-1);
Switch Orangedir begin
Case 1: If Orangedir <> Orangedir[1] then begin vllOrange = llOrange; hhOrange = hh; end;
If vhhOrange < hh then vhhOrange = hh; If vllOrange > ll then vllOrange = ll;
Case -1: If Orangedir <> Orangedir[1] then begin vhhOrange = hhOrange; llOrange = ll; end;
If vhhOrange < hh then vhhOrange = hh; If vllOrange > ll then vllOrange = ll;
end;
If llOrange > ll then llOrange = ll; If hhOrange < hh then hhOrange = hh;

var: Cyandir(0), hhCyan(0), vhhCyan(0), llCyan(0), vllCyan(0);
Cyandir = oo_iff(cycleCyan>cycleCyan[1],1,-1);
Switch Cyandir begin
Case 1: If Cyandir <> Cyandir[1] then begin vllCyan = llCyan; hhCyan = hh; end;
If vhhCyan < hh then vhhCyan = hh; If vllCyan > ll then vllCyan = ll;
Case -1: If Cyandir <> Cyandir[1] then begin vhhCyan = hhCyan; llCyan = ll; end;
If vhhCyan < hh then vhhCyan = hh; If vllCyan > ll then vllCyan = ll;
end;
If llCyan > ll then llCyan = ll; If hhCyan < hh then hhCyan = hh;
end;
If chkShoHHLLPink.checked then begin
plot69(plotfac*vhhPink,"p69",Pink);
plot68(plotfac*vllPink,"p68",Pink);
end;
If chkShoHHLLGold.checked then begin
plot67(plotfac*vhhGold,"p67",Gold);
plot66(plotfac*vllGold,"p66",Gold);
end;
If chkShoHHLLBlue.checked then begin
plot65(plotfac*vhhBlue,"p65",skyblue);
plot64(plotfac*vllBlue,"p64",skyblue);
end;
If chkShoHHLLOrange.checked then begin
plot63(plotfac*vhhOrange,"p63",Orange);
plot62(plotfac*vllOrange,"p62",Orange);
end;
If chkShoHHLLCyan.checked then begin
plot61(plotfac*vhhCyan,"p61",Cyan);
plot60(plotfac*vllCyan,"p60",Cyan);
end;
end;

Plot96(c,"p96",black,default,2);
Plot97(h,"p97",black,default,0);
Plot98(l,"p98",black,default,0);

If False then begin
plot97(1.25*(ampPink+ampGold+ampBlue+ampOrange+ampCyan),"p97",black,default,cyclewid);
plot98(-1.25*(ampPink+ampGold+ampBlue+ampOrange+ampCyan),"p98",black,default,cyclewid);
end;
end;

Once Begin
If chkShoCyclePink.Checked then freq = 1;
If chkShoCycleGold.Checked then freq = 2;
If chkShoCycleBlue.Checked then freq = 4;
If chkShoCycleOrange.Checked then freq = 8;
If chkShoCycleCyan.Checked then freq = 16;

If not chkCalcCyclePink.Checked then ampPink = 0;
If not chkCalcCycleGold.Checked then ampGold = 0;
If not chkCalcCycleBlue.Checked then ampBlue = 0;
If not chkCalcCycleOrange.Checked then ampOrange = 0;
If not chkCalcCycleCyan.Checked then ampCyan = 0;
end;
This is not to say the above code will work, just to highlight that a lot will need to be removed and the remainder heavily adapted. Several statements in the code above still contain TS references (but can likely be rewritten to MultiCharts). With the emphasis on 'likely', because some functions used in the code above (like `oo_iff()`) I can't find in MultiCharts.

Good luck! :)

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Fun with Cycles (a cycle simulator)

Postby Henry MultiСharts » 27 Jan 2015

Options window can be programmed as an external dll and called from the code.


Return to “MultiCharts”