Topics

Forum Topics not found

Replies

ToheedAhmed
19 May 2019, 08:22

RE:
zedodia said:

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