add magic number for all the timeframes to this ea (also see id in toolbox)
Why do you need your own Magic Number for each timeframe?
(I combed your code, but it contains structural errors)
//+------------------------------------------------------------------+ //| macd-neuro-example.mq5 | //| Copyright 2012, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2012, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" //--- #include <Trade\PositionInfo.mqh> #include <Trade\Trade.mqh> //--- CPositionInfo m_position; // object of CPositionInfo class CTrade m_trade; // object of CTrade class //--- weight values input double w0=0.5; input double w1=0.5; input double w2=0.5; input double w3=0.5; input double w4=0.5; input double w5=0.5; input double w6=0.5; input double w7=0.5; input double w8=0.5; input double w9=0.5; input double w10=0.5; input double w11=0.5; input double w12=0.5; input double w13=0.5; input double w14=0.5; input double w15=0.5; input double w16=0.5; input double w17=0.5; input double w18=0.5; input double w19=0.5; input double lot_size = 0.2; // lot size input ulong InpMagic = 200; // Magic number //--- double out; // variable for storing the output neuron value int handle_iMACD; // variable for storing the handle of the iMACD indicator double iMACD_mainbuf[]; // dynamic array for storing indicator values double iMACD_signalbuf[]; // dynamic array for storing indicator values double inputs[20]; // array for storing inputs double weight[20]; // array for storing weights //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create handle of the indicator iMACD handle_iMACD=iMACD(Symbol(),Period(),12,26,9,PRICE_CLOSE); //--- if the handle is not created if(handle_iMACD==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iMACD indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- add the indicator to the price chart ChartIndicatorAdd(0,0,handle_iMACD); //--- set the iMACD_mainbuf array indexing as time series ArraySetAsSeries(iMACD_mainbuf,true); //--- set the iMACD_signalbuf array indexing as time series ArraySetAsSeries(iMACD_signalbuf,true); //--- place weights into the array weight[0]=w0; weight[1]=w1; weight[2]=w2; weight[3]=w3; weight[4]=w4; weight[5]=w5; weight[6]=w6; weight[7]=w7; weight[8]=w8; weight[9]=w9; weight[10]=w10; weight[11]=w11; weight[12]=w12; weight[13]=w13; weight[14]=w14; weight[15]=w15; weight[16]=w16; weight[17]=w17; weight[18]=w18; weight[19]=w19; //--- return 0, initialization complete return(0); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- delete the indicator handle and deallocate the memory space it occupies IndicatorRelease(handle_iMACD); //--- free the iMACD_mainbuf dynamic array of data ArrayFree(iMACD_mainbuf); //--- free the iMACD_signalbuf dynamic array of data ArrayFree(iMACD_signalbuf); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int err1=0; // variable for storing the results of working with the main buffer of the MACD indicator int err2=0; // variable for storing the results of working with the signal buffer of the MACD indicator //--- copy data from the indicator array to the iMACD_mainbuf dynamic array for further work with them err1=CopyBuffer(handle_iMACD,0,2,ArraySize(inputs)/2,iMACD_mainbuf); //--- copy data from the indicator array to the iMACD_signalbuf dynamic array for further work with them err2=CopyBuffer(handle_iMACD,1,2,ArraySize(inputs)/2,iMACD_signalbuf); //--- in case of errors, print the relevant error message into the log file and exit the function if(err1<0 || err2<0) { Print("Failed to copy data from the indicator buffer"); return; } double d1=-1.0; //lower limit of the normalization range double d2=1.0; //upper limit of the normalization range //--- minimum value over the range double x_min=MathMin(iMACD_mainbuf[ArrayMinimum(iMACD_mainbuf)],iMACD_signalbuf[ArrayMinimum(iMACD_signalbuf)]); //--- maximum value over the range double x_max=MathMax(iMACD_mainbuf[ArrayMaximum(iMACD_mainbuf)],iMACD_signalbuf[ArrayMaximum(iMACD_signalbuf)]); //--- In the loop, fill in the array of inputs with the pre-normalized indicator values for(int i=0; i<ArraySize(inputs)/2; i++) { inputs[i*2]=(((iMACD_mainbuf[i]-x_min)*(d2-d1))/(x_max-x_min))+d1; inputs[i*2+1]=(((iMACD_signalbuf[i]-x_min)*(d2-d1))/(x_max-x_min))+d1; } //--- store the neuron calculation result in the out variable out=CalculateNeuron(inputs,weight); //--- if the output value of the neuron is less than 0 if(out<0) { //--- if the position for this symbol already exists if(m_position.Select(Symbol())) { //--- and this is a Sell position, then close it if(m_position.PositionType()==POSITION_TYPE_SELL) m_trade.PositionClose(Symbol()); //--- or else, if this is a Buy position, then exit if(m_position.PositionType()==POSITION_TYPE_BUY) return; } //--- if we got here, it means there is no position; then we open it m_trade.Buy(lot_size,Symbol()); } //--- if the output value of the neuron is equal to or greater than 0 if(out>=0) { //--- if the position for this symbol already exists if(m_position.Select(Symbol())) { //--- and this is a Buy position, then close it if(m_position.PositionType()==POSITION_TYPE_BUY) m_trade.PositionClose(Symbol()); //--- or else, if this is a Sell position, then exit if(m_position.PositionType()==POSITION_TYPE_SELL) return; } //--- if we got here, it means there is no position; then we open it m_trade.Sell(lot_size,Symbol()); } } //+------------------------------------------------------------------+ //| Neuron calculation function | //+------------------------------------------------------------------+ double CalculateNeuron(double &x[],double &w[]) { //--- variable for storing the weighted sum of inputs double NET=0.0; //--- Using a loop we obtain the weighted sum of inputs based on the number of inputs for(int n=0; n<ArraySize(x); n++) { NET+=x[n]*w[n]; } //--- multiply the weighted sum of inputs by the additional coefficient NET*=0.1; //--- send the weighted sum of inputs to the activation function and return its value return(ActivateNeuron(NET)); } //+------------------------------------------------------------------+ //| Activation function | //+------------------------------------------------------------------+ double ActivateNeuron(double x) { //--- variable for storing the activation function results double Out; //--- hyperbolic tangent function Out=(exp(x)-exp(-x))/(exp(x)+exp(-x)); //--- return the activation function value return(Out); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+
-
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help 2017.04.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12 -
You posted code that generates the magic number. Show us where you use it, on opening, and during trade management. Help you with what?
- We aren't going to "correct your EA."
- MT4: Learn to code it.
MT5: Begin learning to code it.
If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code. -
or pay (Freelance) someone to code it. Top of every page is the link Code Base.
Hiring to write script - General - MQL5 programming forum 2019.08.21
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
No free help 2017.04.21 - MT4: Learn to code it.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi, please I need help with this, I whant to add a magic number for all the timeframes in the pair, so I have at the same time the pair opened in diferent timeframes
please correct this EA: