Hello World. I just created an indicator that can tell me when price is within +/- 0.10 of the closeprice. I have been able to loop it around all the symbols in my market watch thanks to help I got in this forum. However, the closePrice does not update when looping around the symbols and only calculates the close price of the first symbol. Can you please tell me what I'm doing wrong?
I have not run your code but it would be easier to debug if you compute the values used in the if condition and then inspect them during runtime.
For example:
double closePrice = PriceInformation[0].close; double closePriceLess -= 0.10; double closePriceMore += 0.10; if ( (ema_10[0]>=closePriceLess) && (ema_10[0]<= closePriceMore) )
Also inspect ema_10[0] to check the logic is working as expected - your brackets also look like they could be wrong
Give that a try as a first step
EMA_10_h=iMA(_Symbol,_Period,10,0,MODE_EMA,PRICE_CLOSE);
int Data=CopyRates(_Symbol,NULL,0,Bars(_Symbol,NULL), PriceInformation);
You are only getting the EMA and Close price of the chart symbol.
This is the third topic that you have started which is about the progression of the same code.
https://www.mql5.com/en/forum/433834
https://www.mql5.com/en/forum/433914
There is no need to start a new topic every time so continue with this one from now on.
- 2022.10.02
- www.mql5.com
This is the third topic that you have started which is about the progression of the same code.
https://www.mql5.com/en/forum/433834
https://www.mql5.com/en/forum/433914
There is no need to start a new topic every time so continue with this one from now on.
Can I use this one instead please? Whenever, I add new comment, people stop giving me help which is why I created a new one
//+------------------------------------------------------------------+ //| Another one..lol.mq5 | //| Chioma J. Obunadike | //| https://wa.me/+2349124641304 | //+------------------------------------------------------------------+ #property copyright "Chioma J. Obunadike" #property link "https://wa.me/+2349124641304" #property version "1.00" #property indicator_separate_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int EMA_10_h=0; // Asssign variable to 10EMA double ema_10[]; int OnInit() {EMA_10_h=iMA(NULL,_Period,10,0,MODE_EMA,PRICE_CLOSE); ArraySetAsSeries(ema_10,true); //--- indicator buffers mapping //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) {CopyBuffer(EMA_10_h,0,1,5,ema_10); for (int i=0; i<SymbolsTotal(1); i++) { MqlRates PriceInformation []; // defines closePrice. Source: https://www.youtube.com/watch?v=H10QFIZoUYA ArraySetAsSeries(PriceInformation,true); int Data=CopyRates(NULL,NULL,0,Bars(NULL,NULL), PriceInformation); double closePrice = PriceInformation[0].close; if ((ema_10[0])>=((closePrice)-0.10) && (ema_10[0])<= ((closePrice)+0.10)) Print("SYMBOL: ",SymbolName(i,1)," Found At: ", +closePrice ); else Print ("Not here", "SYMBOL: ",SymbolName(i,1), +closePrice); } //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
I have replaced all "_Symbol" with "NULL" yet my results remain unchanged. Any tips please?
I have not run your code but it would be easier to debug if you compute the values used in the if condition and then inspect them during runtime.
For example:
Also inspect ema_10[0] to check the logic is working as expected - your brackets also look like they could be wrong
Give that a try as a first step
Hi @R4tna C thanks for the advice!
I did what you recommended but there has been no change. My code compiles and runs on all symbols but the only problem I have is that it isn't updating the closePrice for every symbol its loops on
Can I use this one instead please? Whenever, I add new comment, people stop giving me help which is why I created a new one
I have replaced all "_Symbol" with "NULL" yet my results remain unchanged. Any tips please?
Why? What do you expect to happen by using NULL instead of the symbol?
With respect you should not be trying to work on code such as this as it is way above your level.
Start with something simple and make sure that you completely understand what the code does.
Why? What do you expect to happen by using NULL instead of the symbol?
With respect you should not be trying to work on code such as this as it is way above your level.
Start with something simple and make sure that you completely understand what the code does.
I thought adding the “NULL” function would make the program run on all symbols 🤷♀️
Documentation for iMA
symbol
[in] The symbol name of the security, the data of which should be used to calculate the indicator. The NULL value means the current symbol
NULL means the current chart symbol.
Documentation for CopyRates
symbol_name
[in] Symbol name.
Nowhere does it say that you can use NULL.
Documentation for iMA
NULL means the current chart symbol.
Documentation for CopyRates
Nowhere does it say that you can use NULL.
Yes as Keith has pointed out, you need to specify the symbol.
I don't usually use this approach, but I think as you are using a SymbolsTotal() loop, it looks like you need to get the symbol for each iteration of the loop and use that.
Here is an (incomplete) example to give you an idea.
string symbol; for(int i = 0; i < SymbolsTotal(true); i++) { symbol = SymbolName(i, true); MqlRates PriceInformation []; // defines closePrice. Source: https://www.youtube.com/watch?v=H10QFIZoUYA ArraySetAsSeries(PriceInformation,true); int Data = CopyRates(symbol,NULL,0,Bars(NULL,NULL), PriceInformation); double closePrice = PriceInformation[0].close;
Why is no one pointing out you don't need to copy the total rates, if your intention is to compare the last value only?
int Data = CopyRates(symbol, 0, 0, 1,PriceInformation); //--- Check the number of values copied if(Data!=1) continue; double closePrice = PriceInformation[0].close;Looking at your code, it is important to note that the value 0.1 is different from pair to pair, for Fiber (EurUsd) that is about a 1000 pips while for gold,silver, JPY pairs you get the point.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello World. I just created an indicator that can tell me when price is within +/- 0.10 of the closeprice. I have been able to loop it around all the symbols in my market watch thanks to help I got in this forum. However, the closePrice does not update when looping around the symbols and only calculates the close price of the first symbol. Can you please tell me what I'm doing wrong?