New to programming, need to know what’s wrong with my code

Forums ProRealTime English forum ProOrder support New to programming, need to know what’s wrong with my code

Viewing 7 posts - 1 through 7 (of 7 total)
  • #245769

    Hi! I’m new to trading and new to programming as well. I’m trying to create a simple stop losses system depending on how many point the stock moves.

    The issue is that the stop losses don’t trigger as I wish. Can someone see what’s wrong with the code?

    I wish:

    Initial stop loss at 100

    When the stock moves 100+, the stop loss moves to 50.

    A fuurther movement of 50 point, the stop loss moves another 50 point

    After 200 points of market move, the trailingstop of 100 point kicks in.

     

     

    #245770

    Hi.

    I see you’re using incorrect expressions when defining the stop loss. If you want to set the stop at X points, you should use the expression SET STOP pLOSS X.

    Here are some examples:

    https://www.prorealcode.com/documentation/ploss-2/

     

    2 users thanked author for this post.
    #245786

    Thanks! Is that all that is needed to get the code working? Appreciate all help!

    #245790

    In principle, yes. Perhaps I would change the last expression to this one:

    Or you could place this at the beginning of the code:

    1 user thanked author for this post.
    #245791

    Hello,

    as you mention you’re new to this, it’s probably worth mentionning what might seem obvious for those familiar with the platform:

    1) the instructions “time” and “opentime” are respectively the closing time and the opening time of a candle

    2) a proorder code is only read at candle close, and if orders are sent they are executed immediatly after, namely at the open of the following candle

     

    These 2 points together in mind, when you say in the code:

    if you run your code say on a one hour  timeframe rather than a smaller timeframe, you wouldn’t have any candle closing at 8:30 or 15:30 so the orders would never be sent.
    .
    Similarly, when you say :

    if you are on a 5mn timeframe, or even just a 2mn timeframe, there is no candle closing at 21:57, so you would need to run such code on a 1mn timeframe or x seconds providing it divides 1mn (30s,15s,…)

    .
    Maybe you were already doing that, but I don’t see it in your post, so that’s why I specify it, just in case… because, if you’re running on a timeframe not compatible with those times and you see no orders sent, you might be looking for an error in the code when in fact, it’s an error in timeframe choice (or you might choose to keep a certain timeframe but then need to amend time values in the code to make them compatible with chosen timeframe).
    3 users thanked author for this post.
    #245848

    I want to delve deeper into setting a TARGET and a STOP LOSS.

    SET STOP LOSS and SET TARGET PROFIT both require a value, be it a constant or a variable or an expression, expressed as a price, thus that value must be converted from a number into a price by multiplying it by PIPSIZE (or its equivalent POINTSIZE). Should you use a difference between prices, such as the expression highest[10](high) – lowest[10](low), then NO conversion should be performed as they ARE prices, so this is correct:

    pSTOP and pPROFIT both require a value that is the number of PIPS, be it a constant or a variable or an expression,  thus that value must be a number which doesn’t require any conversion. A conversion would be needed if you would like to use a value expressed as a price, such as the expression highest[10](high) – lowest[10](low). These statements are both correct:

    any price, be it a constant or a variable or a price expression, must be converted into Pips by DIVIDING that price by PIPSIZE (or its equivalent POINTSIZE).

    What has been said about LOSS/TARGET and pLOSS/pTARGET is also true for TRAILING/pTRAILING.

    A different case are SET STOP price and SET TARGET price, as they only require a price, so the statements:

    are both correct and only the latter one requires the numeric constant to be converted into a price, while TRADEPRICE is a price by itself.

     

     

    1 user thanked author for this post.
    #245851

    My bad, the line:

    What has been said about LOSS/TARGET and pLOSS/pTARGET is also true for TRAILING/pTRAILING

    must be replaced by:

    What has been said about LOSS/PROFIT and pLOSS/pPROFIT is also true for TRAILING/pTRAILING.

     

Viewing 7 posts - 1 through 7 (of 7 total)

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