Basically I am trying to create a function that is almost exactly like an iRSI. Instead of "Symbol" I would like to use my custom variable that was calculated using the Symbols. I'm not looking for someone to code anything for me. I just need guidance. show me where to look for the information I need to build this thing. Show me where I'm going wrong.
Hello,
I would agree that you should grasp some programming concepts first, like variable scope (that suits your problem I guess), but I would say to go for C and not C++. Also you can have some read of the Language Basics on the MQL reference.
greets
I appreciate the feedback. I'm beginning to understand functions a little bit more. Now I just need to figure out how to use the parameters I want in my function. As you can see below my function no longer gives errors, however Its not done properly yet. The return function is hanging me up. If I put zero it just returns zero. If I dont use it it throws an error. I'm trying to understand the need for the return function with multiple parameters.
//+------------------------------------------------------------------+ //| My_Currency_Strength_Indicator.mq4 | //| Erick_Fenstermaker | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Erick_Fenstermaker" #property link "https://www.mql5.com" #property version "1.00" #property strict //Opening a separate window and setting the parameters of the window extents #property indicator_separate_window #property indicator_maximum 3 #property indicator_minimum -3 #property indicator_level1 0 #property indicator_level2 1.75 #property indicator_level3 -1.75 //Setting up the memory allocation and default settings for the indicator lines #property indicator_buffers 8 #property indicator_color1 clrPurple #property indicator_color2 clrRed #property indicator_color3 clrOrange #property indicator_color4 clrWhite #property indicator_color5 clrBlue #property indicator_color6 clrGreen #property indicator_color7 clrLightBlue #property indicator_color8 clrYellow #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 2 #property indicator_width5 2 #property indicator_width6 2 #property indicator_width7 2 #property indicator_width8 2 //Declaring the arrays that will draw the lines for the indicator double EUR_Band[]; double GBP_Band[]; double AUD_Band[]; double NZD_Band[]; double USD_Band[]; double CAD_Band[]; double CHF_Band[]; double JPY_Band[]; //double perEUR; //double perGBP; //double perAUD; //double perNZD; //double perUSD; //double perCAD; //double perCHF; //double perJPY; //Sets how far you look into the past (15 min incremints 4 = 1hr) int lookBack = 16 + 1; double iCSI(double ValueOfSymbol, int TimeFrame, int shift) { ValueOfSymbol = 0.0;//I'm doubting this bit is nessessary. Still trying to figure that out. TimeFrame = PERIOD_M15;// I doubt this is correct. I asume that I need to write some code here to mimic the source code of the iRSI to use timeframes //like this .If that is the case I dont no where to even begin with that. int Counted_bars = IndicatorCounted(); // Number of counted bars int limit = Bars - Counted_bars; // Index of the first uncounted shift = limit;//I'm just trying to figure out how to calculate the shift value to mimic the shift parameter in the iRSI function //Value of Symbol is either the symbol itself or a calculation based on the symbol //It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe //How many bars back are we looking at return(perEUR);//This part is confusing me. Why would I return one value with 3 parameters? whatever I put in here is where my buffer line is drawn } //+------------------------------------------------------------------+ //| Gathers the open and current price info | //+------------------------------------------------------------------+ //Gathers the EUR Symbol open values from the past double lookBackEURGBP = iOpen("EURGBP",PERIOD_M15,lookBack); double lookBackEURAUD = iOpen("EURAUD",PERIOD_M15,lookBack); double lookBackEURNZD = iOpen("EURNZD",PERIOD_M15,lookBack); double lookBackEURUSD = iOpen("EURUSD",PERIOD_M15,lookBack); double lookBackEURCAD = iOpen("EURCAD",PERIOD_M15,lookBack); double lookBackEURCHF = iOpen("EURCHF",PERIOD_M15,lookBack); double lookBackEURJPY = iOpen("EURJPY",PERIOD_M15,lookBack); //Gathers the GBP Symbol open values from the past double lookBackGBPAUD = iOpen("GBPAUD",PERIOD_M15,lookBack); double lookBackGBPNZD = iOpen("GBPNZD",PERIOD_M15,lookBack); double lookBackGBPUSD = iOpen("GBPUSD",PERIOD_M15,lookBack); double lookBackGBPCAD = iOpen("GBPCAD",PERIOD_M15,lookBack); double lookBackGBPCHF = iOpen("GBPCHF",PERIOD_M15,lookBack); double lookBackGBPJPY = iOpen("GBPJPY",PERIOD_M15,lookBack); //Gathers the AUD Symbol open values from the past double lookBackAUDNZD = iOpen("AUDNZD",PERIOD_M15,lookBack); double lookBackAUDUSD = iOpen("AUDUSD",PERIOD_M15,lookBack); double lookBackAUDCAD = iOpen("AUDCAD",PERIOD_M15,lookBack); double lookBackAUDCHF = iOpen("AUDCHF",PERIOD_M15,lookBack); double lookBackAUDJPY = iOpen("AUDJPY",PERIOD_M15,lookBack); //Gathers the NZD Symbol open values from the past double lookBackNZDUSD = iOpen("NZDUSD",PERIOD_M15,lookBack); double lookBackNZDCAD = iOpen("NZDCAD",PERIOD_M15,lookBack); double lookBackNZDCHF = iOpen("NZDCHF",PERIOD_M15,lookBack); double lookBackNZDJPY = iOpen("NZDJPY",PERIOD_M15,lookBack); //Gathers the USD Symbol open values from the past double lookBackUSDCAD = iOpen("USDCAD",PERIOD_M15,lookBack); double lookBackUSDCHF = iOpen("USDCHF",PERIOD_M15,lookBack); double lookBackUSDJPY = iOpen("USDJPY",PERIOD_M15,lookBack); //Gathers the CAD Symbol open values from the past double lookBackCADCHF = iOpen("CADCHF",PERIOD_M15,lookBack); double lookBackCADJPY = iOpen("CADJPY",PERIOD_M15,lookBack); //Gathers the CHF Symbol open values from the past double lookBackCHFJPY = iOpen("CHFJPY",PERIOD_M15,lookBack); //Gathers the current EUR Symbol Ask Values double EURGBP = SymbolInfoDouble("EURGBP", SYMBOL_ASK); double EURAUD = SymbolInfoDouble("EURAUD", SYMBOL_ASK); double EURNZD = SymbolInfoDouble("EURNZD", SYMBOL_ASK); double EURUSD = SymbolInfoDouble("EURUSD", SYMBOL_ASK); double EURCAD = SymbolInfoDouble("EURCAD", SYMBOL_ASK); double EURCHF = SymbolInfoDouble("EURCHF", SYMBOL_ASK); double EURJPY = SymbolInfoDouble("EURJPY", SYMBOL_ASK); //Gathers the current GBP Symbol Ask Values double GBPAUD = SymbolInfoDouble("GBPAUD", SYMBOL_ASK); double GBPNZD = SymbolInfoDouble("GBPNZD", SYMBOL_ASK); double GBPUSD = SymbolInfoDouble("GBPUSD", SYMBOL_ASK); double GBPCAD = SymbolInfoDouble("GBPCAD", SYMBOL_ASK); double GBPCHF = SymbolInfoDouble("GBPCHF", SYMBOL_ASK); double GBPJPY = SymbolInfoDouble("GBPJPY", SYMBOL_ASK); //Gathers the current AUD Symbol Ask Values double AUDNZD = SymbolInfoDouble("AUDNZD", SYMBOL_ASK); double AUDUSD = SymbolInfoDouble("AUDUSD", SYMBOL_ASK); double AUDCAD = SymbolInfoDouble("AUDCAD", SYMBOL_ASK); double AUDCHF = SymbolInfoDouble("AUDCHF", SYMBOL_ASK); double AUDJPY = SymbolInfoDouble("AUDJPY", SYMBOL_ASK); //Gathers the current NZD Symbol Ask Values double NZDUSD = SymbolInfoDouble("NZDUSD", SYMBOL_ASK); double NZDCAD = SymbolInfoDouble("NZDCAD", SYMBOL_ASK); double NZDCHF = SymbolInfoDouble("NZDCHF", SYMBOL_ASK); double NZDJPY = SymbolInfoDouble("NZDJPY", SYMBOL_ASK); //Gathers the current USD Symbol Ask Values double USDCAD = SymbolInfoDouble("USDCAD", SYMBOL_ASK); double USDCHF = SymbolInfoDouble("USDCHF", SYMBOL_ASK); double USDJPY = SymbolInfoDouble("USDJPY", SYMBOL_ASK); //Gathers the current CAD Symbol Ask Values double CADCHF = SymbolInfoDouble("CADCHF", SYMBOL_ASK); double CADJPY = SymbolInfoDouble("CADJPY", SYMBOL_ASK); //Gathers the current CHF Symbol Ask Values double CHFJPY = SymbolInfoDouble("CHFJPY", SYMBOL_ASK); //+------------------------------------------------------------------+ //| Calculates the percent of change over time | //+------------------------------------------------------------------+ //calculating the percent change from the past open till the current ask of the EUR values double perEURGBP = (EURGBP - lookBackEURGBP)/lookBackEURGBP*100; double perEURAUD = (EURAUD - lookBackEURAUD)/lookBackEURAUD*100; double perEURNZD = (EURNZD - lookBackEURNZD)/lookBackEURNZD*100; double perEURUSD = (EURUSD - lookBackEURUSD)/lookBackEURUSD*100; double perEURCAD = (EURCAD - lookBackEURCAD)/lookBackEURCAD*100; double perEURCHF = (EURCHF - lookBackEURCHF)/lookBackEURCHF*100; double perEURJPY = (EURJPY - lookBackEURJPY)/lookBackEURJPY*100; //calculating the percent change from the past open till the current ask of the GBP values double perGBPAUD = (GBPAUD - lookBackGBPAUD)/lookBackGBPAUD*100; double perGBPNZD = (GBPNZD - lookBackGBPNZD)/lookBackGBPNZD*100; double perGBPUSD = (GBPUSD - lookBackGBPUSD)/lookBackGBPUSD*100; double perGBPCAD = (GBPCAD - lookBackGBPCAD)/lookBackGBPCAD*100; double perGBPCHF = (GBPCHF - lookBackGBPCHF)/lookBackGBPCHF*100; double perGBPJPY = (GBPJPY - lookBackGBPJPY)/lookBackGBPJPY*100; //calculating the percent change from the past open till the current ask of the AUD values double perAUDNZD = (AUDNZD - lookBackAUDNZD)/lookBackAUDNZD*100; double perAUDUSD = (AUDUSD - lookBackAUDUSD)/lookBackAUDUSD*100; double perAUDCAD = (AUDCAD - lookBackAUDCAD)/lookBackAUDCAD*100; double perAUDCHF = (AUDCHF - lookBackAUDCHF)/lookBackAUDCHF*100; double perAUDJPY = (AUDJPY - lookBackAUDJPY)/lookBackAUDJPY*100; //calculating the percent change from the past open till the current ask of the NZD values double perNZDUSD = (NZDUSD - lookBackNZDUSD)/lookBackNZDUSD*100; double perNZDCAD = (NZDCAD - lookBackNZDCAD)/lookBackNZDCAD*100; double perNZDCHF = (NZDCHF - lookBackNZDCHF)/lookBackNZDCHF*100; double perNZDJPY = (NZDJPY - lookBackNZDJPY)/lookBackNZDJPY*100; //calculating the percent change from the past open till the current ask of the USD values double perUSDCAD = (USDCAD - lookBackUSDCAD)/lookBackUSDCAD*100; double perUSDCHF = (USDCHF - lookBackUSDCHF)/lookBackUSDCHF*100; double perUSDJPY = (USDJPY - lookBackUSDJPY)/lookBackUSDJPY*100; //calculating the percent change from the past open till the current ask of the CAD values double perCADCHF = (CADCHF - lookBackCADCHF)/lookBackCADCHF*100; double perCADJPY = (CADJPY - lookBackCADJPY)/lookBackCADJPY*100; //calculating the percent change from the past open till the current ask of the JPY values double perCHFJPY=(CHFJPY-lookBackCHFJPY)/lookBackCHFJPY*100; //Adds all the percentages from all the pairs together with thier respective pairs double perEUR = (perEURGBP + perEURAUD + perEURNZD + perEURUSD + perEURCAD + perEURCHF + perEURJPY); double perGBP = ((-perEURGBP) + perGBPAUD + perGBPNZD + perGBPUSD + perGBPCAD + perGBPCHF + perGBPJPY); double perAUD = (((-perEURAUD) + (-perGBPAUD)) + perAUDNZD + perAUDUSD + perAUDCAD + perAUDCHF + perAUDJPY); double perNZD = (((-perEURNZD) + (-perGBPNZD) + (-perAUDNZD)) + perNZDUSD + perNZDCAD + perNZDCHF + perNZDJPY); double perUSD = (((-perEURUSD) + (-perGBPUSD) + (-perAUDUSD) + (-perNZDUSD)) + perUSDCAD + perUSDCHF + perUSDJPY); double perCAD = (((-perEURCAD) + (-perGBPCAD) + (-perAUDCAD) + (-perNZDCAD) + (-perUSDCAD)) + perCADCHF + perCADJPY); double perCHF = (((-perEURCHF) + (-perGBPCHF) + (-perAUDCHF) + (-perNZDCHF) + (-perUSDCHF) + (-perCADCHF)) + perCHFJPY); double perJPY = ((-perEURJPY) + (-perGBPJPY) + (-perAUDJPY) + (-perNZDJPY) + (-perUSDJPY) + (-perCADJPY) + (-perCHFJPY)); //timeframe = 0; //numBars = 0; //barPriceBase = 0; //shift = 0; //+------------------------------------------------------------------+ //| Currently printing results to the experts log | //+------------------------------------------------------------------+ // // perEUR = NormalizeDouble(perEUR,2); // Print("rounded percent of the eur: ",perEUR); // perGBP = NormalizeDouble(perGBP,2); // Print("rounded percent of the gbp: ",perGBP); // perAUD = NormalizeDouble(perAUD,2); // Print("rounded percent of the aud: ",perAUD); // perNZD = NormalizeDouble(perNZD,2); // Print("rounded percent of the nzd: ",perNZD); // perUSD = NormalizeDouble(perUSD,2); // Print("rounded percent of the usd: ",perUSD); // perCAD = NormalizeDouble(perCAD,2); // Print("rounded percent of the cad: ",perCAD); // perCHF = NormalizeDouble(perCHF,2); // Print("rounded percent of the chf: ",perCHF); // perJPY = NormalizeDouble(perJPY,2); // Print("rounded percent of the jpy: ",perJPY); //This confirms the percentage math. "Correlation" this should most times be zero it will vary when price first shift // Print("Sum of all percent changes: ", perEUR + perGBP + perAUD + perNZD + perUSD + perCAD + perCHF + perJPY); //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping for EUR SetIndexBuffer (0, EUR_Band); SetIndexStyle (0, DRAW_LINE); SetIndexLabel (0, "EUR Band: "); //--- indicator buffers mapping for GBP SetIndexBuffer (1, GBP_Band); SetIndexStyle (1, DRAW_LINE); SetIndexLabel (1, "GBP Band: "); //--- indicator buffers mapping for AUD SetIndexBuffer (2, AUD_Band); SetIndexStyle (2, DRAW_LINE); SetIndexLabel (2, "AUD Band: "); //--- indicator buffers mapping for NZD SetIndexBuffer (3, NZD_Band); SetIndexStyle (3, DRAW_LINE); SetIndexLabel (3, "NZD Band: "); //--- indicator buffers mapping for USD SetIndexBuffer (4, USD_Band); SetIndexStyle (4, DRAW_LINE); SetIndexLabel (4, "USD Band: "); //--- indicator buffers mapping for CAD SetIndexBuffer (5, CAD_Band); SetIndexStyle (5, DRAW_LINE); SetIndexLabel (5, "CAD Band: "); //--- indicator buffers mapping for CHF SetIndexBuffer (6, CHF_Band); SetIndexStyle (6, DRAW_LINE); SetIndexLabel (6, "CHF Band: "); //--- indicator buffers mapping for JPY SetIndexBuffer (7, JPY_Band); SetIndexStyle (7, DRAW_LINE); SetIndexLabel (7, "JPY Band: "); //--- 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[]) { //Used with SimbolInfoTick to get the price at every tick //MqlTick last_tick; //int counted_bars = IndicatorCounted(); //int limit = Bars - counted_bars; //for(int i = 0; i < lookBack; i++) //{ // int counted_bars=IndicatorCounted(); //Drawing lines in a separate window // int i,// Bar index // Counted_bars; // Number of counted bars int Counted_bars = IndicatorCounted(); // Number of counted bars int limit = Bars - Counted_bars; // Index of the first uncounted for(int i = 0; i < limit; i++) { // //Indicator Lines EUR_Band[i] = iCSI(perEUR, PERIOD_M15, lookBack);//Clearly not functioning corrrectly //EUR_Band[i] = perEUR; //GBP_Band[i] = perGBP; //AUD_Band[i] = perAUD; //NZD_Band[i] = perNZD; //USD_Band[i] = perUSD; //CAD_Band[i] = perCAD; //CHF_Band[i] = perCHF; //JPY_Band[i] = perJPY; } return(rates_total); } //+------------------------------------------------------------------+
You are passing parameters to a function and then not using those parameters in calculation at all.
Do something that includes the passed parameters and then it will work
I'm sorry Mladen, I'm not following what you are saying. Do you mean that when I call the function that the original names of the parameters must be used?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
OK I have been at this now for over a week. I want to draw lines based on the value of perEUR for each candle in the past. The past will be adjustable so I set it as a variable called lookback. Everytime I think I figured out a new way to do it I get a new error. Can someone please guide in the right direction. I'm so new to programming I'm not even sure where to look for answers because I dont even know the right questions to ask. My current code is looking at all the candles because I'm not focused so much on the lookback part of it right now. I'm just trying to figure out how to get the lines to draw based on my custom values. The built in functions dont have the ability, that I'm aware of, to do what I need.
How do I fix this function and get rid of these errors. If I declare the variable outside of the function I get an error that says I'm changing a formal variable. If I dont declare it I get the error about variable not being declared.