Set correct condition for iCustom

 

Hello everyone!

I'm new to coding, I want to add an indicator to the Expert Advisor, I've read a lot of literature, but I can't seem to set the condition correctly.

condition doesn't work. Can someone guide me? Thank you!

         if (UseBands)

         {

              smax[shiftt]=iCustom(NULL,0,"TDTOPTREND",Length,Deviation,1,Signal,Line,Nbars,PRICE_CLOSE,MODE_UPPER);

           smin[shiftt]=iCustom(NULL,0,"TDTOPTREND",Length,Deviation,1,Signal,Line,Nbars,PRICE_CLOSE,MODE_LOWER);

}

if (!skip_buy && UseBands  && smax[shiftt] >curprice) {skip_buy=true; Print ("Skip Cond 9 Buy");}

if (!skip_sell && UseBands && smin[shiftt]<curprice) {skip_sell=true; Print ("Skip Cond 9 Sell");}

 

1 - use the code button so the code is properly formatted.

2 - iCustom, per the documentation, returns a handle to an indicator. A handle is a reference to a space in memory that stores all indicator data. To retrieve the data from the handle, you use CopyBuffer. I don't mean to be offensive, but this code looks like it was generated by ChatGPT - which is against this forum's rules.

Anyway, call iCustom once from the OnInit function and store its result in a global variable.

Use the global variable to retrieve the indicator data calling CopyBuffer inside OnTick function.

If you don't know how to do it, read the AlgoBook or search for an EA that creates a strategy for you (there're a few in the market) or order an EA via the freelancer section.

MQL5 Programming for Traders – MetaTrader 5 algorithmic/automatic trading language manual
MQL5 Programming for Traders – MetaTrader 5 algorithmic/automatic trading language manual
  • www.mql5.com
MQL5 Programming for Traders – MetaTrader 5 algorithmic/automatic trading language manual