Defining Maximum Spread
12 Apr 2019, 00:40
Hi guys,
I was wondering if somebody could point me in the right direction.
I have a cbot almost complete but there is one feature I haven't been able to figure out yet - defining a maximum spread.
Could somebody please give me an example, in the simplest way, of some code that would prevent a trade from executing if spread exceeds a certain number of pips? Can it be done with a simple "if" statement?
Many thanks

2bnnp
12 Apr 2019, 19:43
[Parameter("Max. spread in Pip", DefaultValue = 2, MinValue = 0, Step = 0.1)] public double MaxSpread { get; set; } #region spread logic /// <summary> /// returns true if spread is smaller than max spread /// </summary> /// <returns></returns> bool Spread() { double spread = Symbol.Spread; double size = Symbol.PipSize; double maxSpreadPip = MaxSpread * size; if (spread < maxSpreadPip) { return true; } else { return false; } } #endregionadd this in the main class, you can then use it like so:
protected override void OnBar() { if (TimeWindow() && Spread()) { ManagePositions(); } }@2bnnp