HasCrossedAbove/Below assistance please
HasCrossedAbove/Below assistance please
17 May 2019, 05:11
Slowly im learning to code. Ive been making simple bots to test different conditions so i can see how they work individually before i stack everything together. Ive read through the forums but i cant figure this one out. The HasCrossed command.
I am using a custom vwap indicator, but i commented it out to try with 2 ema's. I still cant get it to work. What am I missing?
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
// private VWAP _vwap;
private ExponentialMovingAverage _ema;
private ExponentialMovingAverage _ema2;
protected override void OnStart()
{
// _vwap = Indicators.GetIndicator<VWAP>();
_ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 13);
_ema2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, 27);
}
protected override void OnTick()
{
var _longPos = Positions.Find(null, Symbol, TradeType.Buy);
var _shortPos = Positions.Find(null, Symbol, TradeType.Sell);
// if (_longPos == null)
{
if (_ema.Result.HasCrossedAbove(_ema2.Result, 0))
ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, null, 1.8, 4.8);
}
// if (_shortPos == null)
{
if (_ema.Result.HasCrossedBelow(_ema2.Result, 0))
ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, null, 1.8, 4.8);
}
}
protected override void OnStop()
{
}
}
}
Replies
ToheedAhmed
19 May 2019, 08:22
RE:
Slowly im learning to code. Ive been making simple bots to test different conditions so i can see how they work individually before i stack everything together. Ive read through the forums but i cant figure this one out. The HasCrossed command.
I am using a custom vwap indicator, but i commented it out to try with 2 ema's. I still cant get it to work. What am I missing?
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
// private VWAP _vwap;
private ExponentialMovingAverage _ema;
private ExponentialMovingAverage _ema2;
protected override void OnStart()
{
// _vwap = Indicators.GetIndicator<VWAP>();
_ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 13);
_ema2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, 27);
}
protected override void OnTick()
{
var _longPos = Positions.Find(null, Symbol, TradeType.Buy);
var _shortPos = Positions.Find(null, Symbol, TradeType.Sell);
// if (_longPos == null)
{
if (_ema.Result.HasCrossedAbove(_ema2.Result, 0))
ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, null, 1.8, 4.8);
}
// if (_shortPos == null)
{
if (_ema.Result.HasCrossedBelow(_ema2.Result, 0))
ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, null, 1.8, 4.8);
}
}
protected override void OnStop()
{
}
}
}
@ToheedAhmed
PanagiotisCharalampous
20 May 2019, 10:30
Hi zedodia,
Can you check the log in case there are any errors there?
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
17 May 2019, 14:43
Hi zedodia,
Can you please explain why do you think it does not work? I ran a backtesting and I get trades.
Best Regards,
Panagiotis
@PanagiotisCharalampous