Great thank you! I have managed to get them working
, I am new to pine coding and coding in general so I am trying to convert or create different strategy's to get used to the whole process and try to gain a little knowledge.. I do seem to keep coming up against an issue with the strategy tester not entering trades on the conditions i have set? ideally i'd lile to close after a certain amount of bars, I also am not ever able to see any stats on profit or drawn down - it seems to stay on $0 or a few pence difference. I have copied the code from one such example, could you see if there's anything obvious causing this? thanks again, this forum and pinemasters have been a god send!
Code: Select all
strategy("My strategy", overlay=true, currency = currency.USD, initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 1000, margin_long = 1000, margin_short = 1000)
RSI_PER = 14
pivot_right = 5
pivot_left = 5
max_range=50
min_range=5
// Creating rsi indicator
rsi_value = ta.rsi(close, RSI_PER)
//plot(rsi_value, title="RSI", linewidth=2, color=color.white)
//hline(50, linestyle=hline.style_dotted)
//rsi_ob = hline(70, linestyle=hline.style_dotted)
//rsi_os = hline(30, linestyle=hline.style_dotted)
//fill(rsi_ob, rsi_os, color=color.new(color.red, 80))
//check if we have pivot low in rsi
pivot_low_true = na(ta.pivotlow(rsi_value, pivot_left, pivot_right)) ? false : true //returns price of the pivot low point. It returns 'NaN', if there was no pivot low point.
pivot_high_true = na(ta.pivothigh(rsi_value, pivot_left, pivot_right)) ? false : true
//Create a function that returns true/false
confirm_range(x) =>
bars = ta.barssince(x == true) //Counts the number of bars since the last time the condition was true
min_range <= bars and bars <= max_range // makes ure bars is less than 60 and less than 5 and returns true
//------------------------------------------------------------------------------
// RSI higher low check
RSI_HL_check = rsi_value[pivot_right] > ta.valuewhen(pivot_low_true, rsi_value[pivot_right], 1) and confirm_range(pivot_low_true[1])
RSI_LH_check = rsi_value[pivot_right] > ta.valuewhen(pivot_high_true, rsi_value[pivot_right], 1) and confirm_range(pivot_low_true[1])
// Price Lower Low check
price_ll_check = low[pivot_right] < ta.valuewhen(pivot_low_true, low[pivot_right], 1)
price_12_check = high[pivot_right] < ta.valuewhen(pivot_high_true, high[pivot_right], 1)
bullCond = price_ll_check and RSI_HL_check and pivot_low_true
bearCond = price_12_check and RSI_LH_check and pivot_high_true
//STRATEGY TEST
if (bullCond)
strategy.entry("Go Long", strategy.long, 100, when = bullCond)
strategy.close("Go Long")
if (bearCond)
strategy.entry("Go Short", strategy.long, 100, when = bearCond)
strategy.close("Go Short")
// SIMPLE ENTRY LOGIC (insert long/short signal here)
//Plot the areas, terneary conditional operator
//plot(pivot_low_true ? rsi_value[pivot_right] : na,offset=-pivot_right,linewidth=3,color=(bullCond ? color.green : color.new(color.white, 100)))//colornew applies the specified transparency to the given color
plotshape(bullCond ? rsi_value[pivot_right] : na,offset=-pivot_right,text=" BUY ",style=shape.arrowup,location=location.belowbar, size = size.normal,color=color.green,textcolor=color.white)
//plot(pivot_high_true ? rsi_value[pivot_right] : na,offset=-pivot_right,linewidth=3,color=(bearCond ? color.red : color.new(color.white, 100)))//colornew applies the specified transparency to the given color
plotshape(bearCond ? rsi_value[pivot_right] : na,offset=-pivot_right,text=" SELL ",style=shape.arrowdown,location=location.abovebar, size = size.normal, color=color.red,textcolor=color.white)