Simple MACD

MACD, short for moving average convergence/divergence, is a trading indicator used in technical analysis of stock prices, created by Gerald Appel in the late 1970s. It is supposed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock's price.

Example 6. Strategy: Simple MACD

      /*
      This is a multiline comment.
      
      ------ Simple MACD Strategy Example ------
      
      */
      
      // Set initial capital 
      SetOption("InitialEquity",50000);
      
      // Positions sizes: use 25% of the current portfolio equity. (It means max. 4 open positions.)
      SetPositionSize( 25, spsPercentOfEquity );
      
      // Round a number of shares to 100. 
      SetOption("RoundLotSize",100);
      
      // Buy when MACD crosses the Signal line up. 
      Buy = Cross(CalcMACD(), CalcMACDSignal());
      
      // Sell when Signal crosses the MACD line. 
      Sell = Cross(CalcMACDSignal(), CalcMACD());
      
      // Delay trades to the next bar open.
      SetTradeDelays( 1, 1, 0, 0 );
      
      // Set buy and sell prices to the opening price.
      BuyPrice = Open;
      SellPrice = Open;