Buffer to open trade

 

Hi..

in mql4

double arrowup = iCustom(Symbol(), Period(),indi, 0, 0);
if(OrdersTotal==0 && arrowup!=EMPTYVALUE)
{
//Open order Buy
}

How do i make it in mql5

int arrow;
double arrowup[];
int OnInit()
{   
   arrow = iCustom(Symbol(), Period(),"arrow");
   if(arrow < 0)
     {
      Print("The creation of pipsbreak_handle has failed: pipsbreak_handle=", INVALID_HANDLE);
      Print("Runtime error = ", GetLastError());
      return(INIT_FAILED);
     }
}
 void OnTick()
  {
  if(CopyBuffer(Symbol(), PERIOD_CURRENT, 0, 200, arrowup) <= 0) return;
   ArraySetAsSeries(arrowup, true);
if(arrowup[1]!=EMPTYVALUE && CalculateAllPositions())
{
//Open order Buy
}
  }

not opening order, am i doing the right thing?

 

Here is how the code should look in MQL5:

int handle_iCustom;
double array_up[];
ArraySetAsSeries(array_up, true);
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create handle of the indicator iCustom
   handle_iCustom=iCustom(Symbol(),Period(),"NAME INDICATOR");
//--- if the handle is not created
   if(handle_iCustom==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  int buffer_num=0,start_pos=0,count=6;
   if(CopyBuffer(handle_iCustom,buffer_num,start_pos,count,array_up)!=count)
      return;

   if(array_up[1]!=EMPTYVALUE && CalculateAllPositions())
     {
      //Open order Buy
     }
  }
 

Thanks for your feedback!!

i tried it but still no trades..

all Eas placed trades except this.. and not a single journal error

code

string indi="arrow_Signal";

int indicator_handle;
double slswing[],buyarw[],sellarw[];

int OnInit()
  {   
   indicator_handle= iCustom(Symbol(), Period(),indi);
   if(indicator_handle==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early
      return(INIT_FAILED);
   }
void OnTick()
  {
   int count=6;
   if(CopyBuffer(indicator_handle, 0, 0, count, buyarw) !=count) return;
   if(CopyBuffer(indicator_handle, 1, 0, count, sellarw) !=count) return;
   if(CopyBuffer(indicator_handle, 8, 0, count, slswing) !=count) return;
   ArraySetAsSeries(buyarw,true);
   ArraySetAsSeries(sellarw,true);
   ArraySetAsSeries(slswing,true);
if(buyarw[1]!=EMPTY_VALUE)
{
//Open order Buy
}

}


still no trades..

i tried to use another ma1 above ma2 =buy and it works..

theere is no journal errors, it runs on strategy tester.. but not a single order placed!!!

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
The idea of ​​automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 
ArraySetAsSeries


added it on global variable it returns error.. supposed to be on global variable..?

and again the

EMPTY_VALUE

yours looks like this

EMPTYVALUE

supposed to be EMPTYVALUE?

 
Abubakar Saidu :


added it on global variable it returns error.. supposed to be on global variable..?

and again the

yours looks like this

supposed to be EMPTYVALUE?

EMPTYVALUE is my typo.

Are you sure you need to check bar # 1? Are you sure you need to check for equality EMPTY_VALUE? In general, your indicator is needed.

 
Vladimir Karputov:

EMPTYVALUE is my typo.

Are you sure you need to check bar # 1? Are you sure you need to check for equality EMPTY_VALUE? In general, your indicator is needed.

Hi.. i tried it but not working..

i used a sample from the below code and get it working

here


   bool need_open_buy=(iCustomGet(handle_iCustom,0,1)==0.0)?false:true;
   bool need_open_sell=(iCustomGet(handle_iCustom,1,1)==0.0)?false:true;

   if(CalculateAllPositions()==0.0)
     {
      if(need_open_buy)
        {
         double sl=(InpStopLoss==0)?0.0:m_symbol.Ask()-ExtStopLoss;
         double tp=(InpTakeProfit==0)?0.0:m_symbol.Ask()+ExtTakeProfit;
         OpenBuy(sl,tp);
        }
      else if(need_open_sell)
        {
         double sl=(InpStopLoss==0)?0.0:m_symbol.Bid()+ExtStopLoss;
         double tp=(InpTakeProfit==0)?0.0:m_symbol.Bid()-ExtTakeProfit;
         OpenSell(sl,tp);
        }
     }
   else
     {
      if(need_open_buy)
         ClosePositions(POSITION_TYPE_SELL);
      else if(need_open_sell)
         ClosePositions(POSITION_TYPE_BUY);
      Trailing();
     }
Thanks a lot for your feedback
 
Abubakar Saidu :

Hi.. i tried it but not working..

i used a sample from the below code and get it working

here


Thanks a lot for your feedback

I don’t understand - why are you asking about "EMPTY_VALUE"? Indeed, the indicator uses the value "0.0" - "0.0" is an empty value.

Second: amend the indicator:

//---- превращение динамического массива в индикаторный буфер
   SetIndexBuffer(1,BuyBuffer,INDICATOR_DATA);
//---- осуществление сдвига начала отсчета отрисовки индикатора 2
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,StartBars);
//--- создание метки для отображения в DataWindow
   PlotIndexSetString(1,PLOT_LABEL,"Buy");
//---- символ для индикатора
   PlotIndexSetInteger(1,PLOT_ARROW,108);
//---- индексация элементов в буфере как в таймсерии
   ArraySetAsSeries(BuyBuffer,true);
//---- запрет на отрисовку индикатором пустых значений
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
 
Vladimir Karputov:

I don’t understand - why are you asking about "EMPTY_VALUE"? Indeed, the indicator uses the value "0.0" - "0.0" is an empty value.

Second: amend the indicator:

HI..

i didn't use this indicator.. i only used the codes in the EA.. to make mine

my indicator is different!! and i only have access to the .ex5 format..

but i got it working using this code

   bool need_open_buy=(iCustomGet(handle_iCustom,0,1)==0.0)?false:true;
   bool need_open_sell=(iCustomGet(handle_iCustom,1,1)==0.0)?false:true;

Thanks again..

 
Abubakar Saidu :

HI..

i didn't use this indicator.. i only used the codes in the EA.. to make mine

my indicator is different!! and i only have access to the .ex5 format..

but i got it working using this code

Thanks again..

Please do not constantly change the terms of the question :)

I have already given you several options that work. And even fixed the indicator that you are using (post   )

Now I finally do not understand: what are you doing and what do you want to receive. My advice: formulate your task, do not change the task constantly, provide an indicator code and an advisor code, ask a question.

Buffer to open trade
Buffer to open trade
  • 2020.03.10
  • www.mql5.com
Hi.. in mql4 How do i make it in mql5 not opening order, am i doing the right thing...
 
Vladimir Karputov:

Please do not constantly change the terms of the question :)

I have already given you several options that work. And even fixed the indicator that you are using (post   )

Now I finally do not understand: what are you doing and what do you want to receive. My advice: formulate your task, do not change the task constantly, provide an indicator code and an advisor code, ask a question.

Ohh am sorry.. Next time

Thanks a lot for your time and feedback

appreciated a lot..

:)

Reason: