ORB 15M error with buy limit MultiTimeFrame
Forums › ProRealTime English forum › ProOrder support › ORB 15M error with buy limit MultiTimeFrame
- This topic has 11 replies, 3 voices, and was last updated 6 years ago by Gianluca.
-
-
09/23/2018 at 6:57 PM #81133
Hi everyone, i have a problem, here is my system that i’m working on, is a Breokout of the first 15m bar, in a 5m timeframe default.
The problem is that the price limit is not respected, as you can see in the photo.Here is the code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177DEFPARAM FLATBEFORE = 080000DEFPARAM PRELOADBARS = 10000DEFPARAM FLATAFTER = 210000DEFPARAM CUMULATEORDERS = FALSEonce maxsetup = 0once minSetup = 0PROFITLONG=20STOPLONG=50PROFITSHORT=50STOPSHORT=50TIMEFRAME (15 MINUTES, UPDATEONCLOSE)ONCE RES = 0//ONCE SUPP= 0if time=091500 thenres=highsupp=lowendifTIMEFRAME (DEFAULT)longok=(close[1]crosses over res) AND (close[1]> res)shortok= (close[1] crosses under supp) and (close[1]<supp)//BUY ORDERSif not onmarket and TIME > 93000 AND TIME < 100000 and longok THENIF maxsetup = 0 THENmaxsetup = resendifBUY 5 CONTRACT AT maxsetup stopendif//SELL ORDERSif not onmarket and TIME > 93000 AND TIME < 100000 and shortok THENif minsetup = 0 thenminsetup = suppendifSELLSHORT 5 CONTRACT AT minsetup stopENDIFIF LONGONMARKET THENSET TARGET PPROFIT PROFITLONGSET STOP PLOSS STOPLONGELSEIF SHORTONMARKET THENSET TARGET PPROFIT PROFITSHORTSET STOP PLOSS STOPSHORTENDIFENDIFif time>212300 thenexitshort at marketsell at marketendifTIMEFRAME (DEFAULT)////TRAILING STOP & BREAKEAVEN//1////////////////////////////////////////////////////////once trailinstop= 1 //1 on - 0 offtrailingstart = 35 //trailing will start @trailinstart points profittrailingstep = 35 //trailing step to move the "stoploss"//////////////once breakeaven = 1 //1 on - 0 offstartBreakeven = 20 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 5 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)//////////////////////////////////partial closeonce PCLOSE=0// --- Partial Close settings ---size = 5mincontracts = 1trigger = 22pointback = 3closepercent = 20if not onmarket thenAllowPartialClose=0endif/////////////////////////////////////////////////////////////2/////////////////////////////////////////////////reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF//3//////////////////////////////test if the price have moved favourably of "startBreakeven" points alreadyif breakeaven>0 thenIF onmarket AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIFendif//************************************************************************//trailing stop functionif trailinstop>0 then//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFendif/////////////////////////////////////////////////////////////////////////////////////////## -- PARTIAL CLOSE PRICE BACK FUNCTION -- ##//## - BUY ORDERSIF PCLOSE>0 THENif longonmarket then//trigger for the partial closure function to startif close-tradeprice>=trigger*pointsize thenAllowPartialClose = 1endifif AllowPartialClose then//compute the maxprice reachedmaxprice = max(maxprice,close)//check to trigger a partial closure or notif maxprice-close>=pointback*pointsize then//close partiallysell max(mincontracts,size*(closepercent/100)) contracts at market//reset the maxprice to the current pricemaxprice = closeendifendifendif//## - SELLSHORT ORDERSif shortonmarket then//trigger for the partial closure function to startif tradeprice-close>=trigger*pointsize thenAllowPartialClose = 1endifif AllowPartialClose then//compute the maxprice reachedminprice = min(minprice,close)//check to trigger a partial closure or notif close-minprice>=pointback*pointsize then//close partiallyexitshort max(mincontracts,size*(closepercent/100)) contracts at market//reset the maxprice to the current priceminprice = closeendifendifendifENDIF09/24/2018 at 12:30 AM #81142Your strategy works fine as you asked it to do!
As from the attached screenshot you can see that at 9:55 it enters a trade because the conditions were true in the setup bar at 9:50. Condition you asked to be met were that the previous candle (at 09:45) had crossed over RES, which it did!
Lines 19-20 can be written
12longok=(close[1]crosses over res)// AND (close[1]> res)shortok= (close[1] crosses under supp)// and (close[1]<supp)since for a crossover/under to be true CLOSE must be above/under RES or SUPP.
The problem is, I guess, that you are referencing the previous candle ([1]) instead of the current one.
1 user thanked author for this post.
09/24/2018 at 12:21 PM #81178Your strategy works fine as you asked it to do!
As from the attached screenshot you can see that at 9:55 it enters a trade because the conditions were true in the setup bar at 9:50. Condition you asked to be met were that the previous candle (at 09:45) had crossed over RES, which it did!
Lines 19-20 can be written
12longok=(close[1]crosses over res)// AND (close[1]> res)shortok= (close[1] crosses under supp)// and (close[1]<supp)since for a crossover/under to be true CLOSE must be above/under RES or SUPP.
The problem is, I guess, that you are referencing the previous candle ([1]) instead of the current one.
yes, it work fine, but i want that when the cross happens the buy/sell order must be at the limit price of the 15m bar of 9.15 that i supposed will be
1BUY 5 CONTRACT AT maxsetup stopbut, price of traded are executed to the max of tha last bar.
the line 19 is ok, because the condition are 2, first the bar (1) have to cross, second the last bar have to close over or under the level, then the system have to put a limit order only at the PRICE of 9.15 (max and minimum)
09/24/2018 at 12:40 PM #8117909/24/2018 at 1:47 PM #81193Sorry if I’m wrong, but since maxsetup=res and you are already above it because “longok” is true, why are you putting a pending STOP order? Buy at a level below the current price is made with a LIMIT order. Same goes for short orders.
09/24/2018 at 2:39 PM #81199Sorry if I’m wrong, but since maxsetup=res and you are already above it because “longok” is true, why are you putting a pending STOP order? Buy at a level below the current price is made with a LIMIT order. Same goes for short orders.
i tried also with LIMIT but price is not respected sometimes
09/24/2018 at 2:46 PM #8120009/24/2018 at 2:57 PM #81203Sorry if I’m wrong, but since maxsetup=res and you are already above it because “longok” is true, why are you putting a pending STOP order? Buy at a level below the current price is made with a LIMIT order. Same goes for short orders.
Hello, i’ve solved the issue, there was something wrong with the variable maxsetup/minsetup
1234567891011121314151617181920IF NOT ONMARKET THENbreakevenLevel=0maxsetup=0minsetup=0ENDIF//BUY ORDERSif not onmarket and TIME > 93000 AND TIME < 100000 and longok THENIF maxsetup = 0 THENmaxsetup = resendifBUY 5 CONTRACT AT maxsetup limitendif//SELL ORDERSif not onmarket and TIME > 93000 AND TIME < 100000 and shortok THENif minsetup = 0 thenminsetup = suppendifSELLSHORT 5 CONTRACT AT minsetup limitENDIF09/24/2018 at 3:03 PM #8120409/24/2018 at 3:17 PM #81209After line 21 insert these lines:
1234if OnMarket THENMinSetup=0MaxSetup=0ENDIFotherwise they’ll never be reset and lines 25 and 33 will never be true again!
Also, despite not affecting the strategy itself, this code is logically WRONG (lines 19-20) as I said before:
12longok=(close[1]crosses over res) AND (close[1]> res)shortok= (close[1] crosses under supp) and (close[1]<supp)1 user thanked author for this post.
09/24/2018 at 3:36 PM #8121609/24/2018 at 4:40 PM #81225GRAPH is your best friend when debugging.
Totally true 🙂
-
AuthorPosts
Find exclusive trading pro-tools on