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

EnterLongLimit doesn't submit order

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

    EnterLongLimit doesn't submit order

    Hello All!

    I'm working on strategy with the next logic:

    According the defined conditions I submit EnterLongLimit with defined price.
    On every new bar close I check the change of desired EnterLongLimit price
    and if it is different from previously submitted price - I change EnterLongLimit order price by submitting new order with the same name.
    After entry order filled I submit ExitLongLimit and manage it in the same manner -
    if some values change on new bar, I change ExitLongLimit order price.
    Stop market order is activated by bar close below some value.

    I'm testing strategy part by part on sim account running it on small timeframe

    Generally first part of code is next:

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class SampleCancelOrder : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"";
    Name = "checkit";
    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;
    }

    }

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

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    if (Condition == true)
    {
    EnterLongLimit(0, true, 1, LimitPrice, "long limit entry"); //Limit price is lower that current

    }

    else if (Condition[0] != Condition[1])
    {
    EnterLongLimit(0, true, 1, NewLimitPrice, "long limit entry"); //Limit price is lower that current
    }
    }
    }
    }

    Here I got the next issue:
    starting the strategy it opens fantom position at the defferent from current price and doesn't submit any realtime order.
    I suppose that it must hold EnterLongLimit order with the defined price (lower than current) and change it on every new bar.
    But nothing happens.

    Please assist

    Regards

    #2
    Hello makhmout,

    Thank you for your inquiry.

    I note that you have "Wait until flat" selected for the 'Start behavior' option in the strategy parameters.

    This means that once the strategy has finished processing the historical data and has transitioned to real-time, it will wait until there is a real-time order submission that will cause the strategy to become flat. This also includes changing from a long position to a short position or vice versa as the position would pass through flat. Until this occurs, the strategy name will be shown in yellow on the Strategies tab of the Control Center, and no real time orders will be submitted until the strategy calculates it would be in a flat position.

    Below is a link to the help guide on the strategy parameters.

    http://ninjatrader.com/support/helpG...tegyProperties

    As well as a link to the start behavior options.

    http://ninjatrader.com/support/helpG..._positions.htm

    To change the behavior here, you have a couple of options.

    You can change the start behavior to "Immediately submit, Synchronize Account" in the parameters of the strategy. This means that if in the historical data the strategy submitted an order to enter a long position, once the strategy has transitioned to processing real-time data it will use this long position as the live position (and will not wait to become flat first). Any working orders that are still in a working state when the strategy transitions from historical to live (such as protective stop losses and profit targets) it will submit as live orders when the strategy is started. It will also submit a synchronization order to bring your account to the same position the strategy has calculated.

    https://ninjatrader.com/support/helpGuides/nt8/index.html?syncing_account_positions.htm#WaitUntil FlatSynchronizeAccount

    The start behavior can also be set in the State.SetDefaults of the script to default to a particular selection.

    http://ninjatrader.com/support/helpG...rtbehavior.htm

    You could also modify your script so that it only places orders if the data is real-time data. To do this you will need to edit the code of your script directly, as the Historical public variable is not available to the Strategy Builder.

    The code needed would be some thing like:

    if (State != State.Realtime)
    return;

    This condition checks to see if the script is not processing real-time data (meaning it is processing historical data) and if true will stop any code appearing after it in the same method from evaluating.

    This can also be written as:

    if (State == State.Historical)
    return;

    This checks to see if the script is processing historical data and will stop processing if true (which is the same condition and action as above). If this logic is placed at the beginning of OnBarUpdate, the strategy will not process until it reaches real-time data and will not calculate historically. If this is placed in the conditions for making an order, it will prevent the order from being placed until the strategy reaches real-time data.

    You could also optionally trigger any open position to exit with an exit market order on the last historical bar. To find the last historical bar:

    if (State == State.Historical && CurrentBar == Count — 2)

    Below is a link to the help guide on the 'State' NinjaScript property.

    http://ninjatrader.com/support/helpG...n-us/state.htm


    Please let me know if this does not resolve your inquiry.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AaronKoRn, Today, 09:49 PM
    0 responses
    2 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    8 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    9 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,975 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X