FXOpen Broker

10+ years’
experience in FX

VISIT WEBSITE

Trading Accounts

ECN, STP,
Micro, Crypto

START TRADING

Try Free Demo

Practice Forex trading
risk free

OPEN DEMO ACCOUNT

PAMM Technology

Become a Master
or a Follower

JOIN PAMM SERVICE
Page 5 of 5 FirstFirst 12345
Results 61 to 71 of 71

Thread: Tips for use Expert Advisors

  1. #61
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    class CSampleExpert
    {
    protected:
    double m_adjusted_point; // point value adjusted for 3 or 5 points
    CTrade m_trade; // trading object
    CSymbolInfo m_symbol; // symbol info object
    CPositionInfo m_position; // trade position object
    CAccountInfo m_account; // account info wrapper
    //--- indicators
    int m_handle_macd; // MACD indicator handle
    int m_handle_ema; // moving average indicator handle
    //--- indicator buffers
    double m_buff_MACD_main[]; // MACD indicator main buffer
    double m_buff_MACD_signal[]; // MACD indicator signal buffer
    double m_buff_EMA[]; // EMA indicator buffer
    //--- indicator data for processing
    double m_macd_current;
    double m_macd_previous;
    double m_signal_current;
    double m_signal_previous;
    double m_ema_current;
    double m_ema_previous;
    //---
    double m_macd_open_level;
    double m_macd_close_level;
    double m_traling_stop;
    double m_take_profit;

    public:
    CSampleExpert(void);
    ~CSampleExpert(void);
    bool Init(void);
    void Deinit(void);
    bool Processing(void);

  2. #62
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    protected:
    bool InitCheckParameters(const int digits_adjust);
    bool InitIndicators(void);
    bool LongClosed(void);
    bool ShortClosed(void);
    bool LongModified(void);
    bool ShortModified(void);
    bool LongOpened(void);
    bool ShortOpened(void);
    };
    //--- global expert
    CSampleExpert ExtExpert;
    //+------------------------------------------------------------------+
    //| Constructor |
    //+------------------------------------------------------------------+
    CSampleExpert::CSampleExpert(void) : m_adjusted_point(0),
    m_handle_macd(INVALID_HANDLE),
    m_handle_ema(INVALID_HANDLE),
    m_macd_current(0),
    m_macd_previous(0),
    m_signal_current(0),
    m_signal_previous(0),
    m_ema_current(0),
    m_ema_previous(0),
    m_macd_open_level(0),
    m_macd_close_level(0),
    m_traling_stop(0),
    m_take_profit(0)
    {
    ArraySetAsSeries(m_buff_MACD_main,true);
    ArraySetAsSeries(m_buff_MACD_signal,true);
    ArraySetAsSeries(m_buff_EMA,true);
    }

  3. #63
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    williambau part-1

    #property copyright
    #property link
    //+------------------------------------------------------------------+
    //| Exponential moving average on price array |
    //+------------------------------------------------------------------+
    int ExponentialMAOnBufferWB(const int rates_total,const int prev_calculated,const int begin,
    const int period,const double& price[],double& buffer[])
    {
    int i,limit;
    //--- check for data
    //if(period<=1 || rates_total-begin<period) return(0);
    if(period<1 || rates_total-begin<period) return(0);
    double dSmoothFactor=2.0/(1.0+period);
    //--- save as_series flags
    bool as_series_price=ArrayGetAsSeries(price);
    bool as_series_buffer=ArrayGetAsSeries(buffer);
    if(as_series_price) ArraySetAsSeries(price,false);
    if(as_series_buffer) ArraySetAsSeries(buffer,false);
    //--- first calculation or number of bars was changed
    if(prev_calculated==0)
    {
    limit=period+begin;
    //--- set empty value for first bars
    for(i=0;i<begin;i++) buffer[i]=0.0;
    //--- calculate first visible value
    buffer[begin]=price[begin];
    for(i=begin+1;i<limit;i++)
    buffer[i]=price[i]*dSmoothFactor+buffer[i-1]*(1.0-dSmoothFactor);
    }
    else limit=prev_calculated-1;
    //--- main loop
    for(i=limit;i<rates_total;i++)
    buffer[i]=price[i]*dSmoothFactor+buffer[i-1]*(1.0-dSmoothFactor);
    //--- restore as_series flags
    if(as_series_price) ArraySetAsSeries(price,true);
    if(as_series_buffer) ArraySetAsSeries(buffer,true);
    //---
    return(rates_total);
    }

  4. #64
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    #property copyright
    #property link
    #property description "Ergodic Oscillator (William Blau)" // description
    #include <WilliamBlau.mqh> // include file (terminal_data_folder\MQL5\Include)
    //--- indicator settings
    #property indicator_separate_window // indicator in a separate window
    #property indicator_buffers 11 // number of buffers
    #property indicator_plots 2 // indicator plots
    //--- horizontal levels
    #property indicator_level1 -25 // level #0
    #property indicator_level2 25 // level #1
    #property indicator_levelcolor Silver // level color
    #property indicator_levelstyle STYLE_DOT // level style
    #property indicator_levelwidth 1 // level width
    //--- min/max
    #property indicator_minimum -100 // minimum
    #property indicator_maximum 100 // maximum
    //--- graphic plot #0 (Main)
    #property indicator_label1 "Ergodic" // graphic plot #0
    #property indicator_type1 DRAW_HISTOGRAM // draw as a histogram
    #property indicator_color1 Silver // histogram color
    #property indicator_style1 STYLE_SOLID // line style
    #property indicator_width1 2 // line width
    //--- graphic plot #1 (Signal Line)
    #property indicator_label2 "Signal" // graphic plot #1
    #property indicator_type2 DRAW_LINE // draw as a line
    #property indicator_color2 Red // line color
    #property indicator_style2 STYLE_SOLID // line style
    #property indicator_width2 1 // line width
    //--- input parameters

  5. #65
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    100 * EMA(EMA(EMA( mtm(price,q) ,r),s),u) 100 * Mtm(price,q,r,s,u)
    TSI(price,q,r,s,u) = –––––––––––––––––––––––––------–––––––––– = ––––––––––––––––------–––––––––––––––
    EMA(EMA(EMA( |mtm(price,q)| ,r),s),u) EMA(EMA(EMA( |mtm(price,q)| ,r),s),u)

  6. #66
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ergodic Oscillator part-II

    input int q=2; // q - period of Momentum
    input int r=20; // r - 1st EMA, applied to Momentum
    input int s=5; // s - 2nd EMA, applied to the 1st smoothing
    input int u=3; // u - 3rd EMA, applied to the 2nd smoothing
    input int ul=3; // ul - period of a Signal Line
    //--- dynamic arrays
    double MainBuffer[]; // Egrodic Line (graphic plot #0)
    double SignalBuffer[]; // Signal Line: EMA(ul), applied to Ergodic Line (graphic plot #1)
    double HMUBuffer[]; // q-period Up Trend Momentum
    double LMDBuffer[]; // q-period Down Trend Momentum
    double HLMBuffer[]; // Composite High/Low Momentum
    double EMA_HLMBuffer[]; // r-period 1st EMA
    double DEMA_HLMBuffer[]; // s-period 2nd EMA
    double TEMA_HLMBuffer[]; // u-period 3rd EMA
    double AbsHLMBuffer[]; // Composite High/Low Momemtum (absolute values)
    double EMA_AbsHLMBuffer[]; // r-period 1st EMA (absolute values)
    double DEMA_AbsHLMBuffer[]; // s-period 2nd EMA (absolute values)
    double TEMA_AbsHLMBuffer[]; // u-period 3rd EMA (absolute values)
    //--- global variables
    int begin1, begin2, begin3, begin4, begin5; // starting bar index
    int rates_total_min; // rates total min
    //+------------------------------------------------------------------+
    //| Custom indicator initialization function |
    //+------------------------------------------------------------------+
    int OnInit()
    {
    //--- indicator buffers
    // graphic plot #0
    SetIndexBuffer(0,MainBuffer,INDICATOR_DATA); // Ergodic Line
    // graphic plot #1
    SetIndexBuffer(1,SignalBuffer,INDICATOR_DATA); // Signal Line: EMA(ul), applied to Ergodic
    // buffers, used for intermediate calculations
    SetIndexBuffer(2,HMUBuffer,INDICATOR_CALCULATIONS); // q-period Up Trend Momentum
    SetIndexBuffer(3,LMDBuffer,INDICATOR_CALCULATIONS); // q-period Down Trend Momentum
    SetIndexBuffer(4,HLMBuffer,INDICATOR_CALCULATIONS); // Composite q-period High/Low Momentum
    SetIndexBuffer(5,EMA_HLMBuffer,INDICATOR_CALCULATIONS); // r-period 1st EMA
    SetIndexBuffer(6,DEMA_HLMBuffer,INDICATOR_CALCULATIONS); // s-period 2nd EMA
    SetIndexBuffer(7,TEMA_HLMBuffer,INDICATOR_CALCULATIONS); // u-period 3rd EMA
    SetIndexBuffer(8,AbsHLMBuffer,INDICATOR_CALCULATIONS); // Composite q-period High/Low Momentum (absolute values)
    SetIndexBuffer(9,EMA_AbsHLMBuffer,INDICATOR_CALCULATIONS); // r-period 1st EMA (absolute values)
    SetIndexBuffer(10,DEMA_AbsHLMBuffer,INDICATOR_CALCULATIONS); // s-period 2nd EMA (absolute values)
    SetIndexBuffer(11,TEMA_AbsHLMBuffer,INDICATOR_CALCULATIONS); // u-period 3rd EMA (absolute values)
    /*

  7. #67
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    //--- graphic plot #0 (Main)
    PlotIndexSetString(0,PLOT_LABEL,"Ergodic"); // label of graphic plot #0
    PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_HISTOGRAM); // draw as a histogram
    PlotIndexSetInteger(0,PLOT_LINE_COLOR,Silver); // histogram color
    PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID); // histogram style
    PlotIndexSetInteger(0,PLOT_LINE_WIDTH,2); // histogram line width
    //--- graphic plot #1 (Signal Line)
    PlotIndexSetString(1,PLOT_LABEL,"Signal"); // label of graphic plot #1
    PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE); // draw as a line
    PlotIndexSetInteger(1,PLOT_LINE_COLOR,Red); // line color
    PlotIndexSetInteger(1,PLOT_LINE_STYLE,STYLE_SOLID); // line style
    PlotIndexSetInteger(1,PLOT_LINE_WIDTH,1); // line width
    */
    //--- precision
    IndicatorSetInteger(INDICATOR_DIGITS,2);
    /*
    //--- horizontal levels
    IndicatorSetInteger(INDICATOR_LEVELS,2); // number of levels
    IndicatorSetDouble(INDICATOR_LEVELVALUE,0,-25); // level #0
    IndicatorSetDouble(INDICATOR_LEVELVALUE,1,25); // level #1
    IndicatorSetInteger(INDICATOR_LEVELCOLOR,Silver); // level line color
    IndicatorSetInteger(INDICATOR_LEVELSTYLE,STYLE_DOT); // level line style
    IndicatorSetInteger(INDICATOR_LEVELWIDTH,1); // level line width
    IndicatorSetString(INDICATOR_LEVELTEXT,0,"Oversold"); // description of level #0 "Oversold"
    IndicatorSetString(INDICATOR_LEVELTEXT,1,"Overbought"); // description of level #1 "Overbought"
    //--- scale
    IndicatorSetDouble(INDICATOR_MINIMUM,-100); // lower bound
    IndicatorSetDouble(INDICATOR_MAXIMUM,100); // upper bound
    */
    //---
    begin1=q-1; // - HLMBuffer[], AbsHLMBuffer[], HMUBuffer[], LMDBuffer[]
    begin2=begin1+r-1; // or =(q-1)+(r-1) - EMA_...[]
    begin3=begin2+s-1; // or =(q-1)+(r-1)+(s-1) - DEMA_...[]
    begin4=begin3+u-1; // or =(q-1)+(r-1)+(s-1)+(u-1) - TEMA_...[], MainBuffer[]
    begin5=begin4+ul-1; // or =(q-1)+(r-1)+(s-1)+(u-1)+(ul-1) - SignalBuffer[]
    //
    rates_total_min=begin5+1; // rates total min
    //--- starting bar index for graphic plot #0
    PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,begin4);
    //--- starting bar index for graphic plot #1
    PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,begin5);
    //--- indicator short name
    string shortname=string(q)+","+string(r)+","+string(s)+","+string(u)+","+string(ul);
    IndicatorSetString(INDICATOR_SHORTNAME,"Blau_Ergodic_DTI("+shortname+")");
    //--- OnInit done
    return(0);
    }

  8. #68
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    D lines part-1


    #property copyright
    #property link ""
    #property version "1.00"
    #property strict
    #property indicator_chart_window

    input int MaxBarsToLookBackForSeparators=0;
    input string LookToAllBars="Input 0";
    //--- Colors each day
    input color Sunday = Red;
    input color Monday = Blue;
    input color Tuesday= Blue;
    input color Wednesday= Blue;
    input color Thursday = Blue;
    input color Friday=Blue;
    input color Saturday=Blue;
    //--- input parameters for style the day line
    input ENUM_LINE_STYLE InpStyle=STYLE_DASHDOTDOT; // Line style
    input int InpWidth=1; // Line width
    //--- input distance text from top of the chart
    input double textplace=30;
    input string InpFont="Arial"; // Font
    input int InpFontSize=8; // Font size
    input ENUM_ANCHOR_POINT InpAnchor=ANCHOR_BOTTOM; // Anchor type

    double textprice,newtextprice,
    max_price,min_price;
    string thisday="";
    string daycheck1="",daycheck2="";
    //+------------------------------------------------------------------+
    //| Custom indicator initialization function |
    //+------------------------------------------------------------------+
    int OnInit()
    {
    //Set Timer
    EventSetMillisecondTimer(250);
    //--- find the highest and lowest values of the chart then calculate textposition
    max_price=ChartGetDouble(0,CHART_PRICE_MAX);
    min_price=ChartGetDouble(0,CHART_PRICE_MIN);
    int heightinpixels=ChartHeightInPixelsGet(0,0);
    textprice=max_price-((max_price-min_price)*(textplace/heightinpixels));
    return(INIT_SUCCEEDED);
    }
    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
    {
    int i2;
    int obj_total=ObjectsTotal(0,-1,-1);
    for(i2=obj_total; i2>=0; i2--)
    {
    string name=ObjectName(0,i2,-1,-1);
    if(StringSubstr(name,0,14)=="NewTradingDay ") {TrendDelete(0,name);}
    if(StringSubstr(name,0,8)=="DayText ") {TextDelete(0,name);}
    }
    //--- destroy timer
    EventKillTimer();
    }

  9. #69
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    D lines part-2

    //+------------------------------------------------------------------+
    //| 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[])
    {

    //---
    int i1; // Bar Index
    string today=TimeToString(time[0],TIME_DATE);

    // starting index for number of Separators
    if(MaxBarsToLookBackForSeparators<=0 || MaxBarsToLookBackForSeparators>rates_total-2)
    i1=rates_total-2; // starting index for calculation of all bars
    else i1= MaxBarsToLookBackForSeparators;


    if((daycheck1 == "NewTradingDay "+today)&&(daycheck2 == "DayText "+today))return(rates_total);

    //--- find the highest and lowest values of the chart
    max_price=ChartGetDouble(0,CHART_PRICE_MAX);
    min_price=ChartGetDouble(0,CHART_PRICE_MIN);
    //calculation place of the text
    int heightinpixels=ChartHeightInPixelsGet(0,0);
    textprice=max_price-((max_price-min_price)*(textplace/heightinpixels));

    while(i1>=0)
    {
    datetime now=time[i1];

    thisday=TimeToString(now,TIME_DATE);
    color clr = CLR_NONE;
    string text="";

    int weekday=TimeDayOfWeekMQL4(now);
    text = DaytoStr(weekday);
    clr = DaytoClr(weekday);

    if(ObjectFind(0,"NewTradingDay "+thisday)<0)
    {
    TrendCreate(0,"NewTradingDay "+thisday,0,now,Point(),now,textprice,clr,InpStyle,
    InpWidth,true,false,true,false,true,0);
    }

    if(ObjectFind(0,"DayText "+thisday)<0)
    {
    TextCreate(0,"DayText "+thisday,0,now,textprice,text,InpFont,InpFontSize,
    clr,90,InpAnchor,false,false,true,0);
    }
    i1--;
    }
    ChartRedraw(0);
    if(ObjectFind(0,"NewTradingDay "+today)==0)daycheck1="NewTradingDay "+today;
    if(ObjectFind(0,"DayText "+today)==0)daycheck2="DayText "+today;

    //--- return value of prev_calculated for next call
    return(rates_total);
    }

  10. #70
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    D lines-3

    //+------------------------------------------------------------------+
    //| Checks at timechange if objects has to move |
    //+------------------------------------------------------------------+
    void OnTimer()
    {
    //--- find the highest and lowest values of the chart
    max_price=ChartGetDouble(0,CHART_PRICE_MAX);
    min_price=ChartGetDouble(0,CHART_PRICE_MIN);

    int heightinpixels=ChartHeightInPixelsGet(0,0);
    textprice=max_price-((max_price-min_price)*(textplace/heightinpixels));

    if((textprice>newtextprice+Point()) || (textprice<newtextprice-Point()))
    {
    ChangeTextPrice(textprice);
    }
    }
    //+------------------------------------------------------------------+
    //+------------------------------------------------------------------+
    //| Set the right DayText to each Day |
    //+------------------------------------------------------------------+
    string DaytoStr(int weekday)
    {
    switch(weekday)
    {
    case 0 : return(" Sun"); break;
    case 1 : return(" Mon"); break;
    case 2 : return(" Tue"); break;
    case 3 : return(" Wed"); break;
    case 4 : return(" Thu"); break;
    case 5 : return(" Fri"); break;
    case 6 : return(" Sat"); break;
    }
    return("");
    }
    //+------------------------------------------------------------------+
    //| Setting the Colors of the Lines |
    //+------------------------------------------------------------------+
    color DaytoClr(int weekday)
    {
    switch(weekday)
    {
    case 0 : return(Sunday); break;
    case 1 : return(Monday); break;
    case 2 : return(Tuesday); break;
    case 3 : return(Wednesday); break;
    case 4 : return(Thursday); break;
    case 5 : return(Friday); break;
    case 6 : return(Saturday); break;
    }
    return(CLR_NONE);
    }

  11. #71
    Intraday Master
    Join Date
    May 2014
    Posts
    415
    FXO Shares
    0
    FXO Bonus
    1.890
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    //+------------------------------------------------------------------+
    //| The function receives the chart height value in pixels. |
    //+------------------------------------------------------------------+
    int ChartHeightInPixelsGet(const long chart_ID=0,const int sub_window=0)
    {
    //--- prepare the variable to get the property value
    long result=-1;
    //--- reset the error value
    ResetLastError();
    //--- receive the property value
    if(!ChartGetInteger(chart_ID,CHART_HEIGHT_IN_PIXELS,sub_window,result))
    {
    //--- display the error message in Experts journal
    Print(__FUNCTION__+", Error Code = ",GetLastError());
    }
    //--- return the value of the chart property
    return((int)result);
    }
    //+------------------------------------------------------------------+
    //| The function Returns the zero-based day of week |
    //| (0 means Sunday,1,2,3,4,5,6) for the specified date. |
    //+------------------------------------------------------------------+
    int TimeDayOfWeekMQL4(datetime date)
    {
    MqlDateTime tm;
    TimeToStruct(date,tm);
    return(tm.day_of_week);
    }

Page 5 of 5 FirstFirst 12345

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Disclaimer
2005-2019 © FXOpen All rights reserved. Various trademarks held by their respective owners.

Risk Warning: Trading on the Forex market involves substantial risks, including complete possible loss of funds and other losses and is not suitable for all members. Clients should make an independent judgment as to whether trading is appropriate for them in the light of their financial condition, investment experience, risk tolerance and other factors.

FXOpen Markets Limited, a company duly registered in Nevis under the company No. C 42235. FXOpen is a member of The Financial Commission.

FXOpen AU Pty Ltd., a company authorised and regulated by the Australian Securities & Investments Commission (ASIC). AFSL 412871ABN 61 143 678 719.

FXOpen Ltd. a company registered in England and Wales under company number 07273392 and is authorised and regulated by the Financial Conduct Authority (previously, the Financial Services Authority) under FCA firm reference number 579202.

FXOpen does not provide services for United States residents.

Join us