MACD crossover around its value

Created at 15 Jul 2013, 21:54
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!
IR

iRobot

Joined 17.02.2013

MACD crossover around its value
15 Jul 2013, 21:54


Hi,

please suggest function to MACD histogram crossover around its own value (with a MACD.Histogram.HasCrossedAbove or any better), for example 0.0004 (period T-2) and 0.0006 (period T-1), meaning that it is a signal that histogram crossed above its own value of 0.0005.

Many thanks.

 


@iRobot
Replies

iRobot
16 Jul 2013, 17:58

Could I expect at least some answer? Thx.


@iRobot

iRobot
16 Jul 2013, 18:38

And could anyone suggest how to make indexing on MACD histogram. That would be very appreciated.


@iRobot

adaled
18 Jul 2013, 12:35

I think you need to give a better explanation. :)


@adaled

iRobot
18 Jul 2013, 16:21

What I need is to have a signal when MACD value (not signal) is higher than some appointed value. For example: let's say MACD value is <0.0005 for some time, but if it's value is greater than 0.0005 the signal is created.The easy way would be a function of crossover (like MACD crossover on signal line). The messy way would be indexing MACD values, but the problem is I don't know how to index MACD (at least it seem not as easy as indexing EMAs).

It would be a great breakthrough if anyone could suggest the solution.


@iRobot

adaled
18 Jul 2013, 17:10

you can reference MacdCrossOver Indicator and index the MACD from it.

    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, ScalePrecision = 5)]
    public class Macd_function : Indicator
    {
        private MacdCrossOver macd;
        
        [Parameter(DefaultValue = 0.001)]
        public double Value { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }
        

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            macd = Indicators.MacdCrossOver(26,12,9);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            
            Result[index] = macd.MACD[index]; // so you see the macd values on the chart
            
            if(!IsRealTime) return; // so that you don't print all historical values
            
            if(macd.MACD[index] >= Value)
                Print("Macd crossed over Value at {0}", macd.MACD[index]);  // your logic
        }
    }




@adaled

iRobot
19 Jul 2013, 23:56

Thanks adaled.

Could you please help me with another thing? It's a super stupd question, but I don't understand how to implement indicator in the robot. There is "robot" class and there is "indicator" class and I don't know how to make them work together. I hope my issue sounds clear.

 


@iRobot

cAlgo_Fanatic
22 Jul 2013, 10:00

You can reference a custom indicator by clicking the button "Add Reference" next to the "build" button in the text editor code view.

A line will be insterted automatically on the top of the code file.

The rest of the code will be similar to the above example, except for initializing:

myIndicator = Indicators.GetIndicator<MyIndicator>(Param1, Param2, ...);

You can see this platform robot sample: "Sample Robot Reference SMA" which references the platform "Sample SMA" Indicator as an example.

 


@cAlgo_Fanatic