Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // STRATEGY SETTINGS
- // Backtest Range
- FromYear = input( defval = 2017, title = "Strategy from Year", type=integer, minval = 2011 )
- FromMonth = input( defval = 04, title = "... Month", type=integer, minval = 1 )
- FromDay = input( defval = 01, title = "... Day", type=integer, minval = 1 )
- ToYear = input( defval = 2018, title = "Strategy to Year", type=integer, minval = 2011 )
- ToMonth = input( defval = 03, title = "... Month", type=integer, minval = 1 )
- ToDay = input( defval = 31, title = "... Day", type=integer, minval = 1 )
- isTimeRange = ( time > timestamp( FromYear, FromMonth, FromDay, 00, 00 ) ) and ( time < timestamp( ToYear, ToMonth, ToDay, 23, 59 ) )
- // -----------------------------------------------------------------------------
- // *****************************************************************************
- // STRATEGY
- // ________________________
- // ______ CONDITIONS ______
- // Definition of strategy conditions
- // NOTE: A "long trade" (i.e. buying to enter the market, then selling at a higher price to exit)
- // is called "Bull Trade".
- // Conversely, a "short trade" (i.e. selling to enter the market, then buying at a lower price to exit)
- // is called "Bear Trade".
- // The logic is always the same: "buy low, sell high" (whatever the order in time).
- // BUY CONDITIONS
- // Entry for a bull trade, exit for bear trade
- // simple conditions for example, using long TF
- // Look for a low above the lines (candle entirely out of the band)
- priceOverNegStDev1 = crossover(low, longDevLineBelow1) // Negative Standard Deviation (i.e. below the mean)
- priceOverNegGolden = crossover(low, longDevLineBelow2) // Negative Golden Deviation
- // Trigger a bull signal when conditions are met
- bullSignal = priceOverNegStDev1 or priceOverNegGolden
- // SELL CONDITIONS
- // Exit for bull, entry for bear
- // simple conditions for example, using long TF
- // Look for a high below the bands
- priceOverPosStDev1 = crossunder(high, longDevLineAbove1) // Positive Standard Deviation (i.e. above the mean)
- priceOverPosGolden = crossunder(high, longDevLineAbove2) // Positive Golden Deviation
- // Trigger a bear signal when conditions are met
- bearSignal = priceOverPosStDev1 or priceOverPosGolden
- // ________________________
- // ______ EXECUTION ______
- // BULL TRADE
- strategy.entry( "BULL", strategy.long, when=( bullSignal and isTimeRange ) )
- strategy.close( "BULL", when=( bearSignal and isTimeRange ) )
- // BEAR TRADE
- //strategy.entry( "BEAR", strategy.short, when=( bearSignal and isTimeRange ) )
- //strategy.close( "BEAR", when=( bullSignal and isTimeRange ) )
- // End of STRATEGY
- // *****************************************************************************
- // -----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement