-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Messages Editor
Forum rules and recommendations - General - MQL5 programming forum (2023) -
nameMacd = ChartIndicatorName(0,3,0); nameMacdSignal = ChartIndicatorName(0,3,1);
Print your value or use the debugger and find out why. Do you really expect us to debug your code for you?
Code debugging - Developing programs - MetaEditor Help
Error Handling and Logging in MQL5 - MQL5 Articles (2015)
Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010) -
Do you really have two MACDs on the same subwindow?
- Where did you get the subwindow ID from?
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Messages Editor
Forum rules and recommendations - General - MQL5 programming forum (2023) -
Print your value or use the debugger and find out why. Do you really expect us to debug your code for you?
Code debugging - Developing programs - MetaEditor Help
Error Handling and Logging in MQL5 - MQL5 Articles (2015)
Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010) -
Do you really have two MACDs on the same subwindow?
- Where did you get the subwindow ID from?
no i have 1 macd on one window, but ther macd has the macd value and the signal value, i need them both for when the macd crosses the signal value. im trying to grab the signal but it wont.
Im following this tutorial: https://youtu.be/DMCYVVNKC4M?t=1224 and the subwindow is the window where the macd is on, so for me its 4 windows down making it 3.
- 2022.12.10
- www.youtube.com
You are probably confusing indicator handles with indicator buffers.
Here is a larger portion of the code, it doesn't make sense because i have basically copied the buffer and double code from the stochastic rsi area and it works but the macd doesn't. // ============ //variables bool IsDemo = true; CTrade trade; int TradesCurrentlyActive = 0; //stoch variables int handleStochasticMain; int handleStochasticSignal; string nameStochMain; string nameStochSignal; //williams variables int handleWilliams; string nameWilliams; //macd variables int handleMacd; int handleMacdSignal; string nameMacd; string nameMacdSignal; //================================== int OnInit(){ //set the starting handle value for stoch nameStochMain = ChartIndicatorName(0,1,0); nameStochSignal = ChartIndicatorName(0,1,1); handleStochasticMain = ChartIndicatorGet(0,1,nameStochMain); handleStochasticSignal = ChartIndicatorGet(0,1,nameStochSignal); //set the willams percentage handle nameWilliams = ChartIndicatorName(0,2,0); handleWilliams = ChartIndicatorGet(0,2,nameWilliams); //set the Macd handle nameMacd = ChartIndicatorName(0,3,0); nameMacdSignal = ChartIndicatorName(0,3,1); handleMacd = ChartIndicatorGet(0,3,nameMacd); handleMacdSignal = ChartIndicatorGet(0,3,nameMacdSignal); if(handleMacdSignal == INVALID_HANDLE) Print(__FUNCTION__," Macd Signal handle is invalid."); return(INIT_PARAMETERS_INCORRECT); //this code is to make sure the program is not active on a real account just to be safe if (!IsDemo) return (INIT_FAILED); int result = ValidateInputs(); if (result != INIT_SUCCEEDED){ return (result);}; return(INIT_SUCCEEDED); } //======================================== void OnTick() { //arrays to hold stochastic data double stochasticMain[]; double stochasticSignal[]; //stochastic rsi data fetch CopyBuffer(handleStochasticMain,0,0,StochLookBackPeriodsUnder20,stochasticMain); CopyBuffer(handleStochasticSignal,1,0,StochLookBackPeriodsUnder20,stochasticSignal); Comment("Stochastic Main: ",stochasticMain[0]); Comment("Stochastic Signal: ",stochasticSignal[0]); //array to hold williams data double williamsMain[]; //williams data fetch CopyBuffer(handleWilliams,0,0,WilliamsLookBackPeriodForUnder20,williamsMain); Comment("Williams: ",williamsMain[0]); //array to hold Macd data double macdMain[]; double macdSignalList[]; //macd data fetch CopyBuffer(handleMacd,0,0,MacdLookBackPeriod,macdMain); CopyBuffer(handleMacdSignal,1,0,MacdLookBackPeriod,macdSignalList); Comment("Macd: ",macdMain[0]); Comment("Macd signal: ",macdSignalList[0]);
Name stoch main: Stoch(5,3,3), Name stoch Signal: , Handle Stoch main: 10, Handle stoch signal: -1
It looks like the stoch signal doesn't have a name also but it has a value of -1, I tried it again and got the same results over and over, does that mean that im doing something wrong, because i can tell that the stoch values are much different. whats going on here
Wait, when i run the code i displayed the values for the stoch names as i wasnt having any issues with stoch so i figured its working and i get this:
It looks like the stoch signal doesn't have a name also but it has a value of -1, I tried it again and got the same results over and over, does that mean that im doing something wrong, because i can tell that the stoch values are much different. whats going on here
Why are you using such approach instead of the classic usage of iCustom (or iMACD, iStoch...) ? If you want to see the indicators started with iCustom, use ChartIndicatorAdd().
Even if you have a solid rationale to use this approach, you should apply it correctly and understand how indicator's shortname, handle, window and buffers are working. As already noticed by Fabio you are mixing all.
Also, you should not hardcode any window index.
Why are you using such approach instead of the classic usage of iCustom (or iMACD, iStoch...) ? If you want to see the indicators started with iCustom, use ChartIndicatorAdd().
Even if you have a solid rationale to use this approach, you should apply it correctly and understand how indicator's shortname, handle, window and buffers are working. As already noticed by Fabio you are mixing all.
Also, you should not hardcode any window
ok thanks for the advice, im quite new to metatrader so i didnt know imacd was a thing. cheers
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hey so I'm having a problem with ChartIndicatorName, im trying to get the macd Signal name and handle. Here is my code, when i compile it it's good, but when i place it in a chart i get the invalid handle issue. Much appreciation to anyone that helps :)
//set the Macd handle
nameMacd = ChartIndicatorName(0,3,0);
nameMacdSignal = ChartIndicatorName(0,3,1);
handleMacd = ChartIndicatorGet(0,3,nameMacd);
handleMacdSignal = ChartIndicatorGet(0,3,nameMacdSignal);
if(handleMacdSignal == INVALID_HANDLE) Print(__FUNCTION__," Macd Signal handle is invalid.");
return(INIT_PARAMETERS_INCORRECT);