• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MACD Strategy - Need Advice

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

    MACD Strategy - Need Advice

    I am trying to use a strategy to find setups like in the picture where the current bar closes above the [email protected], the MACD and MACD AVG are above the Diff, the Diff is greater than 0 and the RSI is greater than 40. This works pretty well in backtesting how i have it but I need to tighten up my losses. My current exit is when the Price low low() ticks below the [email protected] This is for volatile stocks like ADAP today where a stop loss is not appropriate. My enter conditions ensures the bars will always be above the [email protected] so my exit is safe. Here is my script and there is also a pic of the current backtest results. If anyone has any advice on how to cut losses some more please help me.


    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MACDTradeAuto : Strategy
    {
    private MACD MACD1;
    private RSI RSI1;
    private EMA EMA1;
    private EMA EMA2;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "MACDTradeAuto";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 1;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = true;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelCloseIgnoreRejects ;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    ProfitTarget = 20;
    StopLoss = 10;
    TradeSize = 1;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    MACD1 = MACD(Close, 12, 26, 9);
    RSI1 = RSI(Close, 14, 3);
    EMA1 = EMA(Close, 9);
    EMA2 = EMA(Close, 9);
    MACD1.Plots[0].Brush = Brushes.DarkCyan;
    MACD1.Plots[1].Brush = Brushes.Crimson;
    MACD1.Plots[2].Brush = Brushes.DodgerBlue;
    RSI1.Plots[0].Brush = Brushes.DodgerBlue;
    RSI1.Plots[1].Brush = Brushes.Goldenrod;
    EMA1.Plots[0].Brush = Brushes.Goldenrod;
    EMA2.Plots[0].Brush = Brushes.Gold;
    AddChartIndicator(MACD1);
    AddChartIndicator(RSI1);
    AddChartIndicator(EMA1);
    AddChartIndicator(EMA2);
    SetProfitTarget(@"", CalculationMode.Ticks, ProfitTarget);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((MACD1.Diff[0] > 0)
    && (RSI1.Default[0] > 40)
    && (Close[0] > EMA1[0])
    && (MACD1.Default[0] > MACD1.Diff[0])
    && (MACD1.Avg[0] > MACD1.Diff[0]))
    {
    EnterLong(Convert.ToInt32(TradeSize), @"ENTERLong");
    }

    // Set 2
    if ((BarsSinceEntryExecution(0, "", 0) >= 15)
    || (CrossBelow(Low, EMA2, 1)))
    {
    ExitLong(Convert.ToInt32(TradeSize), @"EXITLong", "");
    }

    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="ProfitTarget", Description="Number of ticks up from entry", Order=1, GroupName="Parameters")]
    public int ProfitTarget
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="StopLoss", Description="Number of ticks down from entry ", Order=2, GroupName="Parameters")]
    public int StopLoss
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="TradeSize", Order=3, GroupName="Parameters")]
    public int TradeSize
    { get; set; }
    #endregion

    }
    }
    Last edited by authenticx; 05-29-2020, 10:38 PM.

    #2
    This thread should be moved to the NT8 forums.

    Comment


      #3
      One idea:

      Start the strategy in Chart A (or via Strategy tab in CC).

      In Chart B, enable Chart Trader and when trades are entered
      by the strategy in Chart A, the target/stop orders will appear
      on Chart B. You can manually adjust these target/stop orders
      via drag-n-drop on Chart B and your strategy orders will be
      updated accordingly.

      My point is: Watch (or listen) for trade entries and then (on a separate
      chart) update the stop order to the desired location via Chart Trader.

      Comment


        #4
        That won't work for me because I want to run strategies against multiple symbols and i don't want to monitor them all. I think i figured it out conditionally though without having to use a stop loss.

        Comment


          #5
          Hi authenticx, thanks for your post.

          Unfortunately, the support team can not assist with the performance of a strategy. Other members of the community are still here for their input.

          Kind regards.
          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Darringona, Today, 07:43 AM
          0 responses
          3 views
          0 likes
          Last Post Darringona  
          Started by simonkloot, Today, 07:28 AM
          0 responses
          6 views
          0 likes
          Last Post simonkloot  
          Started by marcus2300, Today, 06:24 AM
          0 responses
          4 views
          0 likes
          Last Post marcus2300  
          Started by Dhjesus, Today, 06:23 AM
          0 responses
          7 views
          0 likes
          Last Post Dhjesus
          by Dhjesus
           
          Started by embreyw, Today, 05:56 AM
          0 responses
          6 views
          0 likes
          Last Post embreyw
          by embreyw
           
          Working...
          X