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 bortz, 11-06-2023, 08:04 AM
        47 responses
        1,602 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        12 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X