Use Icustom() with Separate string by comma

 
Hi all .. sorry becaouse my english is bad ..

i wanna ask , how can I use value

extern string Input_Indicator ="20.0,0.0,0.0,0.0,50.0,0.0,0.0,0.0";

// I wanna give value "Input_Indicator" from the input coloumn , use comma saperated but I dont know how...

if (iCustom(NULL, PERIOD_CURRENT, Indicator_Name,Input_Indicator,Buffer_Sell,Shift_Buffer_Sell) != EMPTY_VALUE)

#include <stdlib.mqh>
#include <WinUser32.mqh>

// exported variables
extern double Lot = 0.01;
extern int StopLoss = 20;
extern int TakeProfit = 30;
extern string Indicator_Name ="MA Cross Arrow";
extern string Input_Indicator ="20.0,0.0,0.0,0.0,50.0,0.0,0.0,0.0";
extern int Buffer_Buy = 0;
extern int Buffer_Sell = 1;
extern int Shift_Buffer_Buy = 1;
extern int Shift_Buffer_Sell = 1;


// 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;   // current bar index, used by Cross Up, Cross Down and many other blocks
int varylots[101]; // used by Buy Order Varying, Sell Order Varying and similar



int init()
{
    NDigits = Digits;
    
    if (false) ObjectsDeleteAll();      // clear the chart
    
    
    Comment("");    // clear the chart
    return (0);
}

// Expert start
int start()
{
    if (Bars < 10)
    {
        Comment("Not enough bars");
        return (0);
    }
    if (Terminated == true)
    {
        Comment("EA Terminated.");
        return (0);
    }
    
    OnEveryTick1();
    return (0);
}

void OnEveryTick1()
{
    PipValue = 1;
    if (NDigits == 3 || NDigits == 5) PipValue = 10;
    
    TechnicalAnalysis2();
    TechnicalAnalysis3();
    
}
// I wanna give value "Input_Indicator" from the input coloumn , use comma saperated but I dont know how...
void TechnicalAnalysis2()
{
    if (iCustom(NULL, PERIOD_CURRENT, Indicator_Name,Input_Indicator,Buffer_Sell,Shift_Buffer_Sell) != EMPTY_VALUE)
    {
        IfOrderDoesNotExist4();//open buy order
        
    }
}

void TechnicalAnalysis3()
{
    if (iCustom(NULL, PERIOD_CURRENT, Indicator_Name,Input_Indicator,Buffer_Buy,Shift_Buffer_Buy) != EMPTY_VALUE)
    {
        IfOrderDoesNotExist5();//open sell order
        
    }
}

/*
//But , when i do this ,, is working, but no simple ..

void TechnicalAnalysis2()
{
    if (iCustom(NULL, PERIOD_CURRENT, Indicator_Name,20.0,0.0,0.0,0.0,50.0,0.0,0.0,0.0,Buffer_Sell,Shift_Buffer_Sell) != EMPTY_VALUE)
    {
        IfOrderDoesNotExist4();//open buy order
        
    }
}

void TechnicalAnalysis3()
{
    if (iCustom(NULL, PERIOD_CURRENT, Indicator_Name,20.0,0.0,0.0,0.0,50.0,0.0,0.0,0.0,Buffer_Buy,Shift_Buffer_Buy) != EMPTY_VALUE)
    {
        IfOrderDoesNotExist5();//open sell order
        
    }
}
*/




void IfOrderDoesNotExist4()
{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 2)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        BuyOrder6();
        
    }
}

void BuyOrder6()
{
    double SL = Ask - StopLoss*PipValue*Point;
    if (StopLoss == 0) SL = 0;
    double TP = Ask + TakeProfit*PipValue*Point;
    if (TakeProfit == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, Lot, Ask, 4, 0, 0, "My Expert", 2, 0, Blue);
    else
    ticket = OrderSend(Symbol(), OP_BUY, Lot, Ask, 4, SL, TP, "My Expert", 2, 0, Blue);
    if (ticket > -1)
    {
        if (true)
        {
            bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}



void IfOrderDoesNotExist5()
{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        SellOrder7();
        
    }
}

void SellOrder7()
{
    double SL = Bid + StopLoss*PipValue*Point;
    if (StopLoss == 0) SL = 0;
    double TP = Bid - TakeProfit*PipValue*Point;
    if (TakeProfit == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_SELL, Lot, Bid, 4, 0, 0, "My Expert", 1, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_SELL, Lot, Bid, 4, SL, TP, "My Expert", 1, 0, Red);
    if (ticket > -1)
    {
        if (true)
        {
            bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}



int deinit()
{
    if (false) ObjectsDeleteAll();
    
    
    return (0);
}

Files:
 
Ridwan Salahudin: i wanna ask , how can I use value

extern string Input_Indicator ="20.0,0.0,0.0,0.0,50.0,0.0,0.0,0.0";
Only by reading the indicator can you understand how it uses that input.
 
if (iCustom(NULL, PERIOD_CURRENT, Indicator_Name,20,0,0,0,50,0,0,0,Buffer_Sell,Shift_Buffer_Sell) != EMPTY_VALUE)
 
Yashar Seyyedin #:

Worth mentioning that you may leave inputs field empty if you expect default entries.(It seems you want default entries)

if (iCustom(NULL, PERIOD_CURRENT, Indicator_Name,Buffer_Sell,Shift_Buffer_Sell) != EMPTY_VALUE)
 
rYashar Seyyedin #:

Worth mentioning that you may leave inputs field empty if you expect default entries.(It seems you want default entries)

thanks for u reply...

but actually i wanna make the ICustom() can change indikator parameter input from value :
extern string Input_Indicator ="20.0,0.0,0.0,0.0,50.0,0.0,0.0,0.0";



so .. if this possible .. i can make EA from any indicator with out change mql4 code frist (if the indicator have Buffer Signal) ...  

 
Ridwan Salahudin #:
the

Then you should use IndicatorCreate instead. Check this link: https://www.mql5.com/en/forum/234571

Simply parse input string and create input parameters accordingly. 

indicatorCreate and iCustom
indicatorCreate and iCustom
  • 2018.04.07
  • www.mql5.com
Hi, I'm wonder what is the difference between iCustom and IndicatorCreate functions which give a handle of home made indicator both...
 
Yashar Seyyedin #:

Then you should use IndicatorCreate instead. Check this link: https://www.mql5.com/en/forum/234571

Simply parse input string and create input parameters accordingly. 


thank u , but thats mql5 .. i need for mql4

 
Ridwan Salahudin #: thank u , but thats mql5 .. i need for mql4

You must split the string, convert each piece to the proper datatype, and pass it through iCustom. You.

 
William Roeder #:

You must split the string, convert each piece to the proper datatype, and pass it through iCustom. You.

yeah .. i do it .. 

string data_OP[];

int stringSplitResult_OP = StringSplit(Input_Indicator_OPorder, ',', data_OP);

int dataCount_OP = ArraySize(data_OP);

double indicatorValues_OP[i];

string stringValues_OP[i];



if (stringSplitResult_OP <= dataCount_OP)
    {
        for (int i = 0; i < dataCount_OP; i++)
        {
            double doubleValue = StrToDouble(data_OP[i]);
            int integerValue = MathRound(doubleValue);

            if (doubleValue == integerValue)
            {
                Print("Terdeteksi integer");
                indicatorValues_OP[i] = DoubleToString(doubleValue);
                stringValues_OP[i] = DoubleToString(doubleValue);
            }

            else
            {
                indicatorValues_OP[i] = DoubleToString(indicatorValues_OP[i])  
              
            }

    }



 if ((iCustom(NULL, PERIOD_CURRENT, Indicator_Name_OPorder, indicatorValues_OP[i],Buffer_Signal_OPBuy, Shift_Buffer_OPBuy+1) == EMPTY_VALUE)





But the problem is.. u will stuck when meet indicator have "Type String" like this   picture >>> https://telegra.ph/file/261ee54292b3c6a1a11dc.jpg <<<



im trying to 

DoubleToString( indicatorValues_OP[i])

but is not working

 

You are not “doing it”.

  1. Ridwan Salahudin #:
    double indicatorValues_OP[i];
    
    string stringValues_OP[i];
    

    Do not post code that will not even compile.

  2. Ridwan Salahudin #:

    yeah .. i do it .. 

     if ((iCustom(NULL, PERIOD_CURRENT, Indicator_Name_OPorder, indicatorValues_OP[i],Buffer_Signal_OPBuy, Shift_Buffer_OPBuy+1) == EMPTY_VALUE)
    
    but is not working
    You are passing one value not all of them.
 
William Roeder #:

You are not “doing it”.

  1. Do not post code that will not even compile.

  2. You are passing one value not all of them.

well actually i put IndicatorValues_op[50], thats why i just have problem with string data :

But here example :

     string a[10]={"0.7","650"};
    double expectedCode =iCustom(Symbol(),0,"NAMEINDICATOR",a[0],a[1],0,0);
     Print(a[0]," X ",a[1]);

what if in the data have string data

     string a[10]={"0.7","650","String Data"};
    double expectedCode =iCustom(Symbol(),0,"NAMEINDICATOR",a[0],a[1],a[3],0,0);
     Print(a[0]," X ",a[1]," X ",a[3]);

i can't do expectedCode = DoubleToStr( expectedCode );

how can I Switch Double expectedCode to string expectedCode when in the array have string data?...

Reason: