Use Icustom() with Separate string by comma

ridwan_007

Trader
Nov 16, 2021
5
0
17
24
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)
6f15cb73ea2df4551d666.jpg

MQL4:
#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);
}
 

Attachments

  • MA Cross Arrow.ex4
    14.5 KB · Views: 3