Bollinger band coding help please

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #80880 quote
    garyoaten
    Participant
    Average

    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?

    Bollu=ExponentialAverage[20](open)+2*std[20](open)
    
    nbpoint=25.4
    
    c1 = (high > Bollu+nbpoint*pointsize)
    
    IF c1 THEN
    SELLSHORT 1 PERPOINT AT MARKET
    
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS nbpoint
    SET TARGET pPROFIT 19

    And this for buys and it doesnt work correctly

    Bolld=ExponentialAverage[20](open)-2*std[20](open)
    
    nbpoint=25.4
    
    c1 = (low < Bolld+nbpoint*pointsize)
    
    IF c1 THEN
    BUY 1 PERPOINT AT MARKET
    
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS nbpoint
    SET TARGET pPROFIT 19

    Any ideas where I am going wrong and how do I put them together to work on 1 code?

    Regards,

     

    Gary

    #80882 quote
    robertogozzi
    Moderator
    Master

    To 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.

    #80886 quote
    robertogozzi
    Moderator
    Master

    Replace line 5 of the second strategy with:

    c1 = (low < Bolld-nbpoint*pointsize)
    #80887 quote
    robertogozzi
    Moderator
    Master

    The two combined:

    Bolld=ExponentialAverage[20](open)-2*std[20](open)
    Bollu=ExponentialAverage[20](open)+2*std[20](open)
    nbpoint=25.4
    c1 = (high > Bollu+nbpoint*pointsize)
    IF c1 AND Not OnMarket THEN
       SELLSHORT 1 PERPOINT AT MARKET
    ENDIF
    c2 = (low < Bolld-nbpoint*pointsize)
    IF c2 AND Not OnMarket THEN
       BUY 1 PERPOINT AT MARKET
    ENDIF
     // Stops and targets
    SET STOP pLOSS nbpoint
    SET TARGET pPROFIT 19
    #80893 quote
    garyoaten
    Participant
    Average

    Thank you Roberto

    #80956 quote
    garyoaten
    Participant
    Average

    Does anybody know if there a way to take half profits at a certain level and then to bring the other half of the stoploss down so the trade becomes a break even trade at worst?

    #80958 quote
    robertogozzi
    Moderator
    Master

    At 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.

    #80959 quote
    Nicolas
    Keymaster
    Master

    This 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:

    defparam cumulateorders=false
    
    // --- settings
    amount = 2 //amount of contract/lot/shares to open for each order
    takeprofit = 30 //takeprofit in points 
    stoploss = 60 //stoploss in points 
    BreakevenAt = 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 settings
    
    upper = BollingerUp[20](close)
    lower = BollingerDown[20](close)
    
    //strategy 
    if high crosses over upper then 
    sellshort amount contract at market 
    endif 
    if low crosses under lower then 
    buy amount contract at market 
    endif 
    set target pprofit takeprofit
    set stop ploss stoploss
    
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    
    startBreakeven =  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 already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    
    //place the new stop orders on market at breakevenLevel
    IF LONGONMARKET AND breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    if countoflongshares=amount then 
    sell Lot2Close contract at market
    endif 
    ENDIF
    // --- end of BUY SIDE ---
    
    // --- SELL SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF SHORTONMARKET AND tradeprice(1)-close>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
    ENDIF
    
    //place the new stop orders on market at breakevenLevel
    IF SHORTONMARKET AND breakevenLevel>0 THEN
    EXITSHORT AT breakevenLevel STOP
    if countofshortshares=amount then
    exitshort Lot2Close contract at market
    endif
    ENDIF
    // --- end of SELL SIDE ---
    robertogozzi and garyoaten thanked this post
    #91739 quote
    wsmurray
    Participant
    New

    This 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

    #91763 quote
    Nicolas
    Keymaster
    Master

    @wsmurray

    Look at the ProRealTime YouTube playlist about trading systems: https://www.youtube.com/playlist?list=PLGw_ZtCHrQ9gkYd50s9qd49uzyqxcK8gE

    #92356 quote
    garyoaten
    Participant
    Average

    I know this should be easy but I am struggling to put it all together. Any help much appreciated?

    
    defparam cumulateorders=false
    
    // --- settings
    ATR = 100 //daily ATR value
    myTarget = 1.25 //target profit coefficient
    Capital = 25000 //capital at starting of the strategy
    Risk = 2 //risk in %
    StartTime = 080000
    EndTime = 163000
    // --- end of settings
    
    //indis
    ema20 = 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 orders
    if high-ema20>ATR*0.2 and low>bollup then
    //money managenemt
    sellentry = low-1*pointsize
    sellstoploss = high+2*pointsize
    StopLoss = sellstoploss-sellentry
    selltarget = StopLoss*myTarget
    equity = Capital + StrategyProfit
    maxrisk = round(equity*(Risk/100))
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    //pending order
    sellshort PositionSize contract at sellentry stop
    set target profit selltarget
    set stop loss StopLoss
    endif
    
    //long orders
    if ema20-low>ATR*0.2 and high<bolldn then
    //money managenemt
    buyentry = high+1*pointsize
    buystoploss = low-2*pointsize
    StopLoss = buyentry-buystoploss
    buytarget = StopLoss*myTarget
    equity = Capital + StrategyProfit
    maxrisk = round(equity*(Risk/100))
    PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
    //pending order
    buy PositionSize contract at buyentry stop
    set target profit buytarget
    set stop loss StopLoss
    endif
    endif
    
    //graph high-ema20>ATR*0.2 and low>bollup
    
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Bollinger band coding help please


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
garyoaten @garyoaten Participant
Summary

This topic contains 10 replies,
has 4 voices, and was last updated by garyoaten
6 years, 12 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/19/2018
Status: Active
Attachments: No files
Logo Logo
Loading...