My EA doesn't want to open a position

 

Hello. Can someone help me. please. My EA doesn't want to open a position. I use FBS Broker, my EA uses ADX and Martingale strategy

double                                  TP_in_Money                             = 0;
int                                             StartLock                               =90;
int                                             Lock                                    = 50;
int     Trailing_Stop;
int             EndHour1, StartHour1, GMTOffset;
string comment1;
bool STP_Broker                 = false;
bool bolehbuy=true, bolehsell=true;
double MinLots, MaxLots, minlot, TPBuy, SLBuy;
int DIGIT, convert, slippage=10, spread, stoplevel;
double last_lot_sell, last_price_sell, last_lot_buy, last_price_buy, last_price, last_lot;
int last_type, pending, OpenOrders, cnt, openbuy, opensell;
bool CLOSE, DELETE;
datetime time;
double last_tp, last_sl;
int buystop=0;
int buylimit=0;
int sellstop=0;
int selllimit=0;
double Lots;
string X[401];
double lotstep;
double Balance, FreeMargin,loti;
double Equity;
double mode_point,TP,SL;
int ticket;
bool modify;
double komponen_buy, komponen_sell;
double harga_open_sell_tertinggi, harga_open_sell_terendah;
double harga_open_buy_tertinggi,harga_open_buy_terendah;
double total_lot_buy, total_lot_sell;
double harga_buystop_tertinggi, harga_sellstop_tertinggi;
double harga_buylimit_tertinggi,harga_selllimit_tertinggi;
int total,pendingbuy,pendingsell;
double harga_buystop_terendah, harga_sellstop_terendah;
double harga_buylimit_terendah, harga_selllimit_terendah;
double last_price_buystop,last_price_buylimit;
double last_price_sellstop,last_price_selllimit;
double komponen_buy_tertinggi=0;
double komponen_buy_terendah=999999;
double komponen_sell_tertinggi=0;
double komponen_sell_terendah=999999;
datetime thistime, Awal, Akhir;
double Margin_Level,rata_buy, rata_sell,Lot_Marti,harga;
double last_sl_buy, last_sl_sell,last_tp_buy, last_tp_sell;
double total_lot_open = 0;
bool modifikasi;
string status;
bool STOP;
double max_lot_martingale,tickvalue;
int OpenOrders1;
int openbuy1, opensell1;
double SL_In_Money       =0;
int insta;

//+------------------------------------------+
//| expert initialization function                      |
//+------------------------------------------+
int OnInit()
        {
if (!IsExpertEnabled()) {Alert ("EA BELUM AKTIF, KLIK TOMBOL AKTIVASI EA");}
if (!IsTradeAllowed()) {Alert ("EA BELUM AKTIF, CENTANG PADA ALLOW LIVE TRADING");}

for (int t=0; t<400; t++)
        {
         X[t] = CharToStr(t);
         }
         return(0);
         }

//+-------------------------------------------+
//| expert deinitialization function            |
//+-------------------------------------------+
void OnDeinit(const int reason)
        {
        return;
        }

//+-------------------------------------------+
//| expert start function                                       |
//+-------------------------------------------+
double OnTester()
        {
        double ret=0.0;
        return(ret);
        }
        
        void OnChartEvent(const int id, const long &lparam,
        const double &dparam,
        const string &sparam)
        {
        }
        void OnTick()
        
        {
tickvalue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE);
minlot    = SymbolInfoDouble (_Symbol,SYMBOL_VOLUME_MIN);
lotstep   = SymbolInfoDouble (_Symbol,SYMBOL_VOLUME_STEP);
MinLots   = SymbolInfoDouble (_Symbol,SYMBOL_VOLUME_MIN);
MaxLots   = SymbolInfoDouble (_Symbol,SYMBOL_VOLUME_MAX);
mode_point = SymbolInfoDouble (_Symbol,SYMBOL_POINT);
stoplevel = SymbolInfoInteger (_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
spread    = SymbolInfoInteger (_Symbol,SYMBOL_SPREAD);
Balance   = AccountInfoDouble (ACCOUNT_BALANCE);
FreeMargin = AccountInfoDouble (ACCOUNT_FREEMARGIN);
Equity    = AccountInfoDouble (ACCOUNT_EQUITY);
Margin_Level = AccountInfoDouble (ACCOUNT_MARGIN_LEVEL);

openord();
rata_buy = rata_price(OP_BUY);
rata_sell = rata_price (OP_SELL);
if (minlot/0.01==1) {DIGIT=2;} else {DIGIT=1;}
if (lotstep*10<1) {DIGIT=2;} else {DIGIT=1;}
if (_Digits==5 ||_Digits==3) {convert=10; slippage=100;} else {convert=1;}
if (StringFind (AccountCompany(), "insta",0)>=0) {insta=1;} else {insta=10;}
convert=1;
loti    = NormalizeDouble(FreeMargin*Lot_Risk/100000,DIGIT);
if (Use_MM_Auto_Lot) {Lots=MinLots;} else {Lots=LOTS;}
if (Lots<MinLots){Lots=MinLots;}
if (Lots>MaxLots){Lots=MaxLots;}
Lots = NormalizeDouble (Lots,DIGIT);
if (TrailingStop*convert<stoplevel+spread&&TrailingStop!=0){Trailing_Stop=(stoplevel+spread)/convert;} else {Trailing_Stop=TrailingStop;}

if(TP_in_Money!=0&& ProfitInMoney()>=TP_in_Money && OpenOrders>0)
{CloseAll(7); CloseAll(7); CloseAll(7); CloseAll(7); CloseAll(7); CloseAll(7); 
CloseAll(7); CloseAll(7); CloseAll(7); CloseAll(7); Alert ("TP IN MONEY");}

if(SL_In_Money!=0&& ProfitInMoney()<=-SL_In_Money && OpenOrders>0)
{CloseAll(7); Alert ("SL IN MONEY");}

getOpenOrders(0,0, Trailing_Stop, StartLock, Lock);
adx_main=iADX(Symbol(),0,ADX_period,ADX_aplied_price, MODE_MAIN, 1);
adx_plus = iADX(Symbol(),0,ADX_period,ADX_aplied_price, MODE_PLUSDI,1);
adx_minus = iADX(Symbol(),0,ADX_period, ADX_aplied_price, MODE_MINUSDI, 1);
adx_main1 = iADX(Symbol(),0,ADX_period, ADX_aplied_price, MODE_MAIN, 2);
adx_plus1 = iADX(Symbol (),0, ADX_period, ADX_aplied_price, MODE_PLUSDI, 2);
adx_minus1 = iADX (Symbol(),0, ADX_period, ADX_aplied_price, MODE_MINUSDI, 2);

openord();
if (openbuy==0 && buylimit>0) {CloseAll(2);}
if (opensell==0 && selllimit>0) {CloseAll(3);}

openord();
if(TimeFilter()&&time!=iTime(Symbol(),0,0)&&kadaluarsa()&&LoginNumber())
{
if(openbuy==0 && buylimit==0 && buy_adx())
{
if (openbuy==Max_Level-1) {SL = StopLoss;} else {SL=0;}
if (OPEN (Symbol(), OP_BUY, Blue, Lots, slippage, Ask, false, SL, TakeProfit_OP1,"",Magic))
        {time=iTime (Symbol(),0,0); bolehbuy=false; bolehsell=true;}
        }
if (opensell==0 && selllimit==0 && sell_adx())
 {
 if (opensell==Max_Level-1) {SL = StopLoss;} else {SL=0;}
 if (OPEN (Symbol(), OP_SELL, Red, Lots, slippage, Bid, false, SL, 
 TakeProfit_OP1,"", Magic))
 {time=iTime (Symbol(),0,0); bolehbuy=true; bolehsell=false;}
 }}
 
 if (true)
 {
 openord();
 if (openbuy>0 && openbuy<Max_Level && buylimit==0)
 {
 if (openbuy==1 && openbuy<=5) {Lot_Marti = NormalizeDouble (last_lot_buy * Multiplier_1, DIGIT);} 
 if (openbuy>5) {Lot_Marti = NormalizeDouble (last_lot_buy * Multiplier_2, DIGIT);}//batas kalimat
 harga = komponen_buy_terendah-Step*convert*Point;
 harga = NormalizeDouble (harga,Digits);
 if (openbuy==Max_Level-1) {SL = StopLoss;} else {SL=0;}
 if (Ask-harga>=stoplevel*_Point)
 {
 if (OPEN (Symbol(), OP_BUYLIMIT, Blue, Lot_Marti, slippage, harga, false, SL, TakeProfit_Marti, "",Magic)) // batas kalimat
 {time=iTime(Symbol(),0,0);}
 }
 
 if (Ask<=harga)
 {
 if (OPEN (Symbol(), OP_BUY, Blue, Lot_Marti, slippage, Ask, false, SL, TakeProfit_Marti,"", Magic))
 {time=iTime (Symbol(),0,0);}
 }}
 
 
 openord();
 if (opensell>0 && opensell<Max_Level&& selllimit==0)
 {
 if (opensell==1 && opensell<=5) {Lot_Marti = NormalizeDouble (last_lot_sell * Multiplier_1, DIGIT);}
 if (opensell>5) {Lot_Marti = NormalizeDouble (last_lot_sell * Multiplier_2, DIGIT);}
 
 harga = komponen_sell_tertinggi+Step*convert*Point;
 harga = NormalizeDouble (harga,Digits);
 if (opensell==Max_Level-1) {SL = StopLoss;} else {SL=0;}
 
 if (harga-Bid >= stoplevel*_Point)
 {
 if (OPEN (Symbol(), OP_SELLLIMIT, Red, Lot_Marti, slippage, harga, false, SL, TakeProfit_Marti, "", Magic))
 {time=iTime (Symbol(),0,0);}
  }
 if (Bid>=harga)
 {
 if (OPEN (Symbol(), OP_SELL, Red, Lot_Marti, slippage, Bid, false, SL, TakeProfit_Marti, "", Magic))
 {time=iTime(Symbol(),0,0);}
 }}}
 
 openord();
 if (openbuy1>openbuy) {CloseAll(2);}
 if (opensell1>opensell) {CloseAll(3);}
 openord();
 openbuy1 = openbuy;
 opensell1 = opensell;
 if (Pindah_TP)
 {
 if (openbuy>0) {ModifyTP(OP_BUY, last_tp_buy);}
 if (opensell>0) {ModifyTP(OP_SELL, last_tp_sell);}
 }
 if (opensell>0) {ModifySL(OP_SELL, last_tp_sell);}
 if (openbuy>0) {ModifySL(OP_BUY, last_tp_buy);}
 if (opensell>=Max_Level) {ModifySL(OP_SELL, last_sl_sell);}
 if (openbuy>=Max_Level) {ModifySL(OP_BUY, last_sl_buy);}
 
 if (STOP) {status = "EA STOP TRADING";} else {status = "EA CONTINUE TRADING";}
 
 komentar (1, "MAGIC", DoubleToString (Magic,0));
 komentar (2, "NAMA", AccountName());
 komentar (3, "No. ACC", AccountNumber());
 komentar (4, "BROKER", AccountCompany());
 komentar (5, "LEVERAGE","1:"+DoubleToString(AccountLeverage(),0));
 komentar (6, "BALANCE", DoubleToString (AccountBalance(),2));
 komentar (7, "EQUITY", DoubleToString (AccountEquity(),2));
 
 if (STP_Broker)
        {
         ModifySL_STP (StopLoss);
         }
         return;
         }

//+====================================================+
//| GETOPENORDER                                                                                |
//+====================================================+
void getOpenOrders(double TakeProfit_func, double StopLoss_func, double Trailing_Stop_func, double StartLock_func, double Lock_func)
{
int totalorders = OrdersTotal();
for(int j=0; j<totalorders;j++)
        {
if (OrderSelect(j, SELECT_BY_POS, MODE_TRADES))
{
if((OrderType() == OP_BUY || OrderType() == OP_SELL) && OrderSymbol() == Symbol() && OrderMagicNumber()==Magic)
{
double val=getPipValue(OrderOpenPrice(), OrderType());
if (TakeProfit_func!=0) {takeProfit(TakeProfit_func,val,OrderTicket());}
if (StopLoss_func!=0) {killTrade(StopLoss_func, val, OrderTicket());}
if (Trailing_Stop_func!=0) {TrailingPositions(Trailing_Stop_func,1,OrderTicket());}
if (StartLock_func!=0) {Lock_Profit(StartLock_func,Lock_func, OrderTicket());}
}}}}

this is part of the script

1. Where is the error? 2. How to open positions more often? thank you for helping me