New position with similar conditions only when the first position take breakeven

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

    I have a position, i want you to another position when the same conditions are met, but only if the first position has breakeven.

    #141712 quote
    robertogozzi
    Moderator
    Master

    Only if the first one closed at breakeven (no profit at all)?

    #141716 quote
    kaq52
    Participant
    Average

    Fran55, could you please elaborate bit more?

    Are you saying something like:

    • Open first position
    • When it has reached a profit of x points, move stoploss of first position to breakeven and open second position with similar conditions as position 1.

    If this indeed is the case, there is a very nice grid strategy here which can be customised to your needs:  https://www.prorealcode.com/topic/grid-orders-with-one-combined-stop-loss-and-limit-can-it-be-done/

    If something else, please explain.

    #141720 quote
    Fran55
    Participant
    Veteran

    The page no found kaq52.

     

    Please…Open other position with conditions, if the first position is on market and breakeven.

    #141721 quote
    kaq52
    Participant
    Average
    defparam CUMULATEORDERS = TRUE
    Once OpenPositions=0
    Ordersize = 1 //amend to reflect how many postions you want each time
    
    // Conditions to enter long positions
    IF  Not LongOnmarket and YourConditions THEN //specify your buy conditions
    BUY Ordersize CONTRACTS AT MARKET
    SL = YourStopLoss //specify your original stop loss
    OpenPositions = Ordersize
    ENDIF
    
    
    
    // Conditions to exit long positions
    If  (OpenPositions=OrderSize) AND YourConditions THEN //Opening Second position and updating stoploss
    Once SL = positionPrice //this moves your stoploss to position-1 buyprice
    //remove keyword "Once" if yuo want both positions to be at breakeven. That is, stoploss will be between buying prices of position1 and Position2, 
    
    BUY Ordersize CONTRACTS AT MARKET
    ENDIF
    
    <Specify  Conditions to exit long positions>
    
    set stop ploss SL
    

    Similarly amend for short conditions.

     

    I know there is an issue on copied links to work, so you couldn’t access above. Hopefully someone can advise how to access above link.

    #141722 quote
    robertogozzi
    Moderator
    Master

    The outcome of the last closed position is returned by PositionPerf(1), so you just need to check it was 0:

    If MyConditions and Not OnMarket and PositionPerf(1) = 0 then
     .
     . Buy/Sellshort.......
     .
    Endif
    #141749 quote
    Fran55
    Participant
    Veteran

    No valid… Thanks!

    See…

    The second position only open if the first position is on market and gain 0.6% or + and conditions.

    #141751 quote
    robertogozzi
    Moderator
    Master

    This to accumulate a position after a 0.6% increase:

    If MyConditions AND ((PositionPerf * 100) >= 0.6) then
     .
     . Buy/Sellshort.......
     .
    Endif
    #141759 quote
    Fran55
    Participant
    Veteran

    Ok.

    And open new position after 0.6% increase at close bar 5 minutes?

    Please.

    #141760 quote
    robertogozzi
    Moderator
    Master

    Yes, if you use a 5-minute TF it will add a position when that bar closes.

    #141765 quote
    Fran55
    Participant
    Veteran

    And two or three máximum accumulated positions???

    Please!

    #141781 quote
    robertogozzi
    Moderator
    Master

    There you go:

    If MyConditions AND (abs(Countofposition) < 3) Then
     .
     . Buy/Sellshort.......
     .
    Endif
    #167796 quote
    Jigsaw20000
    Participant
    Average

    Hello, I tried the following code without success, the second position does not execute:

    If Not Longonmarket and CtimeAchat1 AND CaMom1bis AND CaMom2bis AND CaLoc4bis AND CaLoc5bis AND CaFig6bis AND CaFig7bis and CaWillA2 THEN
    BUY n SHARES AT MARKET
    set target %profit takeprofitbis
    set stop loss Stoplossbis ptrailing 46
    ENDIF
    If longonmarket and ((positionperf*100)>=x1) AND (abs(Countofposition)<3) AND CtimeAchat1 AND CaMom1 AND CaMom2 AND CaLoc4 AND CaLoc5 AND CaFig6 and CaWillA1 THEN
    Buy n shares at market
    set target %profit takeprofit
    set stop loss Stoploss ptrailing 50
    endif

    Bearing, independently, the positions run normally.

    Could you help me ?

    #167802 quote
    robertogozzi
    Moderator
    Master

    @Jigsaw20000

    Try to abide by the basic rules, as highlighted in yellow below:

    • Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
    • Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.

    Thank you 🙂

    #167804 quote
    robertogozzi
    Moderator
    Master

    Try GRAPHing as many variables as possible to spot any issue:

    Graph N
    Graph ((positionperf*100)>=x1)
    Graph (abs(Countofposition)<3)
    Graph .....
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

New position with similar conditions only when the first position take breakeven


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Fran55 @fran55 Participant
Summary

This topic contains 14 replies,
has 4 voices, and was last updated by robertogozzi
4 years, 10 months ago.

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