Code adjustment to avoid 3 trades per day on Breakout Code
Forums › ProRealTime English forum › ProOrder support › Code adjustment to avoid 3 trades per day on Breakout Code
- This topic has 9 replies, 3 voices, and was last updated 8 years ago by Cosmic1.
-
-
10/12/2016 at 7:53 AM #14747
Morning, So the breakout code is working well on 3 markets and over the last 5 weeks everything is in profit so good news there. One issue is that if a trade is opened and closed within the same bar then 3 trades are possible, this is not ideal as it can skew the results and cause unexpected drawdown like yesterday on the DAX with three small losers. I know why it does this but unsure how to fix it. This fix if there is a possible one will also help another strat I’m working on.
Cheers
10/12/2016 at 9:31 AM #1475110/12/2016 at 9:34 AM #1475210/12/2016 at 7:34 PM #1479110/13/2016 at 7:45 AM #14807Could you please remember us why there is this behaviour of the 3 trades possible here? I know we have together already discussed about it, but I don’t remember sorry 🙂
The code I were thinking of is the same as in this french topic: http://www.prorealcode.com/topic/cloture-systematique-a-la-fin-de-bougie-suivant-le-signal/
10/13/2016 at 7:18 PM #1486412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697//-------------------------------------------------------------------------// Main code : Breakout ProOrder EN DAX//-------------------------------------------------------------------------// We do not store datas until the system starts.// If it is the first day that the system is launched and if it is afternoon,// it will be waiting until the next day for defining sell and buy orders//All times are UK Time ZoneDEFPARAM PreLoadBars = 0// Position is closed at 20h00 PMDEFPARAM FlatAfter = 200000// No new position will be initiated after the 16h00 PM candlestickLimitHour = 161500// Market scan begin with the 15 minute candlestick that closed at 8h15 AMStartHour = 081500// The 24th and 31th days of December will not be traded because market close before 7h45 PMIF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) THENTradingDay = 0ELSETradingDay = 1ENDIF// Variables that would be adapted to your preferencesif time = 074500 then//PositionSize = max(2,2+ROUND((strategyprofit-1000)/1000)) //gain re-invest trade volumePositionSize = 1 //constant trade volume over the timeendifMaxAmplitude = 170 //170 //140 //160MinAmplitude = 22 //24 //15OrderDistance = 9 //9 //7 //10PourcentageMin = 19 //19 //30 //32// Variable initilization once at system startONCE StartTradingDay = -1// Variables that can change in intraday are initiliazed// at first bar on each new dayIF (Time <= StartHour AND StartTradingDay <> 0) OR IntradayBarIndex = 0 THENBuyTreshold = 0SellTreshold = 0BuyPosition = 0SellPosition = 0StartTradingDay = 0ELSIF Time >= StartHour AND StartTradingDay = 0 AND TradingDay = 1 THEN// We store the first trading day bar indexDayStartIndex = IntradayBarIndexStartTradingDay = 1ELSIF StartTradingDay = 1 AND Time <= LimitHour THEN// For each trading day, we define each 15 minutes// the higher and lower price value of the instrument since StartHour// until the buy and sell tresholds are not definedIF BuyTreshold = 0 OR SellTreshold = 0 THENHighLevel = Highest[IntradayBarIndex - DayStartIndex + 1](High)LowLevel = Lowest [IntradayBarIndex - DayStartIndex + 1](Low)// Spread calculation between the higher and the// lower value of the instrument since StartHourDaySpread = HighLevel - LowLevel// Minimal spread calculation allowed to consider a significant price breakout// of the higher and lower valueMinSpread = DaySpread * PourcentageMin / 100// Buy and sell tresholds for the actual if conditions are metIF DaySpread <= MaxAmplitude THENIF SellTreshold = 0 AND (Close - LowLevel) >= MinSpread THENSellTreshold = LowLevel + OrderDistanceENDIFIF BuyTreshold = 0 AND (HighLevel - Close) >= MinSpread THENBuyTreshold = HighLevel - OrderDistanceENDIFENDIFENDIF// Creation of the buy and sell orders for the day// if the conditions are metIF SellTreshold > 0 AND BuyTreshold > 0 AND (BuyTreshold - SellTreshold) >= MinAmplitude THENIF BuyPosition = 0 THENIF LongOnMarket THENBuyPosition = 1ELSEBUY PositionSize CONTRACT AT BuyTreshold STOPENDIFENDIFIF SellPosition = 0 THENIF ShortOnMarket THENSellPosition = 1ELSESELLSHORT PositionSize CONTRACT AT SellTreshold STOPENDIFENDIFENDIFENDIF// Conditions definitions to exit market when a buy or sell order is already launchedIF LongOnMarket AND ((Time <= LimitHour AND SellPosition = 1) OR Time > LimitHour) THENSELL AT SellTreshold STOPELSIF ShortOnMarket AND ((Time <= LimitHour AND BuyPosition = 1) OR Time > LimitHour) THENEXITSHORT AT BuyTreshold STOPENDIF// Maximal risk definition of loss per position// in case of bad evolution of the instrument priceSET STOP PLOSS MaxAmplitude//set target pprofit 190//19010/13/2016 at 7:32 PM #14865It is your original CAC Breakout code modified to work on DAX. Are you saying that the thread you linked to holds the key to sorting this issue? If so I will spend some time trying to implement it.
The reason this happens is because the strategy can sometimes open and close a trade within the same bar and so is only recorded as one trade. This creates an option for a third.
10/15/2016 at 9:48 AM #14931Yes it is a common problem that will be solved with multitimeframe support hopefully.
At the beginning of the code, you can add something like this, that will test is a trade is currently on market:
123if longonmarket thencurrentbar = barindexendifThen each time you launch a trade add this just below the trade launch instruction:
12BUY 1 SHARE AT MARKETsavedbar=barindex1and now you could test if the “currentbar” is not the same as the “savedbar” or at least 1 bar old. I think the tradeindex function can’t help because it needs at least 1 bar to compute.
Sometimes we have to remember that the code are read from beginning to the end, so it is obviously a good idea to refresh variables state at the beginning of the code.
This should work .. or not, just a Saturday morning idea, between coffee and children’s cartoons on TV 🙂
1 user thanked author for this post.
10/16/2016 at 6:57 PM #14982 -
AuthorPosts
Find exclusive trading pro-tools on