Exemplo n.º 1
0
def trailOnProfit5(trade, bar, initStop, stop):
    global recentExtremePrice, extremePrice, trailAtr

    TRAIL_ATR_MULTIPLIER = 2
    MIN_X = 1.5
    TIME_CUT_OFF = (14, 54)  # Trail only after cut off time

    extremePrice = mechTM.getExtremePrice(trade, bar, extremePrice)
    isTime = isTimeTriggered(bar, TIME_CUT_OFF)

    if (mechTM.currentTradeStatus(trade, initStop, bar) >= MIN_X):
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER
        stop = mechTM.getTrailPrice(trade, bar, initStop, extremePrice,
                                    distance)
    elif (isTime):
        if (recentExtremePrice is None):
            recentExtremePrice = bar.H if trade.isLong else bar.L  # Use first bar after trigger as initial extreme
        else:
            recentExtremePrice = mechTM.getExtremePrice(
                trade, bar, recentExtremePrice)

        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER
        stop = mechTM.getTrailPrice(trade, bar, initStop, recentExtremePrice,
                                    distance)
    else:
        newStop = donchianLow[bar.Index] if trade.isLong else donchianHigh[
            bar.Index]
        if isStopValid(trade, initStop, newStop):
            stop = newStop

    return stop
Exemplo n.º 2
0
def trailOnProfit5( trade, bar, initStop, stop ):
    global recentExtremePrice, extremePrice, trailAtr
        
    TRAIL_ATR_MULTIPLIER = 2
    MIN_X                = 1.5
    TIME_CUT_OFF         = ( 14,54 )             # Trail only after cut off time

    extremePrice         = mechTM.getExtremePrice( trade, bar, extremePrice )
    isTime               = isTimeTriggered( bar, TIME_CUT_OFF )
    
    if(  mechTM.currentTradeStatus( trade, initStop, bar ) >= MIN_X  ): 
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER        
        stop     = mechTM.getTrailPrice( trade, bar, initStop, extremePrice, distance  )
    elif( isTime ):
        if(  recentExtremePrice is None ):
            recentExtremePrice = bar.H if trade.isLong else bar.L                            # Use first bar after trigger as initial extreme
        else :
            recentExtremePrice = mechTM.getExtremePrice( trade, bar, recentExtremePrice )

        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER
        stop     = mechTM.getTrailPrice( trade, bar, initStop, recentExtremePrice, distance  )
    else:
        newStop = donchianLow[ bar.Index ]  if trade.isLong  else donchianHigh[ bar.Index ]        
        if isStopValid( trade, initStop, newStop ):
            stop = newStop

    return stop
Exemplo n.º 3
0
def timeStop( trade, bar, initStop ):
    global barCount
    
    barCount += 1
    
    if( barCount >=20 and mechTM.currentTradeStatus( trade, initStop, bar ) < 0.1 ):
        return mechTM.markClosedAtCurrentPrice( trade, bar )
    else:
        return False
Exemplo n.º 4
0
def timeStop(trade, bar, initStop):
    global barCount

    barCount += 1

    if (barCount >= 20
            and mechTM.currentTradeStatus(trade, initStop, bar) < 0.1):
        return mechTM.markClosedAtCurrentPrice(trade, bar)
    else:
        return False
Exemplo n.º 5
0
def donchianTrailTimeStop( trade, bar, initStop, stop ):
    global barCount
    
    barCount += 1
    
    TIME_LIMIT = 20
    MIN_X      = 0

    if( barCount >= TIME_LIMIT   and   mechTM.currentTradeStatus( trade, initStop, bar ) < MIN_X   ):
        stop = donchianTrail( trade, bar, initStop, stop )
    
    return stop
Exemplo n.º 6
0
def trailOnProfit( trade, bar, initStop, stop ):
    global extremePrice, trailAtr
        
    TRAIL_ATR_MULTIPLIER = 2
    MIN_X                = 1.5
    extremePrice         = mechTM.getExtremePrice( trade, bar, extremePrice )
    
    if(  mechTM.currentTradeStatus( trade, initStop, bar ) >= MIN_X  ):        
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER        
        stop     =  mechTM.getTrailPrice( trade, bar, initStop, extremePrice, distance  ) 
    
    return stop
Exemplo n.º 7
0
def trailOnProfit(trade, bar, initStop, stop):
    global extremePrice, trailAtr

    TRAIL_ATR_MULTIPLIER = 2
    MIN_X = 1.5
    extremePrice = mechTM.getExtremePrice(trade, bar, extremePrice)

    if (mechTM.currentTradeStatus(trade, initStop, bar) >= MIN_X):
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER
        stop = mechTM.getTrailPrice(trade, bar, initStop, extremePrice,
                                    distance)

    return stop
Exemplo n.º 8
0
def donchianTrailTimeStop(trade, bar, initStop, stop):
    global barCount

    barCount += 1

    TIME_LIMIT = 20
    MIN_X = 0

    if (barCount >= TIME_LIMIT
            and mechTM.currentTradeStatus(trade, initStop, bar) < MIN_X):
        stop = donchianTrail(trade, bar, initStop, stop)

    return stop
Exemplo n.º 9
0
def trailOnProfit3( trade, bar, initStop, stop ):
    global extremePrice, trailAtr
        
    TRAIL_ATR_MULTIPLIER = 2
    MIN_X                = 1.5
    TIME_CUT_OFF         = ( 14,54 )             # Trail only after cut off time

    extremePrice         = mechTM.getExtremePrice( trade, bar, extremePrice )
    isTime               = isTimeTriggered( bar, TIME_CUT_OFF )
    
    #isTime = False
    
    if(  isTime or mechTM.currentTradeStatus( trade, initStop, bar ) >= MIN_X  ):        
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER        
        stop     = mechTM.getTrailPrice( trade, bar, initStop, extremePrice, distance  ) 
    
    return stop
Exemplo n.º 10
0
def trailOnTimeStop( trade, bar, initStop, stop ):
    global barCount, extremePrice, trailAtr
    
    TRAIL_ATR_MULTIPLIER = 2
    MIN_X                = 0
    BAR_TIME_LIMIT       = 20

    barCount  += 1    
    
    extremePrice  = mechTM.getExtremePrice( trade, bar, extremePrice ) 
    
    if( barCount >= BAR_TIME_LIMIT and mechTM.currentTradeStatus( trade, initStop, bar ) < MIN_X  ):
        # TODO try by ignoring BO Bar, ie once time limit is up, take last bar as extreme
        #extremePrice  = mechTM.getExtremePrice( trade, bar, extremePrice )      #  Not updated until Timestop => Trails behind recent extreme (or BO Bar whichever is further) after timestop is active
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER
        stop     = mechTM.getTrailPrice( trade, bar, initStop, extremePrice, distance  ) 
    
    return stop
Exemplo n.º 11
0
def trailOnProfit3(trade, bar, initStop, stop):
    global extremePrice, trailAtr

    TRAIL_ATR_MULTIPLIER = 2
    MIN_X = 1.5
    TIME_CUT_OFF = (14, 54)  # Trail only after cut off time

    extremePrice = mechTM.getExtremePrice(trade, bar, extremePrice)
    isTime = isTimeTriggered(bar, TIME_CUT_OFF)

    #isTime = False

    if (isTime or mechTM.currentTradeStatus(trade, initStop, bar) >= MIN_X):
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER
        stop = mechTM.getTrailPrice(trade, bar, initStop, extremePrice,
                                    distance)

    return stop
Exemplo n.º 12
0
def trailOnTimeStop(trade, bar, initStop, stop):
    global barCount, extremePrice, trailAtr

    TRAIL_ATR_MULTIPLIER = 2
    MIN_X = 0
    BAR_TIME_LIMIT = 20

    barCount += 1

    extremePrice = mechTM.getExtremePrice(trade, bar, extremePrice)

    if (barCount >= BAR_TIME_LIMIT
            and mechTM.currentTradeStatus(trade, initStop, bar) < MIN_X):
        # TODO try by ignoring BO Bar, ie once time limit is up, take last bar as extreme
        #extremePrice  = mechTM.getExtremePrice( trade, bar, extremePrice )      #  Not updated until Timestop => Trails behind recent extreme (or BO Bar whichever is further) after timestop is active
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER
        stop = mechTM.getTrailPrice(trade, bar, initStop, extremePrice,
                                    distance)

    return stop
Exemplo n.º 13
0
def trailOnProfit2( trade, bar, initStop, stop ):
    global extremePrice, trailAtr
        
    TRAIL_ATR_MULTIPLIER = 2
    MIN_X                = 1.5

    
    isPinBar = ( bar.H == bar.L )        
    if( not isPinBar ) :
        if trade.isLong:
            isPinBar = (bar.H-bar.C) / (bar.H-bar.L) > 0.75
        else:
            isPinBar = (bar.C-bar.L) / (bar.H-bar.L) > 0.75
    
    if( not isPinBar ):
        extremePrice = mechTM.getExtremePrice( trade, bar, extremePrice )

    if(  mechTM.currentTradeStatus( trade, initStop, bar ) >= MIN_X  ):
            distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER        
            return  mechTM.getTrailPrice( trade, bar, initStop, extremePrice, distance  ) 
    
    return stop
Exemplo n.º 14
0
def trailOnProfit2(trade, bar, initStop, stop):
    global extremePrice, trailAtr

    TRAIL_ATR_MULTIPLIER = 2
    MIN_X = 1.5

    isPinBar = (bar.H == bar.L)
    if (not isPinBar):
        if trade.isLong:
            isPinBar = (bar.H - bar.C) / (bar.H - bar.L) > 0.75
        else:
            isPinBar = (bar.C - bar.L) / (bar.H - bar.L) > 0.75

    if (not isPinBar):
        extremePrice = mechTM.getExtremePrice(trade, bar, extremePrice)

    if (mechTM.currentTradeStatus(trade, initStop, bar) >= MIN_X):
        distance = trailAtr[bar.Index] * TRAIL_ATR_MULTIPLIER
        return mechTM.getTrailPrice(trade, bar, initStop, extremePrice,
                                    distance)

    return stop