Levas: int P2t=iHighest(iMA(NULL,0,2,0,MODE_SMA,PRICE_CLOSE,i),0,MODE_HIGH,10,1);
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- iMA returns a price. What is the first parameter of iHighest? Of course it won't work.
- You would have to read multiple bars of iMA and find the highest value.
WHRoeder:
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- iMA returns a price. What is the first parameter of iHighest? Of course it won't work.
- You would have to read multiple bars of iMA and find the highest value.
Thanks a lot. I have updated the post. Much better now :)
I have also tried:
double MA2H = 0; double findMA2H() { for (int i=1; i<10; i++) if (iMA(NULL,0,2,0,MODE_SMA,PRICE_CLOSE,i)>MA2H) { MA2H = iMA(NULL,0,2,0,MODE_SMA,PRICE_CLOSE,i); return MA2H; } };
And then the buying condition if:
Close[0]<MA2H
But I don´t manage it..... :(
Please make it clear whether your code is part of the main code or a function as we don't know where your return takes you.
for (int i=1; i<10; i++) if (iMA(NULL,0,2,0,MODE_SMA,PRICE_CLOSE,i)>MA2H) { MA2H = iMA(NULL,0,2,0,MODE_SMA,PRICE_CLOSE,i); return MA2H; }
Your loop exits after the first pass.
MA2H=0, so the iMA for index 1 must be bigger and that causes the return.
The return should be after the loop.
If it is not part of a function, then you don't want to return at all.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello!!
This is my first topic. I am new in this forum and just started to program some expert advisors :)
I am trying to get a code for getting the highest value of a moving averaage within a period of time,for example 10 bars, but I am not able to get it.
I have tried:
But it is not working and I don´t manage to solve it.
My idea is for example buying if:
Close[0]<P2
I also tryied to find it the information in th forum, but I am quite new and get lost with the formulas...
Thanks in advance for your help!!