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

OnPriceChange, Getting Too many Entries per direction!

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

    OnPriceChange, Getting Too many Entries per direction!

    Hello, my name is Roberto.

    Im trying to make a strategy based on the following context:

    If the Volume of Candle [0] is twice as big of Candle[1], in that precise moment EnterLong.

    I have managed to accomplish this, by changing the Calculate. OnPriceChange. But the issue that Im having is that the Entry does 5 or six times in the same candle. Because once the position gets filled then it enters another position in the same candle and I wish only to enter one time in the candle.

    (Im guessing that once it went above twice of the last candle, every time it goes higher is twice as last candle!!! But not sure!.)

    Can you please Help me out


    Calculate = Calculate.OnPriceChange;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.ImmediatelySubmit;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;


    This is What I have on settings!.

    #2
    Hello RobertoPaez,

    Thank you for your post.

    You'd want to use BarsSinceEntryExecution to control whether it can enter again in the same bar:



    Here's a simple example:

    Code:
    protected override void OnBarUpdate()
    {
        if (CurrentBar < BarsRequiredToTrade)
            return;
    
        // Only enter if at least 10 bars has passed since our last entry or we have not yet entered, and our cross condition is true
        if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
            EnterLong();
    
    }
    In your case, since you only want to enter if it's not the same bar as the previous entry, you'd want to use:

    if ((BarsSinceEntryExecution() >= 1 || BarsSinceEntryExecution() == -1) && //additional conditions go here)

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Started by alifarahani, Today, 09:40 AM
    6 responses
    41 views
    0 likes
    Last Post alifarahani  
    Working...
    X