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
  • image.png

  • Posts

    • ...............to make my question a little clearer. Yesterday i had around £800 to deal.   I bought 2 stocks with the full account value leaving around £2 Available to Deal.  While there was a considerable amount Unsettled Credit and Debit which is not uncommon as i trade many times daily, I bought the stocks with no issue.  Shortly after, my Available to Deal showed as -£495 instead of £2, Funds showed as -£495 and my account value showed as £320. even though my stocks choices were only down less than £5 each.
    • Move over Doge, there’s a new meme coin in town! EPIK, a playful duck-themed token launched on the Solana blockchain on April 6th, 2024, is making waves with its rapid price surge and growing popularity.   Despite its recent arrival, it has garnered significant adoption, with its price experiencing a notable upward trajectory since launch. While its social media presence remains relatively small, the recent listing on the prominent Bitget exchange is a major turning point. This exposure has the potential to propel EPIK towards mainstream adoption, creating a potential wealth opportunity for those who jump on board early.   Is EPIK worth keeping an eye on? With its unique character, impressive launch performance, and strategic exchange listing, it’s future looks bright. Whether you’re a seasoned crypto investor or simply intrigued by the power of meme coins, this is certainly a token worth quacking about.
    • Hi @CharlotteIG can you please advise me on this matter? I have been trading with IG since 2018.   I have NEVER had an issue with Trading several times per day using my full account value.  As an example, if my total account value was £1000,  I have been able without issue to trade in and out within minutes and never had an issue of Unsettled Credit or Debit which has not allowed to me to trade any further.  Nor have I ever seen a Negative Balance in either Funds Available or Available to Deal. Yesterday 17th April, I had available over £800 to Trade (total account value £1072).  I bought 2 stocks using the full account value leaving around £2 Available to Deal.  I then went to the shop.  I soon noticed on my App that I was -£495, and my account value was around £320, even though my PL was only under £150.  (these figures are approx). Yesterday i sold half of one of my position, and I am still -$168 with £350 Unsettled credit. I have never experienced this before.   While I have contacted Helpdesk a simple reply of 'Unsettled Credit' was the answer.  What has changed?  I feel something is really wrong here.     Thanks.  
×
×
  • Create New...
us