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 [I][B][COLOR="Red"]entrySignal [/COLOR][/B][/I]called "LStop"
    ExitLongLimit(DTarget,"LTarget"); //exit the position opened by the [COLOR="red"][I][B]entrySignal [/B][/I][/COLOR]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?

      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 argusthome, 03-08-2026, 10:06 AM
        0 responses
        61 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        40 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        21 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        23 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        51 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X