Partial reentry issue

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #168746 quote
    RyuginRyugin
    Participant
    Senior

    Good morning,

    I am trying to code a partial reentry code that, in case that an open position goes near the SL, it should buy/sell a position equal to positionsize/2. I am using cumulateorders = true and Countofposition <=2, and I want the robot to perform the reentry only once. I am not sure what am I doing wrong but the robot does not perform the reentry correctly, could someone give me some light about that topic? I am attaching the code for the reentry:

    ONCE partialreentry = 1
    IF partialreentry and Countofposition<= 2  THEN
    ONCE Partialreentrypos = Positionsize/2              //Position to reenter
    
    IF Not OnMarket THEN
    Flagr = 1
    Flagr2 = 1
    ENDIF
    
    IF LongOnMarket and close <= (PositionPrice - PositionPrice*0.022)  AND Flagr THEN  //0.22 corresponds to the point where I want to set the order, as long as my stoploss is 2,5% away from entry price
    BUY Partialreentrypos Contracts AT Market
    Set stop %loss 0.3
    Set target %profit 2.2
    Flagr = 0
    endif
    
    IF ShortOnMarket and close >= (PositionPrice + PositionPrice*0.018)  AND Flagr2 THEN  // Same here, my stoploss is 2% away from entry price so I would like the robot to sell another position in case that the price is 0,2% away from the SL.
    BUY Partialreentrypos Contracts AT Market
    Set stop %loss 0.2
    Set target %profit 1.8  // The profit corresponds to the BE price of the first position
    Flagr2 = 0
    endif
    endif

    Thank you so much.

    #168749 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Remove ONCE from line 3, because it will be set when the strategy starts only, with an incorrect value (you can GRAPH it).

    Line 10 could also be written like that:

    (PositionPrice*0.978)

    and line 17:

    (PositionPrice*1.018)
    Ryugin thanked this post
    #168752 quote
    RyuginRyugin
    Participant
    Senior

    Thank you for your answer, one more question: In case it opens another position, if I use PositionPrice command which price will the robot take, the one corresponding to the first opened position or the second one?

    #168753 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Do not use QUOTE when unnecessary, as it makes posts more difficult to read and too long!

    Thank you šŸ™‚

    PositionPrice (apart when there’s only one position open), is an average of all entry prices and SL + TP will refer to that price (see pic to see how it is calculated).

    Ryugin thanked this post
    Calcolo-del-Prezzo-Medio-di-una-Posizione-Position-Average-Price-calculation.jpg Calcolo-del-Prezzo-Medio-di-una-Posizione-Position-Average-Price-calculation.jpg
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTimeā„¢ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Partial reentry issue


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Ryugin @ryugin Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/04/2021
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...