Need Help With Using iCustom in my EA

 

I have been trying to program an EA that uses some custom indicators. When I compile my EA I do NOT get any errors. However, when I back test it no trades are ever placed so I am guessing I called iCustom wrong.

Here is my code:

#include <IncludeExample.mqh>


// External variables
extern bool DynamicLotSize = true;
extern double EquityPercent = 2;
extern double FixedLotSize = 0.01;

extern double StopLoss = 80;
extern double TakeProfit = 100;

extern int TrailingStop = 50;
extern int MinimumProfit = 50;


extern int Slippage = 5;
extern int MagicNumber = 123;

extern bool CheckOncePerBar = true;


// Global variables
int BuyTicket;
int SellTicket;

double UsePoint;
int UseSlippage;

bool Buy = true;
bool Sell = false;

datetime CurrentTimeStamp;


// Init function
int init()
        {
                UsePoint = PipPoint(Symbol());
                UseSlippage = GetSlippage(Symbol(),Slippage);
                
        }
        

// Start function
int start()
        {
                
                // Execute on bar open
                if(CheckOncePerBar == true)
                        {
                                int BarShift = 1;
                                if(CurrentTimeStamp != Time[0]) 
                                        {
                                                CurrentTimeStamp = Time[0];
                                                bool NewBar = true;
                                        }
                                else NewBar = false;
                        }
                else 
                        {
                                NewBar = true;
                                BarShift = 0;
                        }
                

      double LotSize = CalcLotSize(DynamicLotSize,EquityPercent,StopLoss,FixedLotSize);
      LotSize = VerifyLotSize(LotSize);
      
      double Stoch_1 = iCustom(NULL,0,"StochHistogram",3,BarShift);
      double Stoch_2 = iCustom(NULL,0,"StochHistogram",3,BarShift+1);
      double Lag_1 = iCustom(NULL,0,"Laguerre-ACS1",3,BarShift);
      double Lag_2 = iCustom(NULL,0,"Laguerre-ACS1",3,BarShift + 1);

                // Begin trade block
                if(NewBar == true)
                        {   
                
                                // Buy order 
                                if(Stoch_1 > 0 && Stoch_2 < 0 && BuyMarketCount(Symbol(),MagicNumber) == 0)
                                        {
                                                // Close sell orders
                                                if(SellMarketCount(Symbol(),MagicNumber) > 0)
                                                        { 
                                                                CloseAllSellOrders(Symbol(),MagicNumber,Slippage);
                                                        }

                                                // Open buy order
                                                BuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber);
                                
                                                // Order modification
                                                if(BuyTicket > 0 && (StopLoss > 0 || TakeProfit > 0))
                                                        {
                                                                OrderSelect(BuyTicket,SELECT_BY_TICKET);
                                                                double OpenPrice = OrderOpenPrice();
                                
                                                                // Calculate and verify stop loss and take profit
                                                                double BuyStopLoss = CalcBuyStopLoss(Symbol(),StopLoss,OpenPrice);
                                                                if(BuyStopLoss > 0) BuyStopLoss = AdjustBelowStopLevel(Symbol(),BuyStopLoss,5);
                                        
                                                                double BuyTakeProfit = CalcBuyTakeProfit(Symbol(),TakeProfit,OpenPrice);
                                                                if(BuyTakeProfit > 0) BuyTakeProfit = AdjustAboveStopLevel(Symbol(),BuyTakeProfit,5);
                                        
                                                                // Add stop loss and take profit
                                                                AddStopProfit(BuyTicket,BuyStopLoss,BuyTakeProfit);
                                                        }  
                                        }
                
                
                                // Sell Order 
                                if(Stoch_1 < 0 && Stoch_2 > 0 && BuyMarketCount(Symbol(),MagicNumber) == 0)
                                        {
                                                if(BuyMarketCount(Symbol(),MagicNumber) > 0)
                                                        { 
                                                                CloseAllBuyOrders(Symbol(),MagicNumber,Slippage);
                                                        }

                                                SellTicket = OpenSellOrder(Symbol(),LotSize,UseSlippage,MagicNumber);
                                
                                                if(SellTicket > 0 && (StopLoss > 0 || TakeProfit > 0)) 
                                                        {
                                                                OrderSelect(SellTicket,SELECT_BY_TICKET);
                                                                OpenPrice = OrderOpenPrice();
                                        
                                                                double SellStopLoss = CalcSellStopLoss(Symbol(),StopLoss,OpenPrice);
                                                                if(SellStopLoss > 0) SellStopLoss = AdjustAboveStopLevel(Symbol(),SellStopLoss,5);
                                        
                                                                double SellTakeProfit = CalcSellTakeProfit(Symbol(),TakeProfit,OpenPrice);
                                                                if(SellTakeProfit > 0) SellTakeProfit = AdjustBelowStopLevel(Symbol(),SellTakeProfit,5);
                                        
                                                                AddStopProfit(SellTicket,SellStopLoss,SellTakeProfit);
                                                        }  
                                        }
                                
                        }  // End trade block 

So, can you please tell me what I did wrong with iCustom? Or is it something else?

I have attached the custom indicator below.

Thanks you so much!

If you have any questions about my code please ask.

Files:
 
Here is my other custom indicator.
Files:
 

read again the documentation how to use iCustom()

symbol - Symbol the data of which should be used to calculate indicator. NULL means current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
name - Custom indicator compiled program name.
... - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.
mode - Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
 
qjol:

read again the documentation how to use iCustom()

symbol - Symbol the data of which should be used to calculate indicator. NULL means current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
name - Custom indicator compiled program name.
... - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.
mode - Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).


Hey, thanks for the reply!

UPDATE: I got it to work. I finally figured out the buffers. I realized what they are FINALLY!