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

Coding in Displacement for Bollinger Visual Plot?

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

  • NinjaTrader_ChelseaB
    replied
    Hello ComfyCouch,

    The position becomes 1 long. The Entries per direction is 1. You are allowing one entry order in a direction. Once the position is taken further orders will be ignored (this is discussed in the Strategy Builder 301 training video).

    From the output:
    12/7/2020 6:23:00 PM | myEntryOrder is null (Long Limit Order)

    - The position is long 1 and will ignore further entries until the position is back to flat
    12/7/2020 6:23:00 PM | EntriesPerDirection: 1 < 1; Long

    - A new entry is attempted however the position already has 1 entry and will ignore further entries
    12/7/2020 6:23:00 PM Strategy 'TestStrat': Entered internal SubmitOrderManaged() method at 12/7/2020 6:23:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.75 StopPrice=0 SignalName='Long' FromEntrySignal=''

    - The new entry is ignored
    12/7/2020 6:23:00 PM Strategy 'TestStrat': Ignored SubmitOrderManaged() method at 12/7/2020 6:23:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.75 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
    Last edited by NinjaTrader_ChelseaB; 02-09-2021, 04:27 PM.

    Leave a comment:


  • ComfyCouch
    replied
    Hi ChelseaB,

    Thanks for the reply. Currently, I have EntriesPerDirection set to default (at 1) and EntryHandling to AllEntries.

    Here's the text file as requested.

    OutputDebug2.txt

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello ComfyCouch,

    EntriesPerDirection prevents new entries after the number of entries in a position have been filled.

    This is discussed in the Strategy Builder 301 training video. Below is a link to a forum post with helpful information about getting started with NinjaScript.


    What do you have EntriesPerDirection set to?

    Print EntriesPerDirection and print the position and size.

    Print(string.Format("{0} | EntriesPerDirection: {1} < {2} {3}, Time[0], EntriesPerDirection, Position.Quantity, Position.MarketPosition));

    Save the output to a text file and include this with your reply.

    Leave a comment:


  • ComfyCouch
    replied
    Hi ChelseaB,

    Hope everything is well. Shortly after your post and with the help of Print() statements, I managed to figure out the root of the problem on why orders were not going through. After some revision to the code, I finally got it to work.

    Recently, however, I decided to try to play around with the addition of target/stop-loss orders to manage different risk and reward situations. However, I encountered a situation where any order placed after EnterLongLimit results in an error: "Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties".

    I attached two text files beneath - one for the what shows up in the Output window and the other, the code. From my basic - dumb understanding, it seems like it's stuck in some loop with the LongLimitOrders, as the Print() statements for any canceled orders or orders from targets/stop-loss are not showing up.

    Code.txt
    OutputDebug.txt


    As always, thank you for your continued help.
    Attached Files
    Last edited by ComfyCouch; 02-09-2021, 12:33 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello ComfyCouch,

    At what time is the order being submitted that is not being filled?

    I only see one place that the entry order 'Long' was submitted:

    12/7/2020 6:22:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:22:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.75 StopPrice=0 SignalName='Long' FromEntrySignal=''

    At what time are you seeing another Long order being submitted in the output from TraceOrders?


    Can you save the output to a text file and include this as an attachment? This keeps your posts short and includes the full output from the output window.
    (See the forum thread post on using prints for detailed steps on saving the output to a text file)

    May I confirm you have watched the video under the label 'Below I am providing a link to videos that demonstrate adding prints to a script to get further information about the behavior of the script." in it's entirety? (You will need to follow the steps in this video to print the values to confirm a cross above)


    Are you wanting to know why the conditions are not submitting the order again?

    Use Prints() to understand the behavior as I have directed in post #13 and post #21.

    For the condition:
    Code:
    if (myEntryOrder == null && CrossAbove([I]longcondition[/I], 3))
    Above add a print to confirm myEntryOrder is null:
    Code:
    if (myEntryOrder == null)
    Print(Time[0].ToString() + " | myEntryOrder is null);
    This will let you know you have properly set the myEntryOrder to null for a new entry.

    Also print the current value of the longcondition series on the previous bar and current bar.
    Code:
    Print(string.Format("{0} | longcondition[1]: {1} < 3 && longcondition[0]: {2}  > 3", Time[0], longcondition[1], longcondition[0]));
    May I confirm that longcondition is a Series object? Otherwise this code will not compile. The space is not allowed either. This looks to be invalid code.


    Last edited by NinjaTrader_ChelseaB; 01-14-2021, 01:12 PM.

    Leave a comment:


  • ComfyCouch
    replied
    Hey Chelsea,

    Thanks for the reply. The exact issue I have is that the strategy only took one trade and did not take anymore trades after. I'm asking as to why is this happening. The debugging log seems to show that it knows it should be taking a trade when respective conditions are true/false, but as shown in the log, a limit price is not shown (therefore showing no trade is taken) and from this chart, no signals are made (also showing no trade is taken).

    Looking forward to your response.

    Click image for larger version

Name:	SignalChart.png
Views:	173
Size:	32.7 KB
ID:	1136798

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello,

    I'm trying to pick out the issue you are having. I'm reading "no actual limit price listed and no buy signal shown in the chart of Strategy Analyzer". Are you asking why an order that was submitted did not fill?

    Are you asking why an order was not submitted?

    Are you asking why an order was filled when you have attempted to cancel the order?

    Are you asking why an order was automatically cancelled?

    Leave a comment:


  • ComfyCouch
    replied
    Hi ChelseaB,

    I understand that a must prerequisite for NinjaScript is having the basic knowledge of C# and while having a very new entry level type experience to C#, I apologize if my previous post looked like a request for a handout. I'm grateful for the resources that NinjaTrader and it's wonderful support staff provide and have been using them every chance I get.

    I looked into ChrisL's post about isLiveUntilCancelled and saw the supplement of CancelOrder, and tried to to implement into my strategy to see if manually canceling the order changes anything in regards to my entries. After compiling, it seems that only one trade is made in the timespan of the backtest: where it enters at long condition and exits at exit condition (conditions are below). Afterwards, there are no further trades made, even though from sight, it is obvious other trades are possible. I figured at OnOrderUpdate, where myEntryOrder is set back to null, the strategy would "reset" and look for the next possible trade of when the long condition holds true, but however, it does not happen.

    With TraceOrder true, I decided to look at the debug and saw the following:

    With the first few minutes after BarsRequiredToTrade is met, when long condition is true, it rightfully takes a position at a limit price and then sells when exit condition is true, as shown by the gap between 6:22 and 6:38. This is also shown on the Chart, in Strategy Analyzer, with a long signal and exit signal. However, shown in the subsequent lines, long condition is met and a position should be taken and it looks like it kind of is (there's a gap shown in the time), but is not actually taken as shown by two things: no actual limit price listed and no buy signal shown in the chart of Strategy Analyzer. As a whole, in the span of two days (the time span of the quick backtest), it shows that only one trade (which is the first trade between 6:22 and 6:38) is taken in its whole duration.
    Is there something missing from when I added CancelOrder?

    Thanks for your time and help.

    12/7/2020 6:05:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:05:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:06:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:06:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.75 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:07:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:07:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3683.00 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:08:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:08:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3683.25 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:10:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:10:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:11:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:11:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:12:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:12:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:13:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:13:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:14:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:14:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:15:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:15:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:16:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:16:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:17:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:17:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.50 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:18:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:18:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.50 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:19:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:19:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3683.00 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:20:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:20:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='BarsRequiredToTrade has not been met'

    12/7/2020 6:21:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:21:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:21:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:21:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:22:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:22:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3682.75 StopPrice=0 SignalName='Long' FromEntrySignal=''

    12/7/2020 6:38:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:38:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:39:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:39:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:39:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:39:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:40:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:40:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:40:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:40:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:41:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:41:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:41:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:41:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:42:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:42:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:42:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:42:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:49:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:49:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:49:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:49:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:50:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:50:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''
    12/7/2020 6:50:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:50:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:51:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:51:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:51:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:51:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:52:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:52:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:52:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:52:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:53:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:53:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:53:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:53:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:54:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:54:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:54:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:54:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:55:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:55:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:55:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:55:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:56:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:56:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:56:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:56:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 6:57:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 6:57:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    12/7/2020 6:57:00 PM Strategy '-': Ignored SubmitOrderManaged() method at 12/7/2020 6:57:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

    12/7/2020 7:01:00 PM Strategy '-': Entered internal SubmitOrderManaged() method at 12/7/2020 7:01:00 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='EL' FromEntrySignal=''

    {
    private Order myEntryOrder = null;
    private int barNumberOfOrder = 0;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"-";
    Name = "-";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = true;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = true;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    IsInstantiatedOnEachOptimizationIteration = true;

    }
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 4)
    return;

    if (myEntryOrder == null && CrossAbove(long condition, 3))
    {
    EnterLongLimit(0, true, 1, Open[1], "Long");
    barNumberOfOrder = CurrentBar;

    }
    if (CurrentBar > barNumberOfOrder + 1)
    CancelOrder(myEntryOrder);


    if (*exit condition*)
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), @"EL", "");
    }

    }
    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {
    if (order.Name == "Long")
    myEntryOrder = order;
    if (myEntryOrder != null && myEntryOrder == order)
    {
    if (myEntryOrder.OrderState == OrderState.Cancelled)
    {
    myEntryOrder = null;
    }
    }
    }
    }
    }

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello ComfyCouch,

    If you are using the managed approach, you choose not to submit an order on a new bar and this will automatically be cancelled. Alternatively, you can supply the order object to CancelOrder().


    Please note, C# programming education comes prerequisite to writing NinjaScript code. The Strategy Builder can be used to see how it generates C# syntax, but please be aware that it is not with our Scripting Support team's scope to provide programming education services or to check your syntax. We highly recommend getting further acquainted with C# through a formal class, or through educational resources that can be found external to NinjaTrader.


    The Print() is intended to give you, the developer, more information so that you understand why the behavior of the script is behaving as it is, so that you can take steps to redesign the code. Using a print is like listening to a car engine to diagnose an issue. Listening to a car engine does not fix the issue, but instead lets you further understand what the issue is.

    Below is a link to a forum post that demonstrates using prints to understand behavior.

    Leave a comment:


  • ComfyCouch
    replied
    Hey ChrisL, thanks for replying back.

    I mentioned that early on that I'm not all experienced with C# and that's currently showing now: confused. I apologize.

    I think if I just plainly say what I'm trying to accomplish, it might be better for both of us.

    If my condition becomes true, I'd like to enter at the price of the previous candle's open. If the current candle does not reach the open price by the end of its close, then I'd like to cancel the order and wait for when the condition becomes true again. I'm not sure if the code that I gave two posts ago is correct in that it represents what I just said in this statement; please let me know whether or not it does and how I could correct this.

    Thank you for help thus far - the print function seemed to solve part of the entry problems (I think since I'm using ">" / "<" in my if conditions, it keeps the limit order active in each bar so long the condition stays true - - will changing to "crossAbove" and 'crossBelow" solve this?)

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    Hello ComfyCouch, thanks for your reply.

    If the limit orders are not re-submitted by the strategy on every bar they will be canceled. To keep the order alive without needing to resubmit them on every bar they should be kept alive, use the special overload that takes a IsLiveUntilCanceled parameter e.g.

    https://ninjatrader.com/support/help...rlonglimit.htm
    EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName) //set IsLiveUntilCanceled to true to keep the order alive until canceled.

    To check if the order has been alive for over 2 bars, save the CurrentBar value at the time of order submission to an int property in the Indicator class, then check for if(CurrentBar == StoredValue+2)

    The entries are not random, use Print statements within the strategy to see why conditions are becoming true. This will be highly dependent on the conditions within the IF condition e.g.

    Code:
    // Set 1
    if (condition here)
    {
        Print("Long Limit Condition True, Submitting order " + Time[0]);
        ExitShort(Convert.ToInt32(DefaultQuantity), @"ES", "");
        EnterLongLimit(Convert.ToInt32(DefaultQuantity), entryprice, "EL");
    }
    
    // Set 2
    Print("Checking Short Limit Condition " + Time[0]);
    if (condition here)
    {
        Print("Short Limit Condition True, Submitting order " + Time[0]);
        ExitLong(Convert.ToInt32(DefaultQuantity), @"EL", "");
        EnterShortLimit(Convert.ToInt32(DefaultQuantity), entryprice, "ES");
    }
    Please let us know if we can assist any further.

    Leave a comment:


  • ComfyCouch
    replied
    Hi Chelsea,

    Thank you for the reply, and I hope you had a great start to the year.

    I think you've addressed pretty much all of what I've had trouble with in this thread, and I thank you for that. I do have one other question/problem, that I'd like to ask help with.

    I wanted to test my strategies results with different entries. To do that, I decided to default back to Calculate.OnBarClose and try to implement a limit order (both Long and Short) at the price of the open of the previous candle (the candle that is right before the default entry candle) by using the syntax of EnterLongLimit/EnterShortLimit. However, when compiling, I'm getting what looks to be like random entries rather than what I want. I used the following to enter a limit position (and EnterLongLimit for a long):

    protected override void OnBarUpdate()
    {

    if (CurrentBars[0] < 4)
    return;

    double entryprice = Open[1];

    // Set 1
    if (condition here)
    {
    ExitShort(Convert.ToInt32(DefaultQuantity), @"ES", "");
    EnterLongLimit(Convert.ToInt32(DefaultQuantity), entryprice, "EL");
    }

    // Set 2
    if (condition here)
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), @"EL", "");
    EnterShortLimit(Convert.ToInt32(DefaultQuantity), entryprice, "ES");
    }

    }

    where entryprice is defined as Open[1] to represent the "previous candle" of the default entry candle (that NinjaTrader uses). What am I doing wrong here? Am I just completely off in my code? Furthermore, to follow up on this, I understand that all limit orders are likely not to be filled so in order to account for this, if my limit order is not filled, is it possible to make it so that it cancels that Limit order after 2 bars pass/till one of the conditions become true or is this done automatically?

    Thanks for your time and I look forward to your response.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello ComfyCouch,

    With the inquiry of orders being on the next bar, this happens if the order is submitted after the bar is closed. Meaning Calculate is OnBarClose, or this is historical data without intra-bar granularity and tick replay.

    https://ninjatrader.com/support/foru...377#post773377

    Displacement is a visual thing only. It doesn't change the bar values, it just changes how forward or backward that plot value appears visually on the chart. You have access to the same plot values. You can use them whenever you want. If you want to wait a few bars after the plot value appears you can. If you want to use values from previous bars, you can.

    Leave a comment:


  • ComfyCouch
    replied
    Hey Chelsea,

    Thanks for the reply, hope you had a great holiday weekend and everything is well.

    I took your advice and implemented your provided code. Comparing the current strategy results to a set of signals that I've verified from live trading, the signals do not match up. It seems like what's still happening is that the signal happens one bar too late (forward).

    I'm not sure if this has to do with displacement or this topic, but I noticed at the current bar (in strategy analyzer chart), there is no value for a non displaced MA. Instead, the value ends at the bar previous to it, and for a displaced Bollinger of -2, two bars previous to that. Could this be why some of the signals above are not lining up? It seems like all the signals I'm given in Strategy Analyzer are moved one bar forward.

    Thanks again and I look forward to your response.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello ComfyCouch,

    Displacment is only visual. For something displaced to the left, the current bars plot value is visually displayed on a bar to the left and there is no value displayed on the current bar.

    If there is no value on the current bar, do you want condition to be true and then wait a number of bars before triggering the action?

    Don't think in displacement. Think about what specific bar numbers you want to process information from.

    You can use bools and an int counter to wait a number of bars before triggering an action.

    Code:
    private bool conditionTriggered;
    private int barCount;
    
    conditionTriggered = false;
    
    if (conditionTriggered == false /* && your condition here */)
    {
    // the condition has been triggered, change bool and wait 2 bars before triggering action
    conditionTriggered = true;
    barCount = 0;
    }
    
    if (conditionTriggered && barCount > 2)
    {
    conditionTriggered = false;
    // we have waited two bars, trigger the action here
    } else
    {
    // it has not been two bars, increment the counter and continue waiting
    barCount++;
    }

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by maybeimnotrader, Yesterday, 05:46 PM
2 responses
22 views
0 likes
Last Post maybeimnotrader  
Started by adeelshahzad, Today, 03:54 AM
5 responses
32 views
0 likes
Last Post NinjaTrader_BrandonH  
Started by stafe, 04-15-2024, 08:34 PM
7 responses
32 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by merzo, 06-25-2023, 02:19 AM
10 responses
823 views
1 like
Last Post NinjaTrader_ChristopherJ  
Started by frankthearm, Today, 09:08 AM
5 responses
22 views
0 likes
Last Post NinjaTrader_Clayton  
Working...
X