• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

order cancellation message

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

  • NinjaTrader_ChelseaB
    replied
    Hi brucelevy,

    Without using IOrders:

    Code:
    In #region Variables
    private double myPrice = 0;
    private IOrder myEntry;
    
    In OnBarUpdate:
    if (/*conditions to enter here*/ true)
    {
    myPrice = Close[0] - 10 * TickSize;
    if (myPrice >= GetCurrentAsk())
    {
    SetStopLoss(CalculationMode.Price, myPrice);
    EnterShort("entryOrder");
    }
    }
    
    In OnExecution:
    if (execution.Name == "entryOrder")
    {
    myPrice = myEntry.AvgFillPrice - 10 * TickSize;
    if (myPrice >= GetCurrentAsk())
    {
    SetStopLoss(CalculationMode.Price, myPrice);
    }
    }
    }

    Leave a comment:


  • brucelevy
    replied
    Is there a simpler way to program this without getting into IOrder methods which I don't understand

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello brucelevy,

    When using SetStopLoss its best to place the stop loss before placing the entry order. You can always modify it later.

    Lets say that I want my stop loss to be 10 ticks below my entry.

    private double myPrice = 0;
    private IOrder myEntry;

    if (/*conditions to enter here*/true)
    {
    myPrice = Close[0]-10*TickSize;
    if (myPrice >= GetCurrentAsk())
    {
    SetStopLoss(CalculationMode.Price, myPrice);
    myEntry = EnterShort();
    }

    In OnExecution():
    if (execution.Order == myEntry)
    {
    myPrice = myEntry.AvgFillPrice-10*TickSize;
    if (myPrice >= GetCurrentAsk())
    {
    SetStopLoss(CalculationMode.Price, myPrice);
    }
    }

    Leave a comment:


  • brucelevy
    replied
    Can you give an example of myPrice being referenced to the entryprice

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello brucelevy,

    May I confirm for your SetStopLoss that you have checked the price you are setting the stop loss to and that this is above the current ask price?

    double myPrice = 0;

    (myPrice would then be set to some calculated price)

    if (myPrice >= GetCurrentAsk())
    {
    SetStopLoss(CalculationMode.Price, myPrice);
    }

    May I confirm that you are checking this price is a valid and acceptable price before you are placing the order?

    Leave a comment:


  • brucelevy
    replied
    I am just using SetStopLoss

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi brucelevy,

    I'm jumping back to post #11.

    If you are getting prints then this means your code is cancelling the order.

    Are you wanting to exit the trade when LinReg(14) crosses below the KAMA(2, 10, 30), 1)?
    (I cannot answer if this is right or wrong, this depends on what you want the script to do which I cannot answer).

    Are you finding that the trade is exited before the print appears in the output window?

    Also, a buy limit order must be above the current ask price.
    A buy stop or stop limit must be below the current ask price.

    A sell limit order must be below the current bid price.
    A sell stop or stop limit must be above the current ask price.

    May I confirm that if you are using a buy limit order that this is above the ask price?
    (For more information about why these orders must be above or below the market price please contact your broker)

    Leave a comment:


  • brucelevy
    replied
    It tried to go short and said I cant put a buy stop limit below the market... I dont know why its trying to put stop losses below the sell when the code doesnt say to do that..

    Leave a comment:


  • brucelevy
    replied
    Here is what I have for an ES long position that went off and immediately closed out at breakeven
    Output window:

    9/25/2015 11:15:00 AMLong Entry L2Flat
    9/25/2015 11:15:00 AM | exiting order L2

    Log:

    https://i.gyazo.com/666757ce010451ef...e946dcbf59.png

    Executions page:

    https://gyazo.com/c6be94cd853061e0d40eaa4ad8e3b01d
    Last edited by brucelevy; 09-25-2015, 09:20 AM.

    Leave a comment:


  • brucelevy
    replied
    Is this correct where it says if market position is short AND Ling Reg cross above KAMA exit short?
    It should exit the short position if the linreg crosses above the kama...

    if (Position.MarketPosition == MarketPosition.Short
    && CrossAbove(LinReg(14), KAMA(2, 10, 30), 1))
    {
    ExitShort("", "S1");
    Print(Time[0]+" | exiting order S1");


    }

    Leave a comment:


  • brucelevy
    replied
    Can you look over the script if I send it to you?

    Leave a comment:


  • brucelevy
    replied
    It just says exiting order continuously..


    9/25/2015 10:52:40 AM | exiting order L2
    9/25/2015 10:52:40 AM | exiting order L3
    9/25/2015 10:52:40 AM | exiting order L4
    9/25/2015 10:52:40 AM | exiting order S2
    9/25/2015 10:52:40 AM | exiting order S4
    9/25/2015 10:52:40 AM | exiting order S5
    9/25/2015 10:53:07 AM | exiting order L2
    9/25/2015 10:53:07 AM | exiting order L3
    9/25/2015 10:53:07 AM | exiting order L4
    9/25/2015 10:53:07 AM | exiting order S2
    9/25/2015 10:53:07 AM | exiting order S4
    9/25/2015 10:53:07 AM | exiting order S5
    9/25/2015 10:53:17 AM | exiting order L2
    9/25/2015 10:53:17 AM | exiting order L3
    9/25/2015 10:53:17 AM | exiting order L4
    9/25/2015 10:53:17 AM | exiting order S2
    9/25/2015 10:53:17 AM | exiting order S4
    9/25/2015 10:53:17 AM | exiting order S5

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello brucelevy,

    Looking at the provided code (I cannot say wether or not the issue is with code that was not included) the following could be exiting your order:
    Code:
    if(Position.MarketPosition == MarketPosition.Long 
    && CrossBelow(LinReg(14), KAMA(2, 10, 30), 1))
    {
    ExitLong("", "L1");
    }
    Try a print to see if this is the order causing the exit.

    Code:
    if(Position.MarketPosition == MarketPosition.Long 
    && CrossBelow(LinReg(14), KAMA(2, 10, 30), 1))
    {
    Print(Time[0]+" | exiting order")
    ExitLong("", "L1");
    }
    Do you see this print appear at the time the order is closed?

    Leave a comment:


  • brucelevy
    replied
    I'd like to first find out why the trades are exiting prematurely. Here is the long exit condition set (flip for shorts)

    // Exit Long Condition
    if(Position.MarketPosition == MarketPosition.Long
    && CrossBelow(LinReg(14), KAMA(2, 10, 30), 1))
    {
    ExitLong("", "L1");

    }

    // Swing Stop

    if(Position.MarketPosition == MarketPosition.Long)
    {
    SetStopLoss(CalculationMode.Price, Swing(5).SwingLow[0] - 3 * TickSize);
    }

    //breakeven at 9 ticks then plus 2

    if (Position.MarketPosition == MarketPosition.Long
    && Close[0] > Position.AvgPrice + 9 * TickSize)
    {
    SetStopLoss(Position.AvgPrice + 2 * TickSize);
    }
    //trail on KAMA after x ticks

    if (Position.MarketPosition == MarketPosition.Long
    && Close[0] > Position.AvgPrice + 12 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, KAMA(2, 10, 30)[0] - 1 * TickSize);
    }

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi brucelevy,

    To assist I will need information.

    What do you want to troubleshoot first?

    Do you want to find out why orders are being rejected?
    Do you want to know why the exit order was cancelled after the entry order trade was closed?

    The exit order that closed the trade on the chart is just named Sell. This means that it was not a stop loss that exited the order.

    Do you call ExitLong, ExitLongLimit, or ExitLongStopLimit anywhere in your code?

    Having added prints to each condition to see what time each condition is being triggered?
    May we see these prints?

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by cutzpr, 07-09-2020, 09:19 PM
2 responses
22 views
0 likes
Last Post kissandfly  
Started by Mirasol, 05-09-2018, 04:48 AM
22 responses
1,869 views
1 like
Last Post kissandfly  
Started by catinabag, Today, 07:31 AM
2 responses
9 views
0 likes
Last Post catinabag  
Started by login_dejavu, Today, 07:28 AM
0 responses
8 views
0 likes
Last Post login_dejavu  
Started by catinabag, Today, 07:01 AM
1 response
7 views
0 likes
Last Post catinabag  
Working...
X