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 will not enter position

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

    Strategy will not enter position

    Hello,

    I am working on a strategy that works with cumulative delta. The code from my perspective looks fine but there is some issue that stops it from entering into a new position. If anyone can see an issue with these few lines of code and point it out it would be greatly appreciated.

    protected override void OnBarUpdate()
    {

    if (CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)
    return;

    // Set 1
    if ((TriggerState >= 2)
    && (Position.MarketPosition == MarketPosition.Flat))
    {
    TriggerState = 0;
    }

    if (Close[1] > Open[1] && OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 1)[1] < 0 && Position.MarketPosition == MarketPosition.Flat)
    {
    TriggerState = 1;
    EnterLong(Quantity, "long");
    SetProfitTarget(CalculationMode.Ticks, BuyProfit);

    }
    else if (Close[1] < Open[1] && OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 1)[1] > 0 && Position.MarketPosition == MarketPosition.Flat)
    {
    TriggerState = 1;
    SetProfitTarget(CalculationMode.Ticks, SellProfit);
    EnterShort(Quantity, "short");
    }



    Thanks in advance!

    #2
    Hello cpbeamer,

    Thanks for your post.

    In the code you shared, I see that you are calling SetProfitTarget() in OnBarUpdate() and are not resetting the target price/offset value when your strategy is flat as stated in the Tips section of the SetProfitTarget help guide page.

    "Should you call this method to dynamically change the target price in the strategy OnBarUpdate() method, you should always reset the target price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your profit target order on your next open position"

    For example:
    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetProfitTarget(CalculationMode.Ticks, ProfitTargetTicks);
    }
    Also, SetProfitTarget(CalculationMode.Ticks, BuyProfit); should be called before your Entry method just like you are doing with SetProfitTarget(CalculationMode.Ticks, SellProfit);.

    SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm

    Otherwise, I do not see anything specific that would prevent the strategy from placing orders. Debugging steps would need to be taken to determine how your strategy is behaving.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ZenCortexAuCost, Today, 04:24 AM
    0 responses
    5 views
    0 likes
    Last Post ZenCortexAuCost  
    Started by ZenCortexAuCost, Today, 04:22 AM
    0 responses
    2 views
    0 likes
    Last Post ZenCortexAuCost  
    Started by SantoshXX, Today, 03:09 AM
    0 responses
    15 views
    0 likes
    Last Post SantoshXX  
    Started by DanielTynera, Today, 01:14 AM
    0 responses
    3 views
    0 likes
    Last Post DanielTynera  
    Started by yertle, 04-18-2024, 08:38 AM
    9 responses
    42 views
    0 likes
    Last Post yertle
    by yertle
     
    Working...
    X