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

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:



    Executions page:

    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 Taddypole, 04-26-2024, 02:47 PM
1 response
12 views
0 likes
Last Post NinjaTrader_Eduardo  
Started by futtrader, 04-21-2024, 01:50 AM
6 responses
58 views
0 likes
Last Post futtrader  
Started by sgordet, Today, 11:48 AM
0 responses
4 views
0 likes
Last Post sgordet
by sgordet
 
Started by Trader146, Today, 11:41 AM
0 responses
5 views
0 likes
Last Post Trader146  
Started by jpapa, 04-23-2024, 07:22 AM
2 responses
20 views
0 likes
Last Post rene69851  
Working...
X