Exit of market in tradeprice

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #145582 quote
    Fran55
    Participant
    Veteran

    I need code. I have a position, after 12 hours in the market it is in losses. I want that if the price returns to the purchase price the operation is closed.

    #145593 quote
    robertogozzi
    Moderator
    Master

    There you go:

    If Not OnMarket then
       Count = 0
    Else
       If Hour <> Hour[1] Then
          x = 1
          If Hour < Hour[1]
             x = ((Hour + 24) - Hour[1])
          Endif
          Count = Count + x
          If Count >= 12 And PositionPerf < 0 Then
               Sell at Market
                Exitshort at Market
           Endif
       Endif
    Endif
    #145631 quote
    Fran55
    Participant
    Veteran

    Like doing the same thing but with 5-minute bars. Instead of 12 hours it would be 144 bars of 5 minutes.

     

    The trade begins, if after 144 bars of 5 minutes the trade is lost, if the quote returns to the purchase price the trade is closed.

     

    Thanks, and sorry.

    #145737 quote
    Fran55
    Participant
    Veteran

    I think your code does not work Roberto, also

    I would need the code but with 5 minute bars.

    Operation opens.
    If after 144 bars the operation is in losses, if the price returns to the purchase point, the operation is closed.

    Thanks!

    #145751 quote
    robertogozzi
    Moderator
    Master

    Yes, my fault, I exited at market.

    Replace lines 11-12 with:

    Sell      at PositionPrice LIMIT
    Exitshort at PositionPrice LIMIT

    I’ll make the other code later.

    Please do NOT use the “insert PRT code” button to enter common text. Use it only for code, instead.

    #145757 quote
    Fran55
    Participant
    Veteran

    Thanks Roberto.

     

    🙂

    #145761 quote
    Vonasi
    Moderator
    Master

    Fran55 – Please be more careful when posting. Your last two posts have had attached HTML (from I guess cutting and pasting translations) which moderators have had to tidy up to make your posts readable.

    #145779 quote
    Fran55
    Participant
    Veteran

    Ok Roberto.

     

    I always have problems with translators, sorry.

    One more thing:
    I want to do the same with%.
    That is … I have a position, I want that if the position loses 1% and returns to the purchase price, the operation is closed.

    Thank you very much!

    #145787 quote
    robertogozzi
    Moderator
    Master

    This is the code with the 3 different ways to exit when in loss:

    //////////////////////////////////////////////////////////////////////////////
    //  ---  Exit at Entry Price if losing AFTER N hours
    If Not OnMarket then
       Count = 0
    Else
       If Hour <> Hour[1] Then
          x = 1
          If Hour < Hour[1] Then
             x = ((Hour + 24) - Hour[1])
          Endif
          Count = Count + x
          If Count >= 12 And PositionPerf < 0 Then                  //12 hours
             Sell      at PositionPrice LIMIT
             Exitshort at PositionPrice LIMIT
          Endif
       Endif
    Endif
    //////////////////////////////////////////////////////////////////////////////
    //  ---  Exit at Entry Price if losing AFTER N bars
    If OnMarket then
       If (BarIndex - TradeIndex) >= 144 And PositionPerf < 0 Then  //144 bars
          Sell      at PositionPrice LIMIT
          Exitshort at PositionPrice LIMIT
       Endif
    Endif
    //////////////////////////////////////////////////////////////////////////////
    //  ---  Exit at Entry Price if losing 1%+
    If Not OnMarket then
       ExitFlag = 0
    Else
       If ((PosiTionPerf * 100) <= -1) OR ExitFlag THEN              //1%  loss
          ExitFlag = 1
          Sell      at PositionPrice LIMIT
          Exitshort at PositionPrice LIMIT
       Endif
    Endif
    //////////////////////////////////////////////////////////////////////////////
    
    ichimoku18 and MAKSIDE thanked this post
    #145788 quote
    Fran55
    Participant
    Veteran

    Much, much, thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    #146037 quote
    Fran55
    Participant
    Veteran

    Okay. And if I want it to close 0.5% above the purchase price ???

    #146047 quote
    robertogozzi
    Moderator
    Master

    We cannot always tidy up your code!

    Please use plain text without embedded formatting codes. Thank you 🙂

    Use

    Sell      at PositionPrice*1.005 LIMIT
    Exitshort at PositionPrice*0.995 LIMIT
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Exit of market in tradeprice


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Fran55 @fran55 Participant
Summary

This topic contains 11 replies,
has 3 voices, and was last updated by robertogozzi
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/27/2020
Status: Active
Attachments: No files
Logo Logo
Loading...