Code for partial close with percentage

Forums ProRealTime English forum ProOrder support Code for partial close with percentage

Viewing 15 posts - 46 through 60 (of 62 total)
  • #162196

    No, I was talking about your previous post, to exit 75% of the whole position in three steps, without using different flags and sevarel IF…ENDIF’s:

     

    #162197

    Example on Dax, daily TF:

     

    #162199

    The use of [1] in line 8 is to make sure it never falls below the previous value, so that the percentage of 25%, whatever the number it is calculated on, remains unchanged.

    #162203

    So that will make a 25% partial close at each .5% increase? Doesn’t it need the flag to keep it from repeating each step?

    #162238

    You are right ,

    I added  Increments to my example above, so that the percentage is increased each new closure by PerCentGain steps:

    you can also remove and Not OnMarket  to accumulate positions.

    1 user thanked author for this post.
    #162249

    that looks great, and far more elegant.

    but now I’m thinking it would be better to be able to alter the percent and percentgain independently. so, for example, it might close 0.3 of the position after a 0.6% gain, then 0.5 at 1.6% gain (all percentages to be optimized).

    This seems to work, but it looks very clunky compared to yours:

     

    #162258

    Yes, but if percentages need to be different you have no choice but do as you’ve done.

    Well… you could use arrays… but that’s more complicated!

     

    #162260

    Ok, I’ll stay with what I’ve got then – thanks for confirming.

     

    #165530

    I was wondering if this code is valid, bit confused with use of ONCE function

    What I am trying is – once the price trades above 10% of Positionprice, LTU condition is valid forever – even if price comes under 10% of position price. I am trying to replace ONCE PIP in above code with percentage.

     

    #165538

    Line 3 changes every bar, so LTU isn’t valid forever!

    ONCE is used only in line 1 because PercentLTU never changes.

     

    #165541

    thanks. Then how would it be possible to allow price to trade above the MA and then exit it when it closes below MA. For example, how to have the strategy do nothing before price trades above a Moving average after entry (eg. price is now above Daily 20 MA, but entry was well below that MA.

    Please see the attached image.

    #165544

    Exit:

     

    #165545

    I am not sure I really understood your question, though.

    Can you make an example with the percentage you talked about?

     

    #165547

    Entry is no issue. Problem is that the entry is below the daily MA, as the price hovers around the daily MA in the process of turning bullish for first time after trade entry, the exit condition is triggered. To solve this i wanted price to trade 20% above positionprice. Once the 20% mark is reached, the exit condition always remains true. For example, If entry price is $10, price goes to $15 and then returns to $11 – I want to exit if Dailyclose<MA in below code.

    I was assuming the below code does what I am saying above. I wanted to replace pips with percentage. For below code when price trades above 20 pips from position price, the condition is still true if the price comes back to say 10 pips from position price.

     

     

    #165549

    This is the code you need (not tested):

    I just added a flag to signal when exit is allowed (after reaching +20%) once it retraces below MA.

     

Viewing 15 posts - 46 through 60 (of 62 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login