Bollinger band coding help please
Forums › ProRealTime English forum › ProOrder support › Bollinger band coding help please
- This topic has 10 replies, 4 voices, and was last updated 5 years ago by garyoaten.
Tagged: BB, bollinger bands, BreakEven, partial close
-
-
09/19/2018 at 1:26 PM #80880
Can somebody please program a strategy for me?
I am looking to input a variable level for a buy trade outside the lower exponential Bollinger band (20, 2) (open). So, when the price moves a set amount below the Bollinger band it triggers a buy trade.
When the buy is triggered its puts a stop loss in of the same value. I.e.: I input a variable of 40 and when the price goes below the exponential Bollinger band (20, 2) (open) by 40 pips it triggers a buy trade with a stop loss level 40 pips below that.
And to have a target profit of 75% of the stop loss
Also,
I am looking to input a variable level for a sell trade outside the upper exponential Bollinger band (20, 2) (open) so, when the price moves a set amount above the Bollinger band it triggers a sell trade.
When the sell is triggered its puts a stop loss in of the same value. I.e.: I input a variable of 40 and when the price goes above the exponential Bollinger band (20,2) (open) by 40 pips it triggers a sell trade with a stop loss level 40 pips above that.
And to have a target profit of 75% of the stop loss
I need to be able to adjust the variable amount that the trade triggers by please.
I have this at the moment for sells trades and it seems to work?
1234567891011121314Bollu=ExponentialAverage[20](open)+2*std[20](open)nbpoint=25.4c1 = (high > Bollu+nbpoint*pointsize)IF c1 THENSELLSHORT 1 PERPOINT AT MARKETENDIF// Stops and targetsSET STOP pLOSS nbpointSET TARGET pPROFIT 19And this for buys and it doesnt work correctly
1234567891011121314Bolld=ExponentialAverage[20](open)-2*std[20](open)nbpoint=25.4c1 = (low < Bolld+nbpoint*pointsize)IF c1 THENBUY 1 PERPOINT AT MARKETENDIF// Stops and targetsSET STOP pLOSS nbpointSET TARGET pPROFIT 19Any ideas where I am going wrong and how do I put them together to work on 1 code?
Regards,
Gary
09/19/2018 at 1:28 PM #80882To write code, please use the <> “insert PRT code” button to make code easier to read. Thank you.
Moreover this is not an indicator, but a strategy, so I will move the topic to ProOrder Support.
09/19/2018 at 1:36 PM #80886Replace line 5 of the second strategy with:
1c1 = (low < Bolld-nbpoint*pointsize)09/19/2018 at 1:41 PM #80887The two combined:
1234567891011121314Bolld=ExponentialAverage[20](open)-2*std[20](open)Bollu=ExponentialAverage[20](open)+2*std[20](open)nbpoint=25.4c1 = (high > Bollu+nbpoint*pointsize)IF c1 AND Not OnMarket THENSELLSHORT 1 PERPOINT AT MARKETENDIFc2 = (low < Bolld-nbpoint*pointsize)IF c2 AND Not OnMarket THENBUY 1 PERPOINT AT MARKETENDIF// Stops and targetsSET STOP pLOSS nbpointSET TARGET pPROFIT 1909/19/2018 at 2:00 PM #8089309/20/2018 at 12:49 PM #8095609/20/2018 at 1:41 PM #80958At present ProOrder does not support partial closures (I think it is possible for manual trading, but I never tried). It is said to be supported in a future upgrade of the platform.
09/20/2018 at 1:56 PM #80959This is an example of how to put an order to breakeven when price reached x% of the takeprofit value, and close part of the position at the same time:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061defparam cumulateorders=false// --- settingsamount = 2 //amount of contract/lot/shares to open for each ordertakeprofit = 30 //takeprofit in pointsstoploss = 60 //stoploss in pointsBreakevenAt = 25 //percent achieved of target to move stop to entry (breakeven)PointsToKeep = 1 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)Lot2Close = 1 //amount of contract/lot/shares quantity to close when breakeven occurs// --- end of settingsupper = BollingerUp[20](close)lower = BollingerDown[20](close)//strategyif high crosses over upper thensellshort amount contract at marketendifif low crosses under lower thenbuy amount contract at marketendifset target pprofit takeprofitset stop ploss stoploss//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIFstartBreakeven = takeprofit*(BreakevenAt/100)//how much pips/points in gain to activate the breakeven function?// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF LONGONMARKET AND breakevenLevel>0 THENSELL AT breakevenLevel STOPif countoflongshares=amount thensell Lot2Close contract at marketendifENDIF// --- end of BUY SIDE ---// --- SELL SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND tradeprice(1)-close>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF SHORTONMARKET AND breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPif countofshortshares=amount thenexitshort Lot2Close contract at marketendifENDIF// --- end of SELL SIDE ---2 users thanked author for this post.
02/19/2019 at 11:39 AM #91739This is also a strategy I wish to use but I don’t know how to add the code into PRT.
Can you point me in the right direction to where it explains how to add code please.
Also how do you control the size of the order which will decrease as the stop loss increases or is this obvious once the code is added?
Many thanks
Stuart
02/19/2019 at 5:16 PM #91763Look at the ProRealTime YouTube playlist about trading systems: https://www.youtube.com/playlist?list=PLGw_ZtCHrQ9gkYd50s9qd49uzyqxcK8gE
02/26/2019 at 12:29 PM #92356I know this should be easy but I am struggling to put it all together. Any help much appreciated?
How to code breakeven when at 80% to target?1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253defparam cumulateorders=false// --- settingsATR = 100 //daily ATR valuemyTarget = 1.25 //target profit coefficientCapital = 25000 //capital at starting of the strategyRisk = 2 //risk in %StartTime = 080000EndTime = 163000// --- end of settings//indisema20 = average[20,1]istd = std[20]bollup = ema20+(istd*2)bolldn = ema20-(istd*2)tcondition = (time>=StartTime and time<=EndTime) and (opendayofweek>=1 and opendayofweek<=5)if tcondition then//short ordersif high-ema20>ATR*0.2 and low>bollup then//money managenemtsellentry = low-1*pointsizesellstoploss = high+2*pointsizeStopLoss = sellstoploss-sellentryselltarget = StopLoss*myTargetequity = Capital + StrategyProfitmaxrisk = round(equity*(Risk/100))PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)//pending ordersellshort PositionSize contract at sellentry stopset target profit selltargetset stop loss StopLossendif//long ordersif ema20-low>ATR*0.2 and high<bolldn then//money managenemtbuyentry = high+1*pointsizebuystoploss = low-2*pointsizeStopLoss = buyentry-buystoplossbuytarget = StopLoss*myTargetequity = Capital + StrategyProfitmaxrisk = round(equity*(Risk/100))PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)//pending orderbuy PositionSize contract at buyentry stopset target profit buytargetset stop loss StopLossendifendif//graph high-ema20>ATR*0.2 and low>bollup -
AuthorPosts
Find exclusive trading pro-tools on