//@version=5 // Declaration of variables var TP75 = 0.0 //75% of take profit reached var size_val = 0.0 var slip = 0 orb_high = float(na) orb_low = float(na) var tp_long_rel = 0.0 var tp_short_rel = 0.0 var sl_short_rel = 0.0 var SL_long_rel = 0.0 var TP_Long = 0.0 var TP_Short = 0.0 var SL_Short = 0.0 var SL_Long = 0.0 var total_trades = 0 var long_trades = 0 var short_trades = 0 var D_Close = 0.0 var check_long = 0 var check_short = 0 var moved_sl_msg = 0 var long_trading_day = false var short_trading_day = false var long_allowed = false var short_allowed = false // Set user input values riskPN = input.float(title="Risk per Trade [%]", defval = 1.5, tooltip = "Please specifiy your risk + in % per trade. Maximum is 3% and minimum is 0.1%.", minval = 0.01, maxval = 3.0, group="PineConnector Settings") openHourCET = input.int(defval=7, title="Entry Hour (CET)", minval=0, maxval=23) openMinuteCET = input.int(defval=40, title="Entry Minute (CET)", minval=0, maxval=59) closeHourCET = input.int(defval=13, title="Exit Hour (CET)", minval=0, maxval=23) closeMinuteCET = input.int(defval=0, title="Exit Minute (CET)", minval=0, maxval=59) // Funktion zum Konvertieren von CET in die aktuelle Zeitzone der Börse timeCET(year, month, day, hour, minute) => timestamp("CET", year, month, day, hour, minute) // Konvertiere die Öffnungs- und Schließzeiten in Unix-Zeitstempel openTimeCET = timeCET(year, month, dayofmonth, openHourCET, openMinuteCET) closeTimeCET = timeCET(year, month, dayofmonth, closeHourCET, closeMinuteCET) SL_value = input.float(title="SL-Mutiplikator ATR",defval=4) max_trades_short = input.int(title="Max Trades Short:",defval = 1) max_trades_long = input.int(title="Max Trades Long:",defval = 0) max_trades = input.int(title="Max Trades Total:",defval = 1) direction = input.int(title="Long/Short",defval=2,tooltip = "Please decide if you want to activate only + long = 1, only short = 2 or long and short = 3 direction.") CRV_long = input.float(title="CRV Long",defval=0.75,tooltip="With CRV Long you specify the TP. TP = + Entry + CRV Long * Opening Range.") CRV_short = input.float(title="CRV Short",defval=1.0,tooltip="With CRV Short you specify the TP. TP = + Entry - CRV Long * Opening Range.") TrailingSL75 = input.bool(title="SL-75%",defval=false) TrailingTreshold = input.float(title="SL-75%-value",defval=0.75) MondayOn = input.bool(title="Monday",defval=true,group="Long Day") TuesdayOn = input.bool(title="Tuesday",defval=true,group="Long Day") WednesdayOn = input.bool(title="Wednesday",defval=true,group="Long Day") ThursdayOn = input.bool(title="Thursday",defval=true,group="Long Day") FridayOn = input.bool(title="Friday",defval=true,group="Long Day") ShortMondayOn = input.bool(title="Monday",defval=true,group="Short Day") ShortTuesdayOn = input.bool(title="Tuesday",defval=true,group="Short Day") ShortWednesdayOn = input.bool(title="Wednesday",defval=true,group="Short Day") ShortThursdayOn = input.bool(title="Thursday",defval=true,group="Short Day") ShortFridayOn = input.bool(title="Friday",defval=true,group="Short Day") // Setup strategy settings strategy('GBP Pounder Short RW', overlay=true, initial_capital=100000, slippage=slip, commission_type=strategy.commission.cash_per_contract) strategy.risk.max_intraday_filled_orders(count=2) D_Close := request.security(syminfo.tickerid, 'D', close[1], lookahead = barmerge.lookahead_on) // Check if today is a short trading day if ShortMondayOn if dayofweek == dayofweek.monday short_trading_day := true if ShortTuesdayOn if dayofweek == dayofweek.tuesday short_trading_day := true if ShortWednesdayOn if dayofweek == dayofweek.wednesday short_trading_day := true if ShortThursdayOn if dayofweek == dayofweek.thursday short_trading_day := true if ShortFridayOn if dayofweek == dayofweek.friday short_trading_day := true // Check if today is a long trading day if MondayOn if dayofweek == dayofweek.monday long_trading_day := true if TuesdayOn if dayofweek == dayofweek.tuesday long_trading_day := true if WednesdayOn if dayofweek == dayofweek.wednesday long_trading_day := true if ThursdayOn if dayofweek == dayofweek.thursday long_trading_day := true if FridayOn if dayofweek == dayofweek.friday long_trading_day := true // Functions // InSession() returns 'true' when the current bar happens inside // the specified session, corrected for the given time zone (optional). // Returns 'false' when the bar doesn't happen in that time period, // or when the chart's time frame is 1 day or higher. InSession(sessionTime) => not na(time(timeframe.period, sessionTime)) // Ma Filter Short // ************************************************************ flag_ma_short = input.bool(title="Ma-Filer (short)",defval=false) ma_val_1 = input.int(title="MA Value",defval=100) ma_1 = request.security(syminfo.tickerid,'D',ta.ema(close,ma_val_1)) plot(flag_ma_short ? ma_1 : na ,'MA (short)',#d335ff) var cond_ma_short = false if flag_ma_short if close < ma_1 cond_ma_short := true else cond_ma_short := false else cond_ma_short := true // ************************************************************ // Ma Filter Long // ************************************************************ flag_ma_Long = input.bool(title="Ma-Filer (long)",defval=false) ma_val_2 = input.int(title="MA Value (long)",defval=100) ma_1_long = request.security(syminfo.tickerid,'D',ta.ema(close,ma_val_2)) plot(flag_ma_Long ? ma_1_long : na ,'MA (long)') var cond_ma_long = false if flag_ma_short if close > ma_1 cond_ma_long := true else cond_ma_long := false else cond_ma_long := true // ************************************************************ // Vola Filter // ************************************************************ flag_vol = input.string(title="Vola Filter",defval="off",options=["off","low","high"]) fast_period = input.int(title="Fast",defval=2) slow_period = input.int(title="Slow",defval=14) atr_slow = request.security(syminfo.tickerid,'D',ta.atr(slow_period)) atr_fast = request.security(syminfo.tickerid,'D',ta.atr(fast_period)) cond_atr = false if flag_vol == "low" if atr_fast < atr_slow cond_atr := true else cond_atr := false if flag_vol == "high" if atr_fast > atr_slow cond_atr := true else cond_atr := false if flag_vol == "off" cond_atr := true // ************************************************************ // Long Trade Check // ************************************************************ if (time >= openTimeCET and time < openTimeCET + 60000) long_allowed := false if long_trading_day if direction == 1 or direction == 3 if long_trades <= max_trades_long if total_trades <= max_trades if cond_ma_long if cond_atr long_allowed := true else long_allowed := false else long_allowed := false // ************************************************************ // Short Trade Check // ************************************************************ if (time >= openTimeCET and time < openTimeCET + 60000) short_allowed := false if short_trading_day if direction == 2 or direction == 3 if short_trades <= max_trades_short if total_trades <= max_trades if cond_ma_short if cond_atr short_allowed := true else short_allowed := false else short_allowed := false // ************************************************************ ATR_2D = request.security(syminfo.tickerid,'D',ta.atr(2)) SL_Diff = ATR_2D*SL_value // Trade Entry // ************************************************************ if long_allowed TP_Long := close + 0.0001*800 //SL_Long := close - 0.0001*80 SL_Long := close - SL_Diff size_val := math.abs((riskPN/100*100000)/(close - SL_Long)) total_trades := total_trades + 1 long_trades := long_trades +1 strategy.entry('Long Trade', strategy.long, qty = size_val) if short_allowed TP_Short := close - 0.0001*800 //SL_Short := close + 0.0001*80 SL_Short := close + SL_Diff size_val := math.abs((riskPN/100*100000)/(SL_Short - close)) max_trades := max_trades + 1 max_trades_short := max_trades_short +1 strategy.entry('Short Trade', strategy.short, qty = size_val) // ************************************************************ //plot(size_val,'Size') if time > closeTimeCET long_trades := 0 short_trades := 0 total_trades := 0 short_trading_day := false long_trading_day := false TP75 := 0 SL_Long := 0.0 SL_Short := 0.0 sl_short_rel := 0.0 SL_Long := 0.0 TP_Long := 0.0 TP_Short := 0.0 tp_short_rel := 0.0 tp_long_rel := 0.0 moved_sl_msg := 0 strategy.close("Long Trade",'Time Limit') strategy.close("Short Trade",'Time Limit') if TrailingSL75 == true if strategy.position_size>0 if close >= TP75 and moved_sl_msg == 0 moved_sl_msg := 1 SL_Long := -1.0 if strategy.position_size<0 if close <= TP75 and moved_sl_msg == 0 sl_short_rel := -1.0 moved_sl_msg := 1 strategy.exit('Close Short','Short Trade', profit=10000, stop=SL_Short) strategy.exit('Close Long','Long Trade',profit=1000, stop=SL_Long) //plot(TP_Long,'TP-Long') //plot(TP_Short,'TP-Short') plot(SL_Short,'SL-Short',color=color.purple) plot(SL_Long,'SL-Long',color=color.rgb(84, 199, 228)) plot(TP75,'TP75',color=color.orange) //plot(strategy.losstrades[0],'Loss Trades 0') //plot(strategy.losstrades[1],'Loss Trades -1') //plot(strategy.wintrades[0],'Win Trades 0') //plot(strategy.wintrades[1],'Win Trades -1')