SCALPING STRATEGY (VWAP/MACD35)

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #175225 quote
    efahmy
    Participant
    Average
    DEFPARAM CumulateOrders = True // Cumulating positions activated
    // Definition of code parameters
    SL = AverageTrueRange[14](close) * 2.0
    PT = SL * 1.5
    STEPFACTOR1 = 0.5
    STEPFACTOR2 = 0.25
    //VWAP calculation
    //
    NoSunday = 0            //1=skip Sunday's
    IF (BarIndex = 0) OR (OpenDay <> OpenDay[1]) THEN
    SumVolPrice = 0
    SumVol      = 0
    ENDIF
    IF Volume > 0 THEN
    IF (OpenDayOfWeek <> 0) OR (OpenDayOfWeek = 0 AND Not NoSunday) THEN
    SumVolPrice = SumVolPrice + (Volume * close)
    SumVol      = SumVol      + Volume
    VWAP        = SumVolPrice / SumVol
    ENDIF
    ENDIF
    indicator1 = MACDline[5,35,5](close)
    indicator2 = MACDSignal[5,35,5](close)
    timeframe(DEFAULT)
    // Conditions to enter long positions
    IF close > VWAP AND indicator1 CROSSES OVER indicator2 THEN
    BUY 10 CONTRACT AT MARKET
    ENDIF
    IF close < VWAP AND indicator1 CROSSES UNDER indicator2 THEN
    SELLSHORT 10 CONTRACT AT MARKET
    // Stops and targets
    SET STOP pTRAILING SL
    SET TARGET pPROFIT PT
    //====== Trailing Stop mechanism - start =====
    trailingstart = (stepfactor1 * SL )
    trailingstep = (stepfactor2 * SL )
    //resetting variables when no trades are on market
    if not onmarket then
    priceexit = 0
    endif
    
    //case LONG order
    if longonmarket then
    
    //first move (breakeven)
    IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN
    priceexit = tradeprice(1) + trailingstep*pointsize
    ENDIF
    //next moves
    IF priceexit>0 THEN
    P2 = close-priceexit >= trailingstart*pointsize
    IF P2 THEN
    priceexit = priceexit + trailingstep*pointsize
    ENDIF
    ENDIF
    ENDIF
    //case SHORT order
    if shortonmarket then
    //first move (breakeven)
    IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN
    priceexit = tradeprice(1) - trailingstep*pointsize
    ENDIF
    //next moves
    IF priceexit>0 THEN
    P2 = priceexit-close >= trailingstart*pointsize
    IF P2 THEN
    priceexit = priceexit - trailingstep*pointsize
    ENDIF
    ENDIF
    ENDIF
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    ENDIF
    //====== Trailing Stop mechanism - end =====
    

    Could you please, check this code.

    #175227 quote
    robertogozzi
    Moderator
    Master

    ENDIF is missing between lines 29 and 30.

    efahmy thanked this post
    #175228 quote
    efahmy
    Participant
    Average
    DEFPARAM CumulateOrders = True // Cumulating positions activated
    // Definition of code parameters
    SL = AverageTrueRange[14](close) * 2.0
    PT = SL * 1.5
    STEPFACTOR1 = 0.5
    STEPFACTOR2 = 0.25
    //VWAP calculation
    //
    NoSunday = 0            //1=skip Sunday's
    IF (BarIndex = 0) OR (OpenDay <> OpenDay[1]) THEN
    SumVolPrice = 0
    SumVol      = 0
    ENDIF
    IF Volume > 0 THEN
    IF (OpenDayOfWeek <> 0) OR (OpenDayOfWeek = 0 AND Not NoSunday) THEN
    SumVolPrice = SumVolPrice + (Volume * close)
    SumVol      = SumVol      + Volume
    VWAP        = SumVolPrice / SumVol
    ENDIF
    ENDIF
    indicator1 = MACDline[5,35,5](close)
    indicator2 = MACDSignal[5,35,5](close)
    timeframe(DEFAULT)
    // Conditions to enter long positions
    IF close > VWAP AND indicator1 CROSSES OVER indicator2 THEN
    BUY 10 CONTRACT AT MARKET
    ENDIF
    IF close < VWAP AND indicator1 CROSSES UNDER indicator2 THEN
    SELLSHORT 10 CONTRACT AT MARKET
    ENDIF
    // Stops and targets
    SET STOP pTRAILING SL
    SET TARGET pPROFIT PT
    //====== Trailing Stop mechanism - start =====
    trailingstart = (stepfactor1 * SL )
    trailingstep = (stepfactor2 * SL )
    //resetting variables when no trades are on market
    if not onmarket then
    priceexit = 0
    endif
    //case LONG order
    if longonmarket then
    //first move (breakeven)
    IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN
    priceexit = tradeprice(1) + trailingstep*pointsize
    ENDIF
    //next moves
    IF priceexit>0 THEN
    P2 = close-priceexit >= trailingstart*pointsize
    IF P2 THEN
    priceexit = priceexit + trailingstep*pointsize
    ENDIF
    ENDIF
    ENDIF
    //case SHORT order
    if shortonmarket then
    //first move (breakeven)
    IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN
    priceexit = tradeprice(1) - trailingstep*pointsize
    ENDIF
    //next moves
    IF priceexit>0 THEN
    P2 = priceexit-close >= trailingstart*pointsize
    IF P2 THEN
    priceexit = priceexit - trailingstep*pointsize
    ENDIF
    ENDIF
    ENDIF
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    ENDIF
    //====== Trailing Stop mechanism - end =====
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

SCALPING STRATEGY (VWAP/MACD35)


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
efahmy @efahmy Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by efahmy
4 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/13/2021
Status: Active
Attachments: No files
Logo Logo
Loading...