hi i need help for coding expert

 
Hey guys
I wrote an EXPERT but did not run correctly
Purchase and sale orders are not sent
I do not know where to use the double function to do the calculation

Please see the attachment
Thanks
Files:
34.PNG  59 kb
m14tdi2.mq4  10 kb
 
MOrizak4:
Hey guys
I wrote an EXPERT but did not run correctly
Purchase and sale orders are not sent
I do not know where to use the double function to do the calculation

Please see the attachment
Thanks

You need to break this whole chunk:

double hig0= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",0,0);
double hig1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",0,1);
double hig2= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",0,2);
double hig3= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",0,3);
double med0= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",1,0);
double med1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",1,1);
double med2= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",1,2);
double med3= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",1,3);
double low0= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",2,0);
double low1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",2,1);
double low2= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",2,2);
double low3= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",2,3);
double rsi0= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",3,0);
double rsi1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",3,1);
double rsi2= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",3,2);
double rsi3= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",3,3);
double sla0= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",4,0);
double sla1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",4,1);
double sla2= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",4,2);
double sla3= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",4,3);
double slb0= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",5,0);
double slb1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",5,1);
double slb2= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",5,2);
double slb3= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",5,3);
double RSIII0= iRSI  (NULL,PERIOD_CURRENT,10,PRICE_MEDIAN,0);
double RSIII1= iRSI  (NULL,PERIOD_CURRENT,10,PRICE_MEDIAN,1);
double RSIII2= iRSI  (NULL,PERIOD_CURRENT,10,PRICE_MEDIAN,2);   

into (1) declaration and (2) assignment/function calling parts. Declaration should look something like this:

double hig0,hig1,hig2,hig3,med0,med1,med2, etc....

and the rest should look something like this:

hig0= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",0,0);
hig1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",0,1);
        :
        :

Part (1) can remain where they are. But part (2) must be moved into your OnTick() function, before your if statement.

After you're done, run, test, and let us know if you need further help.

 
  1. MOrizak4: but did not run correctly
    "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here and our crystal balls are cracked.

  2. @Seng Joo Thio is correct but didn't explain why. Best practice is to put declarations as close to first usage as possible, (same line is best.) These variables must be global since they are use in multiple functions, but they can't be initialized there, (see № 3.)

  3. input int strattime=5;
    double hig0= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",0,0);
    double hig1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",0,1);
    Global and static variables work exactly the same way in MT4/MT5/C/C++.
    1. They are initialized once on program load.
    2. They don't update unless you assign to them.
    3. In C/C++ you can only initialize them with constants, and they default to zero.
    4. In MTx you should only initialize them with constants. There is no default in MT5 or (MT4 with strict which you should always use.)

      MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid. This includes calls to indicator data.
    5. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
                external static variable - Inflation - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. if(Volume[0]<=1 
    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              New candle - MQL4 and MetaTrader 4 - MQL4 programming forum

  5. Hour()<=23
    This is always true

 

You did not put the extern of the indicator, go and see information for ICustom

double sla1= iCustom (NULL,PERIOD_CURRENT,"Traders Dynamic Index",.... EXTERNS.......4,1);
Reason: