I edited your improperly formatted code, but I'm not a Python programmer so please check it.
Please, always use the CODE button (Alt-S) when inserting code.
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
//+------------------------------------------------------------------+ //| SMABot.mq5 | //| Copyright MetaQuotes Ltd. | //| https://www.mql5.com/en/users/metaquotes | //+------------------------------------------------------------------+ #property copyright "Copyright MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 clrRed #property indicator_color2 clrGreen #property indicator_color3 clrBlue #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 //--- indicator buffers double SMA7Buffer[]; double SMA14Buffer[]; double SMA28Buffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0, SMA7Buffer); SetIndexBuffer(1, SMA14Buffer); SetIndexBuffer(2, SMA28Buffer); //--- set plot styles using PlotIndexSetInteger PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_LINE); PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 1); // Line width for SMA7 PlotIndexSetInteger(1, PLOT_LINE_WIDTH, 1); // Line width for SMA14 PlotIndexSetInteger(2, PLOT_LINE_WIDTH, 1); // Line width for SMA28 //--- set index labels IndicatorSetString(INDICATOR_SHORTNAME, "SMA 7, 14, 28"); PlotIndexSetString(0, PLOT_LABEL, "SMA7"); PlotIndexSetString(1, PLOT_LABEL, "SMA14"); PlotIndexSetString(2, PLOT_LABEL, "SMA28"); 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[]) { // Loop through each bar to calculate SMAs for(int i = 0; i < rates_total; i++) { // Calculate SMA7 for the i-th bar SMA7Buffer[i] = iMA(_Symbol, _Period, 7, 0, MODE_SMA, PRICE_CLOSE); // Calculate SMA14 for the i-th bar SMA14Buffer[i] = iMA(_Symbol, _Period, 14, 0, MODE_SMA, PRICE_CLOSE); // Calculate SMA28 for the i-th bar SMA28Buffer[i] = iMA(_Symbol, _Period, 28, 0, MODE_SMA, PRICE_CLOSE); } return(rates_total); }hi again, I was not able to find a solution to my previous problem, so here is a new problem that I am getting, I want to plot 3 SMA, 7, 14, 28, I am not getting any compiling errors, but I cannot for the life of me see the values or the lines on the chart, the value just reads 10 for the SMA7, any help would be greatly appreciated, thank you.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi guys,
Thank you in advance for your time and effort.
I am very new to MT5/MQL5 and Python, trying to migrate from Pinescript to MT5 using Python for Auto-trading. I dont have much coding knowledge. Been using internet resources and some ChatGPT.
I have come across a problem which i need help.
Given my below code I cant seem to fetch the 3 Min required data, what am i missing?
I am using the Anaconda Environment with the Jupyter Notebook
I have pip installed MetaTrade5
Thank you for your help!
Improperly formatted code edited by moderator.