using bollybands as a stop loss

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #206201 quote
    LivJoJadeLivJoJade
    Participant
    Junior
    is it possible to use a different deviation BB as a stop loss instrument. Say I want to enter short above the upper band of a standard BB with a target of crossing the middle line (average) and implimenting a close above a +3 deviation BB for a stop loss. Hope that makes sense.
    #206204 quote
    JSJS
    Participant
    Master

    Hi@LivJoJade

    That’s possible…

    DefParam CumulateOrders=False
    
    n=20 //20 Days
    
    xAvg=Average[n](Close)
    xStd=Std[n](Close)
    
    xBB2Up=xAvg+2*xStd
    xBB3Up=xAvg+3*xStd
    xBB2Down=xAvg-2*xStd
    xBB3Down=xAvg-3*xStd
    
    If Close Crosses Over xBB2Up then
    SellShort 1 contract at Market
    Set Target pProfit (xBB2Up-xAvg)
    Set Stop pLoss(xBB3Up-xBB2Up)
    EndIf
    
    If Close Crosses Under xBB2Down then
    Buy 1 contract at Market
    Set Target pProfit (xBB2Down-xAvg)
    Set Stop pLoss(xBB3Down-xBB2Down)
    EndIf

    #206207 quote
    JSJS
    Participant
    Master

    Hi@Livjojade

    To avoid negative values, you must take the absolute values for the Stop Loss and the Take Profit…  (or immediately fill in the right values… 😉 )

    DefParam CumulateOrders=False
    
    //n=20 //20 Days
    
    xAvg=Average[n](Close)
    xStd=Std[n](Close)
    
    xBB2Up=xAvg+2*xStd
    xBB3Up=xAvg+3*xStd
    xBB2Down=xAvg-2*xStd
    xBB3Down=xAvg-3*xStd
    
    If Close Crosses Over xBB2Up then
    SellShort 1 contract at Market
    Set Target pProfit abs(xBB2Up-xAvg)
    Set Stop pLoss abs(xBB3Up-xBB2Up)
    EndIf
    
    If Close Crosses Under xBB2Down then
    Buy 1 contract at Market
    Set Target pProfit abs(xBB2Down-xAvg)
    Set Stop pLoss abs(xBB3Down-xBB2Down)
    EndIf
    

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

using bollybands as a stop loss


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
LivJoJade @livjojade Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by JSJS
3 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/22/2022
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...