Jump to content
  • 0

PRT Code - Breakout from first candle


Bopperz

Question

Hi all,

Pretty new to PRT, I am looking at an example they give in the docs. From my understanding and some squinting at the charts, this code dosent get the high and low from the opening bars. It actually takes the high and low from the preceding two bars. Am I correct? And if so, how do I get the opening bars?

Suspect code/description in bold.

 

This is a basic breakout intraday trading system that takes only long positions. The initial range is determined
by the highest and lowest points of the first 2 candlesticks of the day
. A support is defined at the lowest point
and a resistance at the highest point.

DEFPARAM CumulateOrders = False
MM = Average[10](close)
MyTarget = 1
EndTime = 170000
IF INTRADAYBARINDEX = 2 THEN
MyResistance = highest[2](high)
MySupport = lowest[2](low)

ENDIF
REM Enter Long:
IF MM > MM[1] AND close CROSSES OVER MyResistance THEN
BUY 1 SHARES AT MARKET
ENDIF
REM Exit Long:
IF time > EndTime THEN
SELL AT MARKET
ENDIF
SELL AT MySupport STOP
SET TARGET %Profit MyTarget

Link to comment

7 answers to this question

Recommended Posts

  • 0

//-------------------------------------------------------------------------
// Main code : AAAAA EU BO 5 min 24 nov skp
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = false
DEFPARAM FLATBefore     = 150000                       
DEFPARAM FLATAfter      = 210000                        
DEFPARAM PreLoadBars    = 2000

ONCE nLots              = 1
ONCE MaxPrice           = 999999
ONCE MinPrice           = 0
ONCE FirstHour          = 150000 // Start

IF time = FirstHour THEN
MaxPrice = highest[12](high)                        // Highest 12 bars 5 min = 60 min
MinPrice = lowest[12](low)                            // LoWest  
ENDIF
//************************************************************************
//     trailing stop function
trailingstart = 13  //5    trailing will start @trailinstart points profit
trailingstep  = 2  //5    trailing step to move the "stoploss"
//
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
//                           LONG
a1 = close > MaxPrice
IF a1 THEN
Buy nLots CONTRACT AT MARKET
MaxPrice = 999999
MinPrice = 0
ENDIF

//                           SHORT
b1 = close < MinPrice
IF b1 THEN
Sellshort nLots CONTRACT AT MARKET
MaxPrice = 999999
MinPrice = 0
ENDIF
SET STOP PLOSS 20

Link to comment
  • 0

//-------------------------------------------------------------------------
// Main code : BO DOW3 3 min
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = false
DEFPARAM FLATBefore     = 090000                        //09:00
DEFPARAM FLATAfter      = 210000                         //21:00
DEFPARAM PreLoadBars    = 2000

ONCE nLots              = 1
ONCE MaxPrice           = 999999
ONCE MinPrice           = 0
ONCE FirstHour          = 090000

IF time = FirstHour THEN
MaxPrice = highest[12](high)                          
MinPrice = lowest[12](low)                            
ENDIF
//************************************************************************
//     trailing stop function
trailingstart = 9    //5    trailing will start @trailinstart points profit
trailingstep  = 11   //5    trailing step to move the "stoploss"
//
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
//                           LONG
a1 = close > MaxPrice
IF a1 THEN
Buy nLots CONTRACT AT MARKET
MaxPrice = 999999
MinPrice = 0
ENDIF

//                           SHORT
b1 = close < MinPrice
IF b1 THEN
Sellshort nLots CONTRACT AT MARKET
MaxPrice = 999999
MinPrice = 0
ENDIF
SET STOP PLOSS 40
SET TARGET PPROFIT 93
 

Link to comment
  • 0

Thanks @kodiak!

I will take a look at your code. It looks like a large part of the code is creating/updating stop loss? They have a built in function for that now, so ill probably use that.

I think there is a problem with their example though. They are identifying the opening candles using the IF INTRADAYBARINDEX = 2 THEN, this triggers on the third candle. But it seem to ignore the very first candle and take the high/low of 2nd and 3rd candle. I changed it to INTRADAYBARINDEX = 1, and it correctly uses the 1st and 2nd candle.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Posts

    • Sainsburys full year earnings and Unilever’s first quarter trading update both say the same thing, UK consumers are in for higher prices. The war in Ukraine, supply chain issues and the effects of ongoing Covid all to blame.      
    • US Dollar (DXY) Daily Price and Analysis US Q1 GDP may stall the greenback’s advance. A 20-year high nears for the US dollar. The multi-month US dollar rally continues with the greenback printing a fresh high today ahead of the first look at US Q1 GDP at 12.30 GMT. The US dollar basket (DXY) has been boosted by renewed weakness in the Euro and the Japanese Yen, as investors move from lower-yielding to higher-yielding currencies, while safe-haven flows continue to benefit the greenback. The US growth release later in the session is expected to show a sharp slowdown from the robust Q4 figure of 6.9%. The markets are currently pricing in growth of just 1% for the first three months of this year, with the slowdown mainly due to a reduction in inventory accrual over the quarter. This release is unlikely to move the greenback, unless there is a large miss or beat, as the Fed believe that 2022 US growth will be robust enough to let them tighten monetary policy sharply without damaging the economy. The latest US Core PCE data – the Fed’s preferred inflation reading – is released on Friday and this may have more effect on the US dollar than today’s GDP data. For all market moving economic data and events, see the DailyFX Calendar. The ongoing US dollar rally has been aided by weakness across a range of G7 currencies including the Euro, the Japanese Yen, and the British Pound. The Euro continues to battle with lowly growth expectations, exacerbated by energy concerns, the British Pound is mired by weak economic data, while the Japanese Yen is in freefall as the BoJ continues with its ultra-loose monetary policy.   The US dollar continues to press higher and looks set to break above 103.96, the March 2020 high. Above here the US dollar would be back at levels last seen nearly two decades ago. The March resistance will likely hold in the short-term, especially with month-end portfolio rebalancing at the end of the week, but US dollar strength is set to continue in the months ahead. USDOLLAR (DXY) WEEKLY PRICE CHART – APRIL 28, 2022 {{THE_FUNDAMENTALS_OF_BREAKOUT_TRADING}} What is your view on the US Dollar – bullish or bearish?   Apr 28, 2022 | DailyFX Nick Cawley, Strategist
    • While Tesla has nothing directly to do with Elon Musk buying Twitter - TSLA stock closed down 12% on news that Musk may have to sell stock and use other holdings to stand against the loan to finalise the purchase of the social media giant.        
×
×
  • Create New...