// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Capital Coders LLC //@version=4 strategy("Fiverr - Strategy - TheDreamBaby", overlay=true, currency = currency.USD, pyramiding = 1) //Uncomment the below section if you are using this Template for Forex and using Leverage for position Sizing //============================================================================== //FOREX EXCHANGE - Currency Conversion //============================================================================== //Select quote currency //quoteCurrency = syminfo.currency //gets quote currency automatically by looking using syminfo function - thank you Rodenwild //Get currency pair rate quoted against USD (base currency) //usdUSDrate = security("USDUSD", "D", close[1]) //gbpUSDrate = security("GBPUSD", "D", close[1]) //audUSDrate = security("AUDUSD", "D", close[1]) //nzdUSDrate = security("NZDUSD", "D", close[1]) //cadUSDrate = security("CADUSD", "D", close[1]) //chfUSDrate = security("CHFUSD", "D", close[1]) //eurUSDrate = security("EURUSD", "D", close[1]) //jpyUSDrate = security("JPYUSD", "D", close[1]) //Fuction to get currency rate into variable //cr_function(source) => // if quoteCurrency == "USD" // 1 // else // if quoteCurrency == "GBP" // gbpUSDrate // else // if quoteCurrency == "AUD" // audUSDrate // else // if quoteCurrency == "NZD" // nzdUSDrate // else // if quoteCurrency == "CAD" // cadUSDrate // else // if quoteCurrency == "CHF" // chfUSDrate // else // if quoteCurrency == "EUR" // eurUSDrate // else // jpyUSDrate //Put currency rate function into variable //cr_multi = cr_function(tr(true)) //============================================================================== //============================================================================== //BACKTEST DATE RANGE - Select Dates //============================================================================== //Input for date window start = input(timestamp("2015-12-12T00:00:00"), type=input.time, title="Start Date",group="============ BACKTEST RANGE ============") finish = input(timestamp("2022-12-12T00:00:00"), type=input.time, title="Finish Date") //Configure Date window dateRange() => time >= start and time <= finish ? true : false //============================================================================== //============================================================================== //============================================================================= // INDICATOR 1 - Entry Trigger //============================================================================= //Indicator Name gr = "======== Ichimoku Settings ========" conversionPeriods = input(9, minval=1, title="Tenkan Length", group = gr) basePeriods = input(26, minval=1, title="Kijun Length", group = gr) laggingSpan2Periods = basePeriods*2 displacement = basePeriods donchian(len) => avg(lowest(len), highest(len)) conversionLine = donchian(conversionPeriods) baseLine = donchian(basePeriods) leadLine1 = avg(conversionLine, baseLine) leadLine2 = donchian(laggingSpan2Periods) c_value = close chikou_ext = line.new(x1=bar_index[basePeriods], x2=bar_index, y1=c_value, y2=c_value, xloc = xloc.bar_index, width=1, color = color.new(#ff9538,10),extend = extend.right) line.delete(chikou_ext[1]) plot(conversionLine, color= color.new(#2fd5ee, 10), title="Tenkan") plot(baseLine, color= color.new(#f7a1af,10), title="Kijun") plot(close, offset = -displacement, color= color.new(#ff9538,10), title="Chikou") p1 = plot(leadLine1, offset = displacement - 1, color=color.new(#969696,10),title="Span A") p2 = plot(leadLine2, offset = displacement - 1, color= color.new(#d5bc58,10),title="Span B") fill(p1, p2, color = leadLine1 > leadLine2 ? color.new(#429b27, 85): color.new(#eb0000,85)) b1 = conversionLine > baseLine b2 = true b3 = close > max(leadLine1[displacement], leadLine2[displacement]) b4 = leadLine1 > leadLine2 b5 = close > conversionLine buy = b1 and b2 and b3 and b4 and b5 ? true : false s1 = conversionLine < baseLine s2 = true s3 = close < min(leadLine1[displacement], leadLine2[displacement]) s4 = leadLine1 < leadLine2 s5 = close < conversionLine sell = s1 and s2 and s3 and s4 and s5 ? true : false last = 0 last := buy ? 1 : sell ? -1 : last[1] color_candles = input(true, title = "Color Candles") candle_color = color_candles and last != last[1] ? color.new(#fe01ff,0) : color_candles and buy ? color.new(#01ff01,0) : color_candles and sell ? color.new(#fe0001,0) : color_candles ? color.new(#818180,0) : na //barcolor(color_candles and last != last[1] ? color.new(#fe01ff,0) : color_candles and buy ? color.new(#01ff01,0) : color_candles and sell ? color.new(#fe0001,0) : color_candles ? color.new(#818180,0) : na) barcolor(candle_color) //plotcandle(open, high, low, close,color = candle_color, wickcolor = candle_color, bordercolor = candle_color) //Long and Short Orders (Confirmation Conditions) Ind_1_L = buy and not buy[1] Ind_1_S = sell and not sell[1] //============================================================================== //============================================================================= // INDICATOR 2 - Filter //============================================================================= //Indicator Name //Long and Short Orders (Confirmation Conditions) Ind_2_L = true Ind_2_S = true //============================================================================== //============================================================================= // INDICATOR 3 - //============================================================================= //Indicator Name //Long and Short Orders (Confirmation Conditions) Ind_3_L = true Ind_3_S = true //============================================================================== //============================================================================= // INDICATOR 4 - //============================================================================= //Indicator Name Ind_4_L = true Ind_4_S = true //============================================================================== //============================================================================== //INDICATOR 5 - //============================================================================== //Indicator Name //Long and Short Orders (Confirmation Conditions) Ind_5_L = true Ind_5_S = true //============================================================================== //============================================================================== //INDICATOR 6 - //============================================================================== //Indicator Name //Long and Short Orders (Confirmation Conditions) Ind_6_L = true Ind_6_S = true //============================================================================== //============================================================================== //ALERT COMMENTS - Configure Alerts //============================================================================== Entry_Long_Alert = input(title = "Entry Long Alert Message" , defval = "A Long Entry has triggered", group="============ ALERT CONFIG ============") Entry_Short_Alert =input(title = "Entry Short Alert Message" , defval = "A Short Entry has triggered", group="============ ALERT CONFIG ============") Exit_Long_Alert =input(title = "Exit Long Alert Message" , defval = "A Long Exit has triggered", group="============ ALERT CONFIG ============") Exit_Short_Alert =input(title = "Exit Short Alert Message" , defval = "A Short Exit has triggered", group="============ ALERT CONFIG ============") Close_Long_Alert =input(title = "Close Long Alert Message" , defval = "A Long Close has triggered", group="============ ALERT CONFIG ============") Close_Short_Alert =input(title = "Close Short Alert Message" , defval = "A Short Close has triggered", group="============ ALERT CONFIG ============") //============================================================================== //Money Management //============================================================================== // Long and Short Trigger Conditions ShortSignals = input(true,"Include Short Trades", group="============ TRADE MGT ============") LongSignals = input(true,"Include Long Trades") //Long and short strategy conditions entry_long = strategy.position_size <=0 and dateRange() and Ind_1_L and Ind_2_L and Ind_3_L and Ind_4_L and Ind_5_L and Ind_6_L and LongSignals entry_short = strategy.position_size >=0 and dateRange() and Ind_1_S and Ind_2_S and Ind_3_S and Ind_4_S and Ind_5_S and Ind_6_S and ShortSignals plotshape(entry_long, color=color.lime, style=shape.arrowup, location = location.belowbar, text="Buy") plotshape(entry_short, color=color.red, style=shape.arrowdown, location = location.abovebar, text="Sell") //Submit long and short orders based on entry conditions if(entry_long) strategy.entry(id="Long Entry 1", long=true, alert_message = Entry_Long_Alert) if(entry_short) strategy.entry(id="Short Entry 1", long=false, alert_message = Entry_Short_Alert) //============================================================================== //============================================================================== // STATIC OR TRAILING STOP LOSS - Conditions //============================================================================== // Select Static or trailing Stoploss Exit_Type = input(defval = "None", title = "Exit Condition Type", options = ["None", "Static", "Trail SL"]) static_Take_Profit = input(title = 'Static Take Profit (%)', minval = 0.0, step = 0.1, defval = .5) * 0.01 static_Stop_Loss = input(title = 'Static Stop Loss (%)', minval = 0.0, step = 0.1, defval = .5) * 0.01 TrailPerc = input(title="Trail Long Loss (%)", minval=0.0, step=0.1, defval= .5) * 0.01 // Store Values entry_atr = float(0.0) //set Float entry_price = float(0.0) //set Float entry_price := strategy.position_size == 0 or entry_long or entry_short ? close : entry_price[1] // Calculate Stop Loss and Take Profit Distance (in price) nloss = entry_price * static_Stop_Loss //1.5 * atr Default nprofit = entry_price * static_Take_Profit //1.5 * atr Default //Find Long entry stop loss and Take Profit long_stop_level = 0.0 long_profit_level = Exit_Type == "Static" ? float(0.0) : na //set float if(Exit_Type == "Static") long_stop_level := entry_price - nloss long_profit_level := entry_price + nprofit else long_stop_level := if (strategy.position_size > 0) stopValue = close * (1 - TrailPerc) max(stopValue, long_stop_level[1]) else 0 //Find Short entry stop loss and Take Profit short_stop_level = 0.0 short_profit_level = float(0.0) //set float if(Exit_Type == "Static") short_stop_level := entry_price + nloss short_profit_level := entry_price - nprofit else short_stop_level := if (strategy.position_size < 0) stopValue = close * (1 + TrailPerc) min(stopValue, short_stop_level[1]) else 999999 //Plot stop loss and profit level on graph; hide levels when no trade plot(strategy.position_size <= 0 or entry_long or entry_short or Exit_Type == "None" ? na : long_stop_level, color = color.red, style = plot.style_linebr, linewidth = 2) plot(strategy.position_size >= 0 or entry_long or entry_short or Exit_Type == "None" ? na : short_stop_level, color = color.red, style = plot.style_linebr, linewidth = 2) plot(strategy.position_size <= 0 or entry_long or entry_short or Exit_Type == "None" or Exit_Type == "Trail SL" ? na : long_profit_level, color = color.green, style = plot.style_linebr, linewidth = 2) plot(strategy.position_size >= 0 or entry_long or entry_short or Exit_Type == "None" or Exit_Type == "Trail SL" ? na : short_profit_level, color = color.green, style = plot.style_linebr, linewidth = 2) //============================================================================== //============================================================================== //EXIT CONDITIONS - Submit Orders //============================================================================== // //Submit exit orders on static profit and loss if(Exit_Type == "Static")//Use a static SL or TP //Long Exits strategy.exit("TP/SL 1", "Long Entry 1", stop = long_stop_level, limit = long_profit_level) //Short Exits strategy.exit("TP/SL 1", "Short Entry 1", stop = short_stop_level, limit = short_profit_level) else if (Exit_Type == "Trail SL") //Use a Trailing SL //Long Exits strategy.exit("TP/SL 2", "Long Entry 1", stop = long_stop_level, limit = na) //Short Exits strategy.exit("TP/SL 2", "Short Entry 1", stop = short_stop_level, limit = na) //Submit exit orders on exit indicator - Exit 1 strategy.close(id="Long Entry 1", comment = "Exit 1 L1", when = not buy, alert_message = Close_Long_Alert) strategy.close(id="Short Entry 1", comment = "Exit 1 S1", when = not sell, alert_message = Close_Short_Alert) //==============================================================================