Hey! I have written so much more advanced things than this so it is pretty embarrassing to write this, but part of my big code didn’t act like I wanted it and when I wrote out a sample and it still didn’t work, it is just a normal MA crossover. The buy and sell don’t appear where they are supposed to.
Please tell me what I have done wrong.
I will attach the code and also a picture of the result.
baseline=exponentialaverage(close)[100]
sma=average(close)[20]
if sma crosses over baseline then
buy 1 shares at market
endif
if sma crosses under baseline then
sellshort 1 shares at market
endif
The buy and sell don’t appear where they are supposed to.
Code is good so it must be your expectations above that are misleading you?
Attach a screenshot and explain more what you expecting?
Right I’m sorry, I tried, I’ll try again.
Try GRAPH = sma crosses over baseline in your Algo code … does it show a 1 / true at correct positions?
Essraw – I have given your topic a more meaningful title. Please try to use more descriptive titles on any future topics.
Have you double checked whether your SMA and EMA indicators are both using close and not something else such as median price?
Thank you Vonasi, GraHal I don’t quite get what you mean.
GraHal is suggesting adding the line:
GRAPH sma crosses over baseline
….to the bottom of your strategy. I imagine though that it will just show the same points of crossover as your strategy is opening and closing trades.
Oh I see, yeah I tested it now, it shows the same!
Yes they are all using close
Have you checked your SMA and EMA settings? Perhaps you have them averaging something different or a horizontal shift added so your indicators are showing something different to your strategy code?
I have just done a quick test and can confirm that something is wrong. It appears to be trading when either close or high or low crosses the EMA. I will test further but there does seem to be some sort of bug.
Yes it seems very weird! I have done a similar code a few weeks back and there was no problem!
It is a typo in your first two lines. Change it to this:
baseline=exponentialaverage[100](close)
sma=average[20](close)