Download MetaTrader 5
To add comments, please log in or register
Do you have idle PCs? Connect them to MQL5 Cloud Network and earn money!
B1-toan_49
9
B1-toan_49 2016.05.28 10:41 

The script don't run. Please help me

//+------------------------------------------------------------------+

//|                                           RSI3_CCI20_DEMA10c.mq4 |

//|                                                             Binh |

//|                                         tranvanbinhqcf@gmail.com |

//+------------------------------------------------------------------+

#property copyright "Binh"

#property link      "tranvanbinhqcf@gmail.com"

#property version   "1.00"

#property strict

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+


// External variables

extern double LotSize = 0.1;

extern double StopLoss = 5;

extern double TakeProfit = 10;


extern int RsiPeriod = 3;

extern int CciPeriod = 20;

extern int DemaPeriod = 10;


extern int Slippage = 0;

extern int MagicNumber = 123;




// Global variable

int BuyTicket; // remembered the global variable will be assigned by zero value if no other value is assgined with it

int SellTicket;

double UsePoint;

int UseSlippage;


int init()

  {

//---

    UsePoint = PipPoint(Symbol());

    UseSlippage = GetSlippage(Symbol(),Slippage);

//---

   return(0);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

int start()

  {

//---

     // Moving averages

     double Rsi3 = iRSI(NULL,0,RsiPeriod,0,0);

     double Cci20 = iCCI(NULL,0,CciPeriod,0,0);

     double Dema10c =iClose(NULL,0,0) - 2*iMA(NULL,0,DemaPeriod,0,1,0,0)+ iMA(NULL,0,DemaPeriod,1,iMA(NULL,0,DemaPeriod,0,1,0,0),0);

     

     

     // Buy order

     if(-200 < Cci20 && CCi20 < -125 && 23 < Rsi3 && Rsi3 < 35 && -95 < Dema10c && Dema10c < -80 && BuyTicket == 0)

        {

           OrderSelect(SellTicket,SELECT_BY_TICKET);

        

           // Close sell order

           if(OrderCloseTime() == 0 && SellTicket > 0)

              {

                 double CloseLots = OrderLots();

                 double ClosePrice = Ask;

                 bool Closed = OrderClose(SellTicket,CloseLots,ClosePrice,UseSlippage,Red);  

              }

           

           double OpenPrice = Ask;

           

           // Calculate stop loss and take profit

           if(StopLoss > 0) double BuyStopLoss = OpenPrice - (StopLoss*UsePoint);

           if(TakeProfit > 0) double BuyTakeProfit = OpenPrice + (TakeProfit*UsePoint);

           

           // Open Buy

           BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,UseSlippage,BuyStopLoss,BuyTakeProfit,"Buy Order",MagicNumber,0,Green);  

           

           SellTicket = 0;

        }

        

        // Sell order

     if(130 < Cci20 && Cci20 < 230 && 88 < Rsi3 && Rsi3 < 95 && 75 < Dema10c && Dema10c < 85 && SellTicket == 0)

        {

           OrderSelect(BuyTicket,SELECT_BY_TICKET);

           

           // Close buy order

           if(OrderCloseTime() == 0 && BuyTicket > 0)

              {

                 CloseLots = OrderLots();

                 ClosePrice = Bid;

                 

                 Closed = OrderClose(BuyTicket,CloseLots,ClosePrice,UseSlippage,Red); 

              }

              

           // Sell order

           OpenPrice = Bid;

           

           if(StopLoss > 0) double SellStopLoss = OpenPrice + (StopLoss*UsePoint);

           if(TakeProfit > 0) double SellTakeProfit = OpenPrice - (TakeProfit*UsePoint);

           

           SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,OpenPrice,UseSlippage,SellStopLoss,SellTakeProfit,"Sell Order",MagicNumber,0,Red);

           BuyTicket = 0; 

           

        }

     return(0);

  }

  

  //+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+


// PipPoint Function

double PipPoint(string Currency)

  {

     int CalcDigits = MarketInfo(Currency,MODE_DIGITS);

     if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;

     else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;

     return(CalcPoint);

  }


// Get Slippage Function

int GetSlippage(string Currency, int SlippagePips)

  {

//---

    int CalcDigits = MarketInfo(Currency,MODE_DIGITS);

    if(CalcDigits == 2 || CalcDigits == 4) double CalcSlippage = SlippagePips;

    else if(CalcSlippage == 3 || CalcSlippage == 5) CalcSlippage = SlippagePips*10;

    return(CalcSlippage); 

  }

//+------------------------------------------------------------------+ 

whroeder1
13610
whroeder1 2016.05.28 15:20  
B1-toan_49: The script don't run. Please help me
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. It's an EA not a script, (nor an indicator.)
  3. "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.
  4. Make up your mind. Your title says you can't compile, so of course "the script don't run." Your text says it doesn't run, do you even have a smiley face? There are no mind readers here.
  5. Check your return codes and find out why. Check your return codes (OrderSelect and OrderClose) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
/
To add comments, please log in or register