hi
first post from sweden.
im looking for a code to do the following:
Buy stock when up 2,2% from openening price the same day and then has retracted down below a moving average of my choosing during a specefic timeframe say the first 60 min from market open.
I have tryied coding it whotout succses, having problems whit getting the % up to work.
Thanks for the help.
br marcus, sweden.
You can try with the below code, the “trigger” variable is the one used to test the gap percent at the first opening hour. “endtime” is the time limit to test the price retraction below the moving average. There is no stop and limit in the code.
defparam cumulateorders=false
trigger = 0.5 //trigger in percent
timeframe(daily)
percent = Variation(close)
timeframe(default)
endtime = 100000
MAperiod = 10
if day<>day[1] then
todayvar = percent
todaystart=barindex
endif
MA = average[MAperiod](close)
if time<=endtime and todaystart<>start and todayvar>=trigger and close crosses under MA then
start=todaystart
buy at market
endif
//graph time<=endtime and todaystart<>start and todayvar>=trigger