Announcement

Collapse
No announcement yet.

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.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    93 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    152 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    80 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    54 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    65 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X