2B
Topics
10 May 2020, 17:07
1363
3
12 Apr 2019, 15:52
1
1126
1
26 Mar 2019, 05:12
1
1380
1
17 Mar 2019, 07:22
14
1686
2
13 Mar 2019, 16:21
4
1005
1
12 Feb 2019, 19:01
1996
2
15 Jan 2019, 18:17
5
952
1
12 Jan 2019, 20:33
1
921
1
Replies
2bnnp
13 Apr 2019, 13:49
Line 49:
private WeightedMovingAverage wma { get; set; }
I would recommend using a underscore as prefix for private variables (_wma)
Theres also a typo in line 61/25 and 143.
And well line 109/121, you need to tell the wma what variable it should check for if it crossed above, in your case the close.
private void ManagePositions()
{
double close = MarketSeries.Close.LastValue;
if (wma.Result.HasCrossedAbove(close,0))
{
// if there is no buy position open, open one and close any sell position that is open
if (!IsPositionOpenByType(TradeType.Buy))
{
OpenPosition(TradeType.Buy);
}
ClosePosition(TradeType.Sell);
}
// if a sell position is already open and signal is buy do nothing
if (wma.Result.HasCrossedBelow(close,0))
{
// if there is no sell position open, open one and close any buy position that is open
if (!IsPositionOpenByType(TradeType.Sell))
{
OpenPosition(TradeType.Sell);
}
ClosePosition(TradeType.Buy);
}
}
@2bnnp
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;
}
}
#endregion
add this in the main class, you can then use it like so:
protected override void OnBar()
{
if (TimeWindow() && Spread())
{
ManagePositions();
}
}
@2bnnp
2bnnp
24 Mar 2019, 09:34
[Parameter("Timeframe #1", DefaultValue = "Minute15")]
public TimeFrame Tf1 { get; set; }
private StochasticOscillator _stochCTF { get; set; }
private StochasticOscillator _stochMTF { get; set; }
protected override void OnStart()
{
var timeFrameOne = MarketData.GetSeries(Tf1);
_stochCTF = Indicators.StochasticOscillator(KPeriods, KSlowing, DPeriods, MovingAverageType.Simple);
_stochMTF = Indicators.StochasticOscillator(timeFrameOne, KPeriods, KSlowing, DPeriods, MovingAverageType.Simple);
}
@2bnnp

2bnnp
11 May 2020, 11:46
@2bnnp