Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy with Macd

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy with Macd

    hi, i'm try to build strategy with macd but there is a problem

    Code:
    public class ProvaStrategy : Strategy
    	{
    		
    		private MACD fast;
            private MACD slow;
    ....
    ....
    
    	else if (State == State.Configure)
    			{
    				fast=MACD(12,26,9);
                    slow = MACD(12, 26, 9);
    
                }
    
    protected override void OnBarUpdate()
    		{
    			if (CurrentBar < BarsRequiredToTrade)
    				return;
    
    			if (CrossAbove(fast, slow, 1))  
    			    EnterLong();
    			else if (CrossBelow(fast, slow, 1))
    			    EnterShort();
    			//Add your custom strategy logic here.
    		}
    I want to use fast.fast and slow.slow but i don't underestand how i set parameter (fast and slow) in strategy...

    If i write :

    Code:
    CrossAbove(fast.fast, slow.slow)),..
    it give me an error

    thanks

    #2
    Originally posted by turbofib View Post
    hi, i'm try to build strategy with macd but there is a problem

    Code:
    public class ProvaStrategy : Strategy
    	{
    		
    		private MACD fast;
            private MACD slow;
    ....
    ....
    
    	else if (State == State.Configure)
    			{
    				fast=MACD(12,26,9);
                    slow = MACD(12, 26, 9);
    
                }
    
    protected override void OnBarUpdate()
    		{
    			if (CurrentBar < BarsRequiredToTrade)
    				return;
    
    			if (CrossAbove(fast, slow, 1))  
    			    EnterLong();
    			else if (CrossBelow(fast, slow, 1))
    			    EnterShort();
    			//Add your custom strategy logic here.
    		}
    I want to use fast.fast and slow.slow but i don't underestand how i set parameter (fast and slow) in strategy...

    If i write :

    Code:
    CrossAbove(fast.fast, slow.slow)),..
    it give me an error

    thanks
    What is the text of the error?

    Comment


      #3
      in this script is not a error because i'm missing parameter .fast and .slow of macd
      I write CrossAbove(fast.fast, slow.slow)) it give me following error:

      ERROR CODE CS1502 AND CS1503

      CS CS1503 : impossible convert int ===> Iseries<Double>

      I need to use this parameter...( i want fast line cross with slow line )

      Comment


        #4
        Originally posted by turbofib View Post
        in this script is not a error because i'm missing parameter .fast and .slow of macd
        I write CrossAbove(fast.fast, slow.slow)) it give me following error:

        ERROR CODE CS1502 AND CS1503

        CS CS1503 : impossible convert int ===> Iseries<Double>

        I need to use this parameter...( i want fast line cross with slow line )
        The relevant public properties exposed by the MACD indicator are Fast and Slow, both ints. You are trying to call them as fast and slow, which also happen to be ISeries defined in your indicator.

        That message is telling you that it cannot do that conversion. Refer to your properties by their correct names. c# is case-sensitive: fast is NOT the same as Fast.

        Comment


          #5
          ok..
          and if i want to do CrossAbove Macd line fast cross with MAcd line slow what i write ?

          Comment


            #6
            Originally posted by turbofib View Post
            ok..
            and if i want to do CrossAbove Macd line fast cross with MAcd line slow what i write ?
            This snippet from the MACD properties shows the exposed Plots.
            Code:
            		[Browsable(false)]
            		[XmlIgnore]
            		public Series<double> Avg
            		{
            			get { return Values[1]; }
            		}
            
            		[Browsable(false)]
            		[XmlIgnore]
            		public Series<double> Default
            		{
            			get { return Values[0]; }
            		}
            		
            		[Browsable(false)]
            		[XmlIgnore]
            		public Series<double> Diff
            		{
            			get { return Values[2]; }
            		}
            Reading the code, implies that the main MACD Plot is called Default. This is confirmed in the code proper if one knows how the MACD is calculated.
            Code:
            				Value[0]		= macd;
            				Avg[0]			= macdAvg;
            				Diff[0]			= macd - macdAvg;
            Therefore, your parameters for the Cross... for what you have written would be fast.Default and slow.Default.

            That is strictly following that which you have written. In practical terms, as you have defined your fast MACD object and your slow MACD object identically, there can never be a Cross of anything over the same value, so do not expect to ever see that filter invoked.
            Last edited by koganam; 01-31-2016, 10:31 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by zstheorist, Today, 07:52 PM
            0 responses
            3 views
            0 likes
            Last Post zstheorist  
            Started by pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            149 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            5 views
            0 likes
            Last Post mattbsea  
            Started by RideMe, 04-07-2024, 04:54 PM
            6 responses
            33 views
            0 likes
            Last Post RideMe
            by RideMe
             
            Started by tkaboris, Today, 05:13 PM
            0 responses
            5 views
            0 likes
            Last Post tkaboris  
            Working...
            X