Please kind. How to solve this ?

Created at 13 Mar 2016, 19:21
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CO

commando1

Joined 11.03.2016

Please kind. How to solve this ?
13 Mar 2016, 19:21


Hi All,

Can somebody help me to solve this, any type of assistance would be appreciated. 

I am trying to get a cBot to email me,  if (1) two MA have crossed then (2)in subsequent bars the price travels X number of pips from the fast ma. 

The code below if flawed because it only sends the email if two event happen together. What type of logic/ structures are required in order to make the program remember that (1) has happened now scan for (2). 

sing System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;


namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MACrossTest : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter("At")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Slow Periods", DefaultValue = 30)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 15)]
        public int FastPeriods { get; set; }

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Pip Criteria", DefaultValue = 65)]
        public int PipCriteria { get; set; }

        private MovingAverage slowMa;
        private MovingAverage fastMa;

        protected override void OnStart()
        {
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

        protected override void OnBar()
        {
            if (fastMa.Result.HasCrossedAbove(slowMa.Result, 1))
            {
                var pipsDifference = (MarketSeries.Close.Last(1) - fastMa.Result.Last(1)) / Symbol.PipSize;
                if (pipsDifference >= PipCriteria)
                {
                    Print("BUY");
                    // to replaced with sending email
                }

            }

            else if (fastMa.Result.HasCrossedBelow(slowMa.Result, 1))
            {
                var pipsDifference = (fastMa.Result.Last(1) - MarketSeries.Close.Last(1)) / Symbol.PipSize;
                if (pipsDifference >= PipCriteria)
                {
                    Print("SELL");
                    // to replaced with sending email
                }

            }
        }
    }
}

 


@commando1
Replies

breakermind
13 Mar 2016, 20:12

Mail C#

Hi,

1 spotware

https://www.youtube.com/watch?v=P_s6YHv3WXw

2 Try search C# mail

http://stackoverflow.com/questions/9201239/send-e-mail-via-smtp-using-c-sharp

3 open free hosting account ( php mail function)

create php file which send email and call it from cBot .


@breakermind

croucrou
13 Mar 2016, 22:48

Maybe you can flag it with an integer variable named e.g."myEvents" with "0" as default value.

If the first condition is met, the value of "myEvents" changes to "1".

If both conditions are met, the value of "myEvents" changes to "2".

If "myEvents" equals "1" send an email: "First condition met".

If "myEvents" equals "2" send an email: "First and second condition met" and change the value back to "0".


@croucrou