Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help with Strategy that Doubles Down

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

    Need help with Strategy that Doubles Down

    Hello,

    I have this issue where my strategy doubles down properly, but then only closes one of the positions. The strategy is for Forex and goes up to 2 min lots, (20000). That part works, but when it's tim to close the strategy the strategy only closes 1 lot (10000). Can someone please tell me what I'm doing wrong? Everything looks fine historically when the strategy is applied to a chart. Code is below:

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class StochasticSlowDoubleDown : Strategy
    {
    private EMA EMA1;
    private double currentPnL = 0;
    private double unrealizedPL = 0;
    private StochasticsFast StochasticsFast1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "StochasticSlowDoubleDown";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Close, 50);
    EMA1.Plots[0].Brush = Brushes.Goldenrod;

    AddChartIndicator(EMA1);

    //SetStopLoss("", CalculationMode.Currency, 200, false);
    StochasticsFast1 = StochasticsFast(Close, 3, 5);
    AddChartIndicator(StochasticsFast1);
    }
    }

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

    if (CurrentBars[0] < 1)
    return;


    // Set 1
    if ((Close[0] > EMA1[0])
    && (CrossBelow(StochasticsFast1.D, 10, 1)))
    {
    EnterLong(Convert.ToInt32(10000), "");
    }


    ///Gets Strategy Unrealized PL
    currentPnL = SystemPerformance.AllTrades.TradesPerformance.NetP rofit;

    // Set 2
    if ((CrossBelow(StochasticsFast1.D, 90, 1) && currentPnL > 0))
    {
    ExitLong(Convert.ToInt32(10000), "", "");
    }

    //else if (CrossBelow(StochasticsFast1.D, 10, 1) && Close[0] > EMA1[0])
    else if (CrossBelow(StochasticsFast1.D, 10, 1) && Position.MarketPosition != MarketPosition.Flat)
    {
    EnterLong(Convert.ToInt32(10000), "");
    }

    if (CrossBelow(StochasticsFast1.D, 90, 1))
    {
    ExitLong(Convert.ToInt32(20000), "", "");
    }


    }
    }
    }

    #2
    Hello omermirza,

    Thank you for your post.

    In my testing, when the Entries Per Direction is set to 2, I'm seeing it exit both trades successfully. Can you provide a screenshot of your settings for the strategy and also an example screenshot of what you're seeing?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Sure.

      Click image for larger version

Name:	ss1.PNG
Views:	155
Size:	11.1 KB
ID:	1144627
      Attached Files

      Comment


        #4
        Hello omermirza,

        Thank you for your reply.

        If you set the Entry Handling to All Entries, does it behave as you'd expect? Keep the Entries Per Direction as 2.

        Thanks in advance; I look forward to assisting you further.

        Comment


          #5
          Originally posted by NinjaTrader_Kate View Post
          Hello omermirza,

          Thank you for your reply.

          If you set the Entry Handling to All Entries, does it behave as you'd expect? Keep the Entries Per Direction as 2.

          Thanks in advance; I look forward to assisting you further.
          I will try it and update you.

          Thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          55 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          132 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X