Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't get this exit strategy to work....

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

  • NinjaTrader_Lance
    replied
    Originally posted by CoopGeko View Post
    I use the strategy on a 1-day, 5-min chart with ES as primary bars object and SPY as Secondary (1).
    I'm seeing you add two SPY series and a 1 minute series for the Primary (ES as you stated)

    If you're running on a 1 day chart you will need to type 5 instead of 1 on your line 44: Add(PeriodType.Minute, 1);

    You then have 4 bar series in the strategy but I'm only seeing you handle the BIP 0 (primary series) and BIP 1 (in this case its a 1 minute chart of the primary series)

    Additionally you have some oddly placed brackets.

    Code:
    if (BarsInProgress == 1)
                {ExitShortStop(1, true, 1, Position.AvgPrice + 8 * TickSize, "SHORTstop", "SHORT");}
                {ExitShortLimit(1, true, 1, Position.AvgPrice - 6 * TickSize, "SHORTtarget", "SHORT");}
                {ExitLongStop(1, true, 1, Position.AvgPrice - 8 * TickSize, "LONGstop", "LONG");}
                {ExitLongLimit(1, true, 1, Position.AvgPrice + 6 * TickSize, "LONGtarget", "LONG");}
    You should not be bracketing your exit orders like this.

    Please see the following as an example of how to use BarsInProgress: http://www.ninjatrader.com/support/h...nstruments.htm

    Let me know if I can be of further assistance.

    Leave a comment:


  • CoopGeko
    replied
    Thanks Koganam and Sledge.....

    I've attached the script here.....

    I'm brand new to this and I'm sure there are many ways of coding this idea where the final result would be the same, but in a nutshell what I'm trying to do is enter one instrument at the exact time another instrument breaks a predetermined level. And then have the script full manage the exit. The exit is is a bracket order with an adjustable break even stop so that after primary instrument has moved most of the way to the target, then the stop is moved to a tick above breakeven.

    I'm probably mixing oranges and apples in the code...

    I use the strategy on a 1-day, 5-min chart with ES as primary bars object and SPY as Secondary (1).

    The Idea is that if SPY breaks to a new intraday low (for example 147.50 on Friday), I want to go long ES with a market order.
    Attached Files

    Leave a comment:


  • sledge
    replied
    Like Koganam suggested, just to confirm - you are in a position and there are no exits being generated?

    Can you post something that is 'complete' but not related to your strategy that we could reproduce?



    Have you tried using the output window with Print statements to print the values of the conditions or if you are entering the conditional area?


    if (BarsInProgress == 1)
    {
    Print ( "BIP==1 ExitLongStop Entering $" + (Position.AvgPrice - 8 * TickSize ));
    ExitLongStop(1, true, 1, Position.AvgPrice - 8 * TickSize, "LONGstop", "LONG");
    }

    {
    Print ("BIP==1 ExitLongLimit Entering $" + (Position.AvgPrice + 6 * TickSize ));
    ExitLongLimit(1, true, 1, Position.AvgPrice + 6 * TickSize, "LONGtarget", "LONG");
    }

    (and did you really mean to not use an ELSE in there ?)



    Originally posted by CoopGeko View Post
    Here's the entry code......it calls a different BarsArray....(2)......


    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()




    {
    if (BarsInProgress == 0)
    {

    // Condition set 2- LONG SETUP
    if (Lows[2][0] <= -375)
    {
    EnterLong(DefaultQuantity,
    "LONG");

    }
    }

    Leave a comment:


  • CoopGeko
    replied
    Here's the entry code......it calls a different BarsArray....(2)......


    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()




    {
    if (BarsInProgress == 0)
    {

    // Condition set 2- LONG SETUP
    if (Lows[2][0] <= -375)
    {
    EnterLong(DefaultQuantity,
    "LONG");

    }
    }

    Last edited by CoopGeko; 01-19-2013, 10:05 PM.

    Leave a comment:


  • koganam
    replied
    Originally posted by CoopGeko View Post
    Hi-

    While the below code compiles fine, it does not send out any exit orders.....



    if (BarsInProgress == 1)
    {ExitLongStop(1, true, 1, Position.AvgPrice - 8 * TickSize, "LONGstop", "LONG");}
    {ExitLongLimit(
    1, true, 1, Position.AvgPrice + 6 * TickSize, "LONGtarget", "LONG");}



    {
    // If a long position is open, allow for stop loss modification to breakeven
    if (Position.MarketPosition == MarketPosition.Long)

    {
    // Once the price is greater than entry price+12 ticks, set stop loss to breakeven + 2 ticks
    if (High[0] > Position.AvgPrice + 12 * TickSize)

    {

    ExitLongStop(
    1, true, 1, Position.AvgPrice + 2 * TickSize, "LX", "LONG");

    }




    }


    Any thoughts?
    Looking only at the code that you have posted, you cannot exit a position unless a position already exists. Your block brackets also seem to be strange, but without seeing your entry code, it is hard to say for sure.
    Last edited by koganam; 01-19-2013, 11:32 PM.

    Leave a comment:


  • CoopGeko
    started a topic Can't get this exit strategy to work....

    Can't get this exit strategy to work....

    Hi-

    While the below code compiles fine, it does not send out any exit orders.....



    if (BarsInProgress == 1)
    {ExitLongStop(1, true, 1, Position.AvgPrice - 8 * TickSize, "LONGstop", "LONG");}
    {ExitLongLimit(
    1, true, 1, Position.AvgPrice + 6 * TickSize, "LONGtarget", "LONG");}



    {
    // If a long position is open, allow for stop loss modification to breakeven
    if (Position.MarketPosition == MarketPosition.Long)

    {
    // Once the price is greater than entry price+12 ticks, set stop loss to breakeven + 2 ticks
    if (High[0] > Position.AvgPrice + 12 * TickSize)

    {

    ExitLongStop(
    1, true, 1, Position.AvgPrice + 2 * TickSize, "LX", "LONG");

    }




    }


    Any thoughts?

Latest Posts

Collapse

Topics Statistics Last Post
Started by giulyko00, Yesterday, 12:03 PM
3 responses
12 views
0 likes
Last Post NinjaTrader_BrandonH  
Started by habeebft, Today, 07:27 AM
1 response
14 views
0 likes
Last Post NinjaTrader_ChristopherS  
Started by AveryFlynn, Today, 04:57 AM
1 response
12 views
0 likes
Last Post NinjaTrader_Erick  
Started by Max238, Today, 01:28 AM
5 responses
39 views
0 likes
Last Post Max238
by Max238
 
Started by r68cervera, Today, 05:29 AM
1 response
10 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X