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 wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        26 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, Yesterday, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        192 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,234 views
        0 likes
        Last Post xiinteractive  
        Working...
        X