wolfParticipant
Junior
Hi, Im having trouble coding a system where it will open a position after a stock has risen/fallen 1% in the last 30 minutes.
Any help is welcome since I have been struggling to code anything that works.
Thank you
Jem
There is a specific instruction for Variation that you can use easily to make what you want to do.
On a 30 minutes chart, the code would be :
condition = Variation(close)>=1
IF condition THEN
BUY 1 SHARE AT MARKET
ENDIF
wolfParticipant
Junior
ok great thank you, but what if i wanted the last 30 minutes but on a 5 minute chart?
Thanks
You can code it like this, make the summation of the last 6 Variation (6 x 5minutes candlesticks = 30 minutes) :
condition = summation[6](Variation(close))>=1
Didn’t test it though, but it should work ok.
wolfParticipant
Junior
Hi Nicolas,
I’ve tested it and it seems to work but still unsure as it is the weekend, but thank you for your help.
I would greatly appreciate it if you could breakdown the part of code listed below since I might need to adjust some conditions at a later date.
Thanks
Code:
condition = summation[100](Variation(close))>=1
IF condition THEN
buy 1 share at market
ENDIF
You want me to explain each line?
wolfParticipant
Junior
no sorry just this part please ‘summation[100](Variation(close))>=1’
Summation calculate the sum over the last X periods (100 in this case) of the value under brackets.
But in this statement, we test if this summation is superior or equal to 1. So if it’s true, the ‘condition’ variable is set to 1 (which is “true” in PRT language).
wolfParticipant
Junior
ok thank you, so if i wanted to adjust the code to look for 2% changes instead of 1%, what part should i alter.
wolfParticipant
Junior
Also it doesnt seem to work with stocks that have fallen x % it only shows stocks that have gone up
wolfParticipant
Junior
Hi Nicolas,
After doing some testing ive found out it works alot better in a screener format, ive only changed the code from ‘buy 1 share at market’ to ‘screener’ and ive found these issues:
- Code doesn’t display stocks that have fallen, only risen
- It doesn’t work alot of the time, for example to test the code, I found some examples where the stock has risen 1% or more in the last few hours of Friday’s trading day and adjusted the screener to the same amount of hours and the stock wont appear in the screener when it should.
- It works well when candles our on ‘daily’ (still only stocks that have risen) but when I put it on 10 mintues or 5 minutes I have many issues.
Any help is welcome, thank you
Yes this code is only for rising 1%, if you want to catch the falling stocks, just change the formula to find the ones that are <=-1% .. that’s all 🙂
I believe you have not real time access, only EOD?
wolfParticipant
Junior
Just added the falling stock code, and everything has gone crazy lol. Have I done something wrong? as it now picks stocks that havnt moved more than 1% in the last 30 mins. Ive attached a picture where you can see my code, the stock and the screener on the left.
Thanks for your help 🙂
Image: https://gyazo.com/925f98b99649fb9601bb6d8a7874e259
Ouch…what have you done? 😨
I’ll fix this tomorrow or maybe later.
You can also upload pictures here FYI.
wolfParticipant
Junior
Clearly im good at breaking stuff haha
Anytime before monday would be hugely appreciated.
I saw you could but the program i use gives me a web link but ill upload the images instead from now on 🙂