error

 

Hi. I wrote a expert but my custom indicator(ftlm-stlm) is repeated in chart when i want to test it. how can i solve it ?!        thanks!


#include <Trade\Trade.mqh>

// exported variables


// local variables
double PipValue=1;    // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = "\n";  // use this in custom or utility blocks where you need line feeds
int NDigits = 4;   // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0;  // count of all objects created on the chart, allows creation of objects with unique names
int current = 0;



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    //---
    NDigits = Digits();
    if (NDigits == 3 || NDigits == 5) PipValue = 10;
    
    if (AccountInfoInteger(ACCOUNT_TRADE_EXPERT) == false)
    {
        Print("Check terminal options because EA trade option is set to not allowed.");
        Comment("Check terminal options because EA trade option is set to not allowed.");
    }
    
    //---
    return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    //---
    if (Terminated == true)
    {
        Comment("EA Terminated.");
    }
    
    OnEveryTick1();
}

//+------------------------------------------------------------------+
//| Get Low for specified bar index                                  |
//+------------------------------------------------------------------+
double Low(int index)
{
    double arr[];
    double low = 0;
    ArraySetAsSeries(arr, true);
    int copied = CopyLow(Symbol(), PERIOD_CURRENT, 0, Bars(Symbol(), PERIOD_CURRENT), arr);
    if (copied>0 && index<copied) low = arr[index];
    return (low);
}
//+------------------------------------------------------------------+
//| Get the High for specified bar index                             |
//+------------------------------------------------------------------+
double High(int index)
{
    double arr[];
    double high = 0;
    ArraySetAsSeries(arr, true);
    int copied = CopyHigh(Symbol(), PERIOD_CURRENT, 0, Bars(Symbol(), PERIOD_CURRENT), arr);
    if (copied>0 && index<copied) high=arr[index];
    return(high);
}
//+------------------------------------------------------------------+
//| Get Close for specified bar index                                |
//+------------------------------------------------------------------+
double Close(int index)
{
    double arr[];
    double close = 0;
    ArraySetAsSeries(arr, true);
    int copied = CopyClose(Symbol(), PERIOD_CURRENT, 0, Bars(Symbol(), PERIOD_CURRENT), arr);
    if (copied>0 && index<copied) close = arr[index];
    return (close);
}
//+------------------------------------------------------------------+
//| Get Open for specified bar index                                 |
//+------------------------------------------------------------------+
double Open(int index)
{
    double arr[];
    double open = 0;
    ArraySetAsSeries(arr, true);
    int copied = CopyOpen(Symbol(), PERIOD_CURRENT, 0, Bars(Symbol(), PERIOD_CURRENT), arr);
    if (copied>0 && index<copied) open = arr[index];
    return (open);
}
//+------------------------------------------------------------------+
//| Get current bid value                                            |
//+------------------------------------------------------------------+
double Bid()
{
    return (SymbolInfoDouble(Symbol(), SYMBOL_BID));
}

//+------------------------------------------------------------------+
//| Get current ask value                                            |
//+------------------------------------------------------------------+
double Ask()
{
    return (SymbolInfoDouble(Symbol(), SYMBOL_ASK));
}

//+------------------------------------------------------------------+
//| Is there an error                                                |
//+------------------------------------------------------------------+
bool IsError(MqlTradeResult& result, string function)
{
    if (result.retcode != 0 && result.retcode != TRADE_RETCODE_DONE && result.retcode != TRADE_RETCODE_PLACED)
    {
        Print("Function: ", function, " Error: ", result.retcode, " ", result.comment);
        return (true);
    }
    else
    Print("> Executed: [", function, "]");
    return (false);
}

bool IsError(CTrade& trade, string function)
{
    if (trade.ResultRetcode() != 0 && trade.ResultRetcode() != TRADE_RETCODE_DONE && trade.ResultRetcode() != TRADE_RETCODE_PLACED)
    {
        Print("Function: ", function, " Error: ", trade.ResultRetcode(), " ", trade.ResultRetcodeDescription());
        return (true);
    }
    else
    Print("> Executed: [", function, "]");
    return (false);
}

//+------------------------------------------------------------------+
//| Get indicator value back                                         |
//+------------------------------------------------------------------+
double GetIndicator(int handle, int buffer_num, int index)
{
    //--- array for the indicator values
    double arr[];    
    //--- obtain the indicator value in the last two bars
    if (CopyBuffer(handle, buffer_num, 0, index+1, arr) <= 0)
    {        
        Sleep(5);
        for(int i=0; i<100; i++)
        {
            if (BarsCalculated(handle) > 0)
            break;
            Sleep(50);
        }
        int copied = CopyBuffer(handle, buffer_num, 0, index+1, arr);
        if (copied <= 0)
        {
            Print("CopyBuffer Failed. Error = ", GetLastError());
            return -1;
        }
        else
        {
            IndicatorRelease(handle);
            return (arr[index]);
        }
    }
    else
    {
        IndicatorRelease(handle);
        return (arr[index]);
    }
    
    IndicatorRelease(handle);
    return 0;
}

//+------------------------------------------------------------------+
//| Building blocks                                                  |
//+------------------------------------------------------------------+
void OnEveryTick1()
{
    if (true == false && false) PipValue = 10;
    if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;
    
    TechnicalAnalysis16();
    TechnicalAnalysis2();
    
}

void TechnicalAnalysis16()
{
    
    if (GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,0) < 0)
    {
        TechnicalAnalysis2x17();
        
    }
}

void TechnicalAnalysis2x17()
{
    
    if ((GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,2) < GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,1)) && (GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,1) < GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,0)))
    {
        TechnicalAnalysis2x18();
        
    }
}

void TechnicalAnalysis2x18()
{
    
    if ((GetIndicator(iCustom(NULL, NULL, "RBCI_",0),0,2) > GetIndicator(iCustom(NULL, NULL, "RBCI_",0),0,1)) && (GetIndicator(iCustom(NULL, NULL, "RBCI_",0),0,1) < GetIndicator(iCustom(NULL, NULL, "RBCI_",0),0,0)))
    {
        Arrow19();
        
    }
}

void Arrow19()
{
    
    ObjCount += 1;
    string objName = "EAChart_" + IntegerToString(ObjCount);
    
    // set object parameters
    double price=SymbolInfoDouble(Symbol(), SYMBOL_BID);
    if (!ObjectCreate(0, objName, OBJ_ARROW_LEFT_PRICE, 0, TimeCurrent(), price))
    {
        // arrow create error
        printf("Arrow create: Error %d!", GetLastError());
        //
        return;
    }
    else
    ObjectSetInteger(0, objName, OBJPROP_COLOR, White);
    Alert20();
    
}

void Alert20()
{
    Alert("RBCI.........................Buy...........................................");
    
}

void TechnicalAnalysis2()
{
    
    if (GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,0) > 0)
    {
        TechnicalAnalysis2x3();
        
    }
}

void TechnicalAnalysis2x3()
{
    
    if ((GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,2) > GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,1)) && (GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,1) > GetIndicator(iCustom(NULL, NULL, "FTLM-STLM"),0,0)))
    {
        TechnicalAnalysis2x4();
        
    }
}

void TechnicalAnalysis2x4()
{
    
    if ((GetIndicator(iCustom(NULL, NULL, "RBCI_",0),0,2) < GetIndicator(iCustom(NULL, NULL, "RBCI_",0),0,1)) && (GetIndicator(iCustom(NULL, NULL, "RBCI_",0),0,1) > GetIndicator(iCustom(NULL, NULL, "RBCI_",0),0,0)))
    {
        Arrow5();
        
    }
}

void Arrow5()
{
    
    ObjCount += 1;
    string objName = "EAChart_" + IntegerToString(ObjCount);
    
    // set object parameters
    double price=SymbolInfoDouble(Symbol(), SYMBOL_BID);
    if (!ObjectCreate(0, objName, OBJ_ARROW_LEFT_PRICE, 0, TimeCurrent(), price))
    {
        // arrow create error
        printf("Arrow create: Error %d!", GetLastError());
        //
        return;
    }
    else
    ObjectSetInteger(0, objName, OBJPROP_COLOR, Red);
    Alert7();
    
}

void Alert7()
{
    Alert("RBCI.........................SELL...........................................");
    
}


Files:
FTLM-STLM.mq5  29 kb
RBCI_.mq5  7 kb
 
Sarsali:

Hi. I wrote a expert but my custom indicator(ftlm-stlm) is repeated in chart when i want to test it. how can i solve it ?!        thanks!


It's perfectly normal, what you get is in accordance with your code (and this code is a mess).

You didn't write an expert, this code comes from an EA generator, so I suggest you to ask support from the author of this tool.

 
angevoyageur:

It's perfectly normal, what you get is in accordance with your code (and this code is a mess).

You didn't write an expert, this code comes from an EA generator, so I suggest you to ask support from the author of this tool.

Thanks angevoyageur

yes, my intent from write was creating it(by EA generator) !!!

i think it's NOT normal, problem must be from my code! I try to correct it and search for it's reason.

i don' have this problem in MT4 !

Reason: