Need help with code
Results 1 to 3 of 3

Thread: Need help with code

  1. #1
    Hi all. I would like help with the code. It's a moving average cross alert that I added an alert and bought a little. Whether the email alert will work because I keep getting 1 error when I compile I am not positive. I have pasted the code below

    I have gone through the code a few times and I can't seem to pinpoint the issue. Thanks for your help in advance.

    The error says ... '\end_of_program' - unbalanced left parenthesis



    // ------------------------------------------------------------------
    //| MACrossEarlyAlert.mq4 |
    //| Mariano Silva |
    //| |
    // ------------------------------------------------------------------
    #property copyright Mariano Silva
    #property link

    #property indior_chart_window
    //-- input parameters
    extern bool EmailAlert = false;
    extern int FastMAPeriod=50;
    extern string Type=0-SMA, 1-EMA;
    extern int FastMAType=1;
    extern int SlowMAPeriod=1;
    extern int SlowMAType=0;
    extern int EarlyPips=15;
    extern int ResetAlert=20;
    extern color LineColor=Orange;
    // ------------------------------------------------------------------
    //| Custom indior initialization function |
    // ------------------------------------------------------------------
    int init()

    //-- indiors
    //--
    return(0);

    // ------------------------------------------------------------------
    //| Custom indior deinitialization function |
    // ------------------------------------------------------------------
    int deinit()

    string LineName;
    //--
    LineName=StringConenate(FastMAPeriod,/,SlowMAPeriod, MA Cross);
    ObjectDelete(LineName);
    //--
    return(0);

    // ------------------------------------------------------------------
    //| Custom indior iteration function |
    // ------------------------------------------------------------------
    int start()

    // int counted_bars=IndiorCounted();

    double FastMALastBar, SlowMALastBar, PriceToCross, Cross, FastMATest, SlowMATest;
    bool AlertEnabled=true;
    string LineName=StringConenate(FastMAPeriod,/,SlowMAPeriod, MA Cross);


    // LineName=StringConenate(FastMAPeriod,/,SlowMAPeriod, MA Cross);

    //--

    if(NewBar())

    FastMALastBar=iMA(NULL,0,FastMAPeriod,0,FastMAType ,PRICE_CLOSE,1);
    SlowMALastBar=iMA(NULL,0,SlowMAPeriod,0,SlowMAType ,PRICE_CLOSE,1);
    PriceToCross=Open[0];
    Cross=FastMALastBar-SlowMALastBar;


    if(Crossgt;0.0)

    while(Crossgt;0.0)

    PriceToCross=PriceToCross-Point;
    FastMATest=CalcMA(FastMAPeriod,FastMAType,PriceToC ross,FastMALastBar);
    SlowMATest=CalcMA(SlowMAPeriod,SlowMAType,PriceToC ross,SlowMALastBar);
    Cross=FastMATest-SlowMATest;


    else

    while(Crosslt;0.0)

    PriceToCross=PriceToCross Point;
    FastMATest=CalcMA(FastMAPeriod,FastMAType,PriceToC ross,FastMALastBar);
    SlowMATest=CalcMA(SlowMAPeriod,SlowMAType,PriceToC ross,SlowMALastBar);
    Cross=FastMATest-SlowMATest;




    ObjectDelete(LineName);
    drawLine(PriceToCross,LineName,LineColor,0);



    if(AlertEnabled)

    if(MathAbs(Close[0]-PriceToCross)lt;=EarlyPips*Point)

    Alert(Close to ,FastMAPeriod,/,SlowMAPeriod, MA Cross on ,Symbol(), ,Period());

    if EmailAlert SendMail(Close to ,FastMAPeriod,/,SlowMAPeriod, MA Cross on ,Symbol(), ,Period();

    AlertEnabled=false;


    else

    if(MathAbs(Close[0]-PriceToCross)gt;=ResetAlert*Point)

    AlertEnabled=true;







    //--
    return(0);

    // ------------------------------------------------------------------


    double CalcMA(int MAPeriod, int MAType, double PriceTest, double LastMA)

    double MA, pr;

    switch(MAType)

    case 0:

    MA=-LRB-(LastMA*MAPeriod)-Close[MAPeriod] PriceTest)/MAPeriod;
    break;

    case 1:

    pr=2.0/(MAPeriod 1);
    MA=PriceTest*pr LastMA*(1-pr);
    break;



    return(MA);


    void drawLine(double lvl,string name, color Col,int type)

    ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl);//,Time[0],lvl);

    if(type == 1)
    ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
    else
    ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);

    ObjectSet(name, OBJPROP_COLOR, Col);
    ObjectSet(name,OBJPROP_WIDTH,1);

    return;



    bool NewBar()
    static datetime lastbar;
    datetime curbar = Time[0];
    if(lastbar! =curbar)

    lastbar=curbar;
    return (true);

    else
    return(false);

  2. #2
    Simply post the MQL document... nobody likes reading this to the ribbon without a compiler...

  3. #3
    Thank you for your answer Rbi. I have attached an MQL file of the code under. I want the indior to fire off an alert and send me an email one time only, if price stems to within 15 pips of 34EMA/8EMA crossover. The status should then flashed after price moves a specified no. Of pips (in this case 20 pips) from 34EMA/8EMA Cross. I Tried tweaking the code and now I get 3 errors:

    ')' - incorrect parameters depend

    'else' - unexpected token

    'MAType' - inner mistake

    Any Help will be greatly valued.

    Thanks
    https://www.forexforum.co.za/attachm...2240799907.mq4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.