• 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

Problem with Exit

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

    Problem with Exit

    I have the following problem with my exit script.

    if(Position.MarketPosition == MarketPosition.Long)
    {
    if (CrossBelow(Close,DayOpen, 1))
    ExitLong();

    double DStop = Position.AvgPrice-stop;
    double DTarget=Position.AvgPrice+target;
    PrintWithTimeStamp("Entered Long. DayOpen is:"+DayOpen.ToString()+"EntryPrice :"+Position.AvgPrice+" ProfitTarget :"+DTarget.ToString()+ " Stop :"+DStop.ToString());
    //SetStopLoss("LE",CalculationMode.Price,Position.Av gPrice-DStop,false);
    //SetProfitTarget("LE",CalculationMode.Price,Positio n.AvgPrice+DTarget);
    ExitLongStop(DStop,"LStop");
    ExitLongLimit(DTarget,"LTarget");
    }

    Here is the print log output for the trade in question:
    9/29/2014 1:40:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:41:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:42:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:43:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:44:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:45:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:46:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:47:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:48:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:49:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:50:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    The trade exits on the close and the market traded much higher than my entryprice.

    Here is a copy from the analyzer :
    Trade-# Instrument Account Strategy Market pos. Quantity Entry price Exit price Entry time Exit time Entry name Exit name Profit Cum. profit Commission MAE MFE ETD Bars 214 ES 12-14 Backtest SGHScalper Long 1 1964.75 1968.5 9/29/2014 1:40 PM 9/29/2014 4:15 PM Buy Exit on close 187.5 1987.5 0 50 462.5 275 141

    What is wrong with my logic?

    Thank you,

    David

    #2
    Originally posted by Cowpux View Post
    I have the following problem with my exit script.

    if(Position.MarketPosition == MarketPosition.Long)
    {
    if (CrossBelow(Close,DayOpen, 1))
    ExitLong();

    double DStop = Position.AvgPrice-stop;
    double DTarget=Position.AvgPrice+target;
    PrintWithTimeStamp("Entered Long. DayOpen is:"+DayOpen.ToString()+"EntryPrice :"+Position.AvgPrice+" ProfitTarget :"+DTarget.ToString()+ " Stop :"+DStop.ToString());
    //SetStopLoss("LE",CalculationMode.Price,Position.Av gPrice-DStop,false);
    //SetProfitTarget("LE",CalculationMode.Price,Positio n.AvgPrice+DTarget);
    ExitLongStop(DStop,"LStop");
    ExitLongLimit(DTarget,"LTarget");
    }

    Here is the print log output for the trade in question:
    9/29/2014 1:40:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:41:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:42:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:43:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:44:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:45:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:46:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:47:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:48:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:49:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    9/29/2014 1:50:00 PM Entered Long. DayOpen is:1964EntryPrice :1964.75 ProfitTarget :1965.75 Stop :1963.25

    The trade exits on the close and the market traded much higher than my entryprice.

    Here is a copy from the analyzer :
    Trade-# Instrument Account Strategy Market pos. Quantity Entry price Exit price Entry time Exit time Entry name Exit name Profit Cum. profit Commission MAE MFE ETD Bars 214 ES 12-14 Backtest SGHScalper Long 1 1964.75 1968.5 9/29/2014 1:40 PM 9/29/2014 4:15 PM Buy Exit on close 187.5 1987.5 0 50 462.5 275 141

    What is wrong with my logic?

    Thank you,

    David
    You have used he wrong syntax.
    Code:
    ExitLongStop(DStop,"LStop");//exit the position opened by the entrySignal called "LStop"
    ExitLongLimit(DTarget,"LTarget"); //exit the position opened by the entrySignal called "LTarget"
    The names you have used give me the impression that those must be exitSignal names.

    Comment


      #3
      Hello Cowpux,

      Thank you for your post.

      Koganam is correct, you must use the entrySignalName string. Are you using an entrySignalName for your Enter() method? Can you provide the full syntax used for your Enter() method?
      Patrick H.NinjaTrader Customer Service

      Comment


        #4
        Thanks to both of you. I fixed it. I need to look at the function definitions a bit closer!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Hanstanz, Today, 04:44 AM
        0 responses
        2 views
        0 likes
        Last Post Hanstanz  
        Started by juniortut, Today, 04:38 AM
        0 responses
        1 view
        0 likes
        Last Post juniortut  
        Started by rojiinko, Today, 03:58 AM
        0 responses
        1 view
        0 likes
        Last Post rojiinko  
        Started by mreanuzlazx, Today, 01:30 AM
        0 responses
        1 view
        0 likes
        Last Post mreanuzlazx  
        Started by xinepev, Today, 12:33 AM
        0 responses
        4 views
        0 likes
        Last Post xinepev
        by xinepev
         
        Working...
        X