Code a DOUBLE STOP at opening price candle and turn it into a TRAILING STOP ???

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #249226 quote
    Danield
    Participant
    New

    Hello everyone, I’m new here and this is my first post 😊
    I’m just starting to learn programming and I want to create an automated trading robot in PRT (ProRealTime), which I’ve been using manually in demo mode for the past 2 months.

    My idea is to create a code that will execute at a specific time (my research led me to use TIME=153000, on the 1-minute timeframe).

    At exactly 15:30:00, I want to place two STOP orders, each 10 points away from the opening price of the 15:30 candle (or from the close of the 15:29 candle).

    Let’s imagine an opening price at 15:30:00 of $100. I want to place the first STOP at $90 (in case the price goes up) and the second STOP at $110 (in case the price goes down).
    The first of the two stops that gets triggered by the price will become a market order, and the other will remain a STOP order.

    This setup allows taking a position regardless of which direction the price moves at the candle’s opening.

    I’ve already done this manually, but I don’t know how to code it.
    Does anyone have an idea to help me? A code example would be great too.

    (Super) Bonus question: Once one of the stops has been triggered and becomes a market order, can the other one be transformed into a trailing stop instead of remaining a fixed stop?

    Thanks so much in advance!

    #249237 quote
    Iván González
    Moderator
    Master

    Hi! here you have:

    DEFPARAM CumulateOrders = False
    dist=10
    once inTrade = 0
    
    IF opentime = 152900 THEN
       basePrice = close
       stopBuyPrice = basePrice + dist * pointsize
       stopSellPrice = basePrice - dist * pointsize
       inTrade = 1
    ENDIF
    
    IF inTrade = 1 THEN
       IF NOT longonmarket AND NOT shortonmarket THEN
          BUY AT stopBuyPrice STOP
          SELLSHORT AT stopSellPrice STOP
       ENDIF
    ENDIF
    if onmarket then
       inTrade = 0
       SET STOP ploss dist
    endif
    //---Graph
    graphonprice basePrice coloured("blue")
    graphonprice stopSellPrice coloured("red")
    graphonprice stopBuyPrice coloured("green")
    
    robertogozzi thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Code a DOUBLE STOP at opening price candle and turn it into a TRAILING STOP ???


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Danield @danield Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
6 months, 2 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/31/2025
Status: Active
Attachments: No files
Logo Logo
Loading...