Stop loss set at 0

Viewing 10 posts - 1 through 10 (of 10 total)
  • #170861

    Hello Everyone

    I am relatively new to PRT, I am trying to create a code that enters a long position whenever a price is hit and I would like to set a stop loss at the entry price.

    So for instance whenever target price x is reached then buy 1 contract and if the price on the next candel drops back to the entry price x then exit long position.

    PRT does not allow me to set the stop loss at 0 usd

    The idea is to exit the long position before it make a loss

    Does anyone any Alice on how to achieve this?

     

    Thank you in advance.

     

    Regards.

     

    #170862

    You will be at a loss the instant you execute a Buy (or SellShort).

    Reason for above is that the broker takes a spread between Buy and Sell Price (also between SellShort and ExitShort).

    Also IG will not let us have a Stop Loss that is nearer the Buy Price than the minimum IG specify … typically 6 for the DJI.  But this can be between 10 and even 100’s at volatile periods.

    Best we can do to keep Order Rejections to a minimum on the DJI is to use SL = 10, or at least 8.

    #170875

    Tutu – My initial response is exactly as GraHal’s. So that. And notice that what this comes down to is setting the StopLoss at +6 which would be about equal to the spread he mentions.
    What I wanted to add :

    In program code you can do what you want. This would mean that you don’t work with a StopLoss command as such, but that you just exit (Sell when you are Long) when you / the program likes it. Is that at your calculated 0 ? then fine, you will lose the spread (amount). Did you calculate/expect** that the spread will be 10 ? then exit at a gain of 10 compared to your entry price and your profit will be 0 (what you wanted).

     

    **): Before you ask, you can’t really know the spread in advance. So you’d need to take a figure of which you’ll know to be on the safe side. However, do notice that the spread can be seen in the IG platform (not sure where – or their mobile app which shows it about everywhere).

    #170881

    Thank you for your prompt reply.

    I used to follow a manual strategy/ trade manually in IG by entering long positions on select stock and commodities ( based on news and some technical/ fundamental analysis) I exit the long position the same day if the price does not move higher as expected by placing a stop loss at the entry price in IG platform after the price increases a little bit higher than the minimum spread requirement (in other words I wait for the price to increase slightly before putting the stop loss at the entry price).

    I am trying to replicate the same strategy in automatic trade in PRT.

     

    Basically I buy long position at x price wait a little bit for the price to increase then assign a stop loss at the entry price (x) so that the loss is 0 (barring any slippage) if the price does not move in the desired direction.

    If the price decreases outright after I entered the long position I set a different stop loss at say 10 pips.

    If the price moves higher I usually set a target profit.

    I am struggling to code this strategy in PRT.

    #170897

    I recommend reading posts such as this one from Nicolas:

    https://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/

    The code that you might think would be logical for setting a stop loss to break even,

    actually deactivates the stop loss (if you didn’t know that already).

    #171381

    Thanks a lot everyone very helpful

    #171495

    Hello Everyone,

    I am still facing an issue with the following code : instead of selling ( exit long position ) the system is placing a stop loss.

    Basically what I am trying to achieve is this : buy at $x , if current price > $x  do nothing , whenever price goes back to $x then sell at $x

    Thank you

     

     

    #171496

    Replace line 14 with:

    #171500

    Thank you Roberto.

    • Since I am using IG I have to consider the spread ( assuming it is 5) then I should take it into account

       

    #171501

    Yes, you can do so.

     

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

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