Any reasons why this code is not working

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #87817 quote
    ramarama
    Participant
    Senior
    pr=2
    mp=40
    mp1=-30
    
    floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
    if floatingprofit>=(mp or mp1) then
    SELL AT close-pr stop
    endif
    
    floatingprofit = (((positionprice-close)*pointvalue)*countofposition)/pipsize //actual trade gains
    if floatingprofit>=(mp or mp1) then
    EXITSHORT AT close+pr stop
    endif

    I want to close all open positions short or long

    if loss is >=30

    or profit >=40

    #87819 quote
    GraHalGraHal
    Participant
    Master

    Just a thought … below won’t work if, for example, you are trying to exit within the bid-ask spread range (spread = 4 or more?).

    I guess you’ve tried higher values for pr?

    pr=2
    
    SELL AT close-pr stop
    
    EXITSHORT AT close+pr stop
    #87824 quote
    VonasiVonasi
    Moderator
    Master

    COUNTOFPOSITION can be positive or negative which will completely mess up your calculations.

    Also as GraHal says CLOSE +/- 2 will very likely be too close for a minimum order distance on most markets.

    #87835 quote
    GraHalGraHal
    Participant
    Master

    Isn’t COUNTOFPOSITION either 0 or greater?

    When can it be negative?

    #87836 quote
    VonasiVonasi
    Moderator
    Master

    Isn’t COUNTOFPOSITION either 0 or greater?

    When can it be negative?

    When you are short.

    [attachment file=87837]

    GraHal thanked this post
    Screenshot_1.png Screenshot_1.png
    #87839 quote
    GraHalGraHal
    Participant
    Master

    @rama try below (AND increase pr > spread) … let us know if it works.

    floatingprofit = (((close-positionprice)*pointvalue)*countoflongshares)/pipsize //actual trade gains
    if floatingprofit>=(mp or mp1) then
    SELL AT close-pr stop
    endif
     
    floatingprofit = (((positionprice-close)*pointvalue)*countofshortshares)/pipsize //actual trade gains
    if floatingprofit>=(mp or mp1) then
    EXITSHORT AT close+pr stop
    endif
    #87859 quote
    ramarama
    Participant
    Senior

    I am testing the new code, I have tried with PR =1 and MP=any value(without mp1 condition) it works well

    I am trying to add loss in the same code that is where it has problem

    #87860 quote
    GraHalGraHal
    Participant
    Master

    try below and let us know

    if (floatingprofit>= mp) or (floatingprofit <= mp1) then
    #87959 quote
    ramarama
    Participant
    Senior

    I am running the program now with ,I will let you know the results

    1
    if (floatingprofit>= mp) or (floatingprofit <= mp1) then
    #87961 quote
    verygrubbyverygrubby
    Participant
    Master

    COUNTOFPOSITION can be positive or negative

    I think the definition in the manual should be tweaked to make that a bit more obvious. All it says at the moment is “Counts the number of open shares or lots.”

    Can a clarification be added (eg “a buy position would should as +1 and a sell position would show as -1”)?

    *when I say manual I mean here: https://www.prorealcode.com/documentation/countofposition/

    GraHal thanked this post
Viewing 10 posts - 1 through 10 (of 10 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

Any reasons why this code is not working


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
rama @rama Participant
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by verygrubbyverygrubby
7 years, 8 months ago.

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