- Custom symbols. Errors, bugs, questions, suggestions.
- Moving Average RSI
- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
Do not double post
Your other topic has been deleted.
#property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict int SMA_CrossUp; int SMA_CrossDown; //-- Ma CrossOver settinga-----------------------------------------// extern int SlowMa =50; extern int SlowMaShift =0; extern int SlowMaMethod =0; // '0' = simple extern int SlowMaAppliedTo =0; //on the close //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(IsThisANewCandle()) { CheckMa(); } } //+------------------------------------------------------------------+ //|MA CrossOver funtion for direcrtion. | //+------------------------------------------------------------------+ void CheckMa() { //-- Up arrow------------------------------------------------------- int i; for(i=0.0; i<Bars; i++) if(Close[i]<Open[i]) { double CurrentSlow=iMA(NULL,0,SlowMa,SlowMaShift,SlowMaShift,SlowMaAppliedTo,i); if(Close[i]<CurrentSlow ) { string name="FXX_IchiupArrow"+(string)Time[0]; if(ObjectFind(0,name)!=0) { ObjectCreate(name,OBJ_ARROW_UP,0,Time[0],Low[0]-(Period()*Point*2));// Time[0] since you are talking about current bar ObjectSet(name,OBJPROP_COLOR,clrRed); ObjectSet(name,OBJPROP_WIDTH,1); ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_TOP); } } } //--Down arrow------------------------------------------------------- else if(Close[i]>Open[i]) { double CurrentSlow=iMA(NULL,0,SlowMa,SlowMaShift,SlowMaShift,SlowMaAppliedTo,i); if(Close[i]>CurrentSlow) { string name="FXX_IchiupArrow"+(string)Time[0]; if(ObjectFind(0,name)!=0) { ObjectCreate(name,OBJ_ARROW_DOWN,0,Time[0],High[0]+(Period()*Point*2));// Time[0] since you are talking about current bar ObjectSet(name,OBJPROP_COLOR,clrRed); ObjectSet(name,OBJPROP_WIDTH,1); ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_TOP); } } } } //--Is this a new Candle?---------------------------------------------// bool IsThisANewCandle() { static int BarsOnChart=100; //-- this will be update on initialization, static will stop it reseting if(Bars==BarsOnChart) //-- will update int in GBL with bars on current chart return(false); //-- No new number BarsOnChart=Bars; //-- Is this number higher than the last saved number return(true); //-- This is a new candle } //+------------------------------------------------------------------+
Hi, can anybody help me here, I'd very much appreciate it. This EA is supposed to just identify a candle as it crosses a SMA and mark it. Its not doing that. I've spent a good few days trying and failing to get it to work.
Code is:
You should make iMA() call for each 'i' (i.e. move your iMA() call into the 'for' loop, and instead of '1', use 'i').
Also, not sure why you chose to do this in EA rather than an indicator... because using EA, you have to name your arrows uniquely, and including time in their names will be more appropriate rather than the bar index 'i' because bar index for the same candle will change over time.
Another issue is your new candle check - don't use bar (won't be reliable especially when Bars will change as your page up/down or change your charts' display number of display bars). Use time instead.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use