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

strategy stops after one trade

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

    strategy stops after one trade

    Can anybody help with this script please?

    It makes a trade once and then doesn't make any more when the conditions are met.
    needs re-enabling to makes another trade, then makes one trade and so forth.
    Script is as follows: Compiles OK


    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Historical)
    {
    SetProfitTarget(CalculationMode.Ticks, 60);
    SetStopLoss(CalculationMode.Ticks, 60);


    }
    else if (State == State.DataLoaded)
    {

    QuantumDynamicPricePivots1 = QuantumDynamicPricePivots(Close, 10);
    VolumeOscillator1 = VolumeOscillator(Close, 3, 50);
    }
    }


    protected override void OnBarUpdate()
    {
    if (CurrentBar < 5)
    return;

    if(State == State.Historical) return;

    if ((entryOrder == null && Close[0] > 0)
    && (VolumeOscillator1[0] > 0)
    &&(QuantumDynamicPricePivots1.MarketAnalyzerPlo t[0] == -1))


    EnterLong("myEntryOrder");



    if (BarsSinceEntryExecution() >3)
    {
    ExitLong();


    }



    }
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
    // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not gauranteed to be complete if it is referenced immediately after submitting
    if (execution.Order.Name == "myEntryOrder" && execution.Order.OrderState == OrderState.Filled)
    entryOrder = execution.Order;

    if (entryOrder != null && entryOrder == execution.Order)
    Print(execution.ToString());
    }





    }
    }

    Many thanks

    #2
    I'm going to guess that entryOrder is no longer null after you assign it in the OnExecutionUpdate - hence blocking further trades.

    Comment


      #3
      you got it Thanks a lot !

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ScottWalsh, 04-16-2024, 04:29 PM
      7 responses
      34 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by cls71, Today, 04:45 AM
      0 responses
      3 views
      0 likes
      Last Post cls71
      by cls71
       
      Started by mjairg, 07-20-2023, 11:57 PM
      3 responses
      214 views
      1 like
      Last Post PaulMohn  
      Started by TheWhiteDragon, 01-21-2019, 12:44 PM
      4 responses
      546 views
      0 likes
      Last Post PaulMohn  
      Started by GLFX005, Today, 03:23 AM
      0 responses
      3 views
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Working...
      X