Heya guys (and gals perhaps?)!
I´m new to metatrader, been doing some very simple ea's and slowly making them more advanced. I am now trying to make an ea that buys when RSI is below 10 and when the last periods MA50 is higher then it has been duuring the last 50 periods. I have been searching alot around this forum and within the documentation, but I´m still stuck. I get no signals what so ever.
I would really appreciate if someone could take a look at my code and tell me where I´m doing it wrong.
Thanks in advance!
You declare your arrays . .
double madaily1[5], madaily2[5];
. . . with 5 elements and then try to write 20 elements ?
int malookback1 = 20; for(int i=0; i<malookback1; i++) { madaily1[i] = iMA(NULL,0,madailyPERIOD,0,0,0,i); dhhv1 = iHigh(NULL,0,(ArrayMaximum(madaily1,20, 1))) ; }
why don't you get the max value in the array when it is fully populated ? i.e. outside of the for loop ?
OrderSend() does not return a bool . . . it returns an int, get into the habit of checking the return values from your trading functions and if they have failed report the error and any relevant variables, read this: What are Function return values ? How do I use them ?
Thank you, I now get signals but not the way I want. I get signals even when the last periods ma50 is lower then the prevoius 20 periods.
I´ll keep looking into this and if you or someone else finds anything that seems to be wrong i my code, please to tell.
Again, thanks for you help.
#define __STRATEGY_MAGIC 1293699797 //Inputs //Declaration double _RSI; bool _Compare; bool _Open_Position; bool _ma50; double madaily1[20], madaily2[20];//declare an array double dhhv1, dllv1, dhhv2, dllv2; int madailyPERIOD = 50; //moving average period int malookback1=20; //antal perioder att se bakåt int malookback2=1; //antal perioder att se bakåt int start(){ for(int i=0;i<malookback1; i++) { madaily1[i]=iMA(NULL,0,madailyPERIOD,0,0,0,i); } dhhv1=iHigh(NULL,0,(ArrayMaximum(madaily1,20, 1))) ; for(int i1=0;i<malookback2; i++) { madaily2[i1]=iMA(NULL,0,madailyPERIOD,0,0,0,i1); } dhhv2=iHigh(NULL,0,(ArrayMaximum(madaily2,2, 1))) ; _ma50 = dhhv2 > dhhv1; //Level 1 _RSI = iRSI(Symbol(),0,5,5,0); //Level 2 _Compare = _RSI > 10; //Level 3 if(_ma50 && _Compare && !__isExist(0))_Open_Position = OrderSend(Symbol(),0,01,MarketInfo(Symbol(),MODE_ASK),30,MarketInfo(Symbol(), MODE_ASK)-MarketInfo(Symbol(),MODE_POINT)*100,MarketInfo(Symbol(),MODE_ASK)+MarketInfo(Symbol(),MODE_POINT)*150,"",__STRATEGY_MAGIC + 0)>=0; return(0); } //Services bool __selectOrderByMagic(int __magic){for(int __i=0;__i<OrdersTotal();__i++){if(OrderSelect(__i,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==__STRATEGY_MAGIC+__magic)return(true);}return(false);} bool __isExist(int __magic){return(__selectOrderByMagic(__magic));}
Thank you, I now get signals but not the way I want. I get signals even when the last periods ma50 is lower then the prevoius 20 periods.
I´ll keep looking into this and if you or someone else finds anything that seems to be wrong i my code, please to tell.
I told you about something else that was wrong but you ignored my advice . . .
OrderSend() does not return a bool . . . it returns an int, get into the habit of checking the return values from your trading functions and if they have failed report the error and any relevant variables, read this: What are Function return values ? How do I use them ?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Heya guys (and gals perhaps?)!
I´m new to metatrader, been doing some very simple ea's and slowly making them more advanced. I am now trying to make an ea that buys when RSI is below 10 and when the last periods MA50 is higher then it has been duuring the last 50 periods. I have been searching alot around this forum and within the documentation, but I´m still stuck. I get no signals what so ever.
I would really appreciate if someone could take a look at my code and tell me where I´m doing it wrong.
Thanks in advance!