Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Sure.

      Click image for larger version

Name:	ss1.PNG
Views:	110
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.
        Kate W.NinjaTrader Customer Service

        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 CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,266 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          13 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X