Transferring Indicator Code to an EA but where to put my trade operations?

 

I'm in the process of completing my first complex EA and I'm not 100% sure that I have inserted my Trade Logic Operations in the proper area. All this EA does is look for the cross of the TDI(RSI Signal Line & RSI Price Line). I imported the actual code that retrieves the 2 TDI values(Signal Line/Price Line) from the "TDI Red Green Indicator" and by going through the Article "Transferring an Indicator Code into an EA code" I'm hopeful that I ported everything over properly. Since the biggest adjustment was the Indicators Buffers Emulation along with replacing IndicatorCounted(). The explanation was fairly straightforward and a significant portion of the housekeeping duties I just copied over directly. However, I'm having problems understanding where I put my actual Trade Operations. Since Indicators are meant to display graphical representations of the data array I understand the idea of traversing through the indicator buffers in order to output to the Terminal. However in EA's my understanding is that I am for the most part looking at the current (0) bar checking for my optimal conditions(Crossovers) in order to execute my trade. I decided not to use the iCustom() function in this EA for the reasons stated in the article. Thus the question, where do I make my trade operations(see lower half of code)?

All helpful replies, I thank You in Advance!

My Current Source Code

//declare the external variable
// External variables
extern double LotSize      = 0.1;
extern double StopLoss     = 50;
extern double TakeProfit   = 100;

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

extern int RSI_Period         = 13;         
extern int RSI_Price          = 0;           
extern int Volatility_Band    = 34;    
extern int RSI_Price_Line     = 2;      
extern int RSI_Price_Type     = 0;      
extern int Trade_Signal_Line  = 7;   
extern int Trade_Signal_Type  = 0;   

// declare the global variables
int      BuyTicket;
int      SellTicket;
double   UsePoint;
int      UseSlippage;

//These are my Indicator Buffers
double   RSIBuf[],MaBuf[],MbBuf[];

//---- DECLARING VARIABLES FOR CHOOSING A CHART
string symbol; int timeframe;

//+-----------------------------------------------------------------------------------------+
// Init function
int init()
        {
      //---- CHOOSING A CHART FOR INDICATOR CALCULATION
      symbol = Symbol();   //INITIALIZATION OF THE VARIABLE symbol;
      timeframe =60;       //INITIALIZATION OF THE VARIABLE timeframe;
      
      return(0);
        }
//+-----------------------------------------------------------------------------------------+
// Start function
int start()
        {
           // GETTING THE AMOUNT OF ALL BARS OF THE CHART
      int IBARS = iBars(symbol, timeframe);
           //-- Checking whether the bars number is enough for further calculation
           if(Bars < RSI_Period)
       return(0);
           
           //---- INDICATOR BUFFERS EMULATION
      if(ArraySize(RSIBuf) < Bars)
     {
       ArraySetAsSeries(RSIBuf, false);
       ArraySetAsSeries(MaBuf, false);
       ArraySetAsSeries(MbBuf, false);
       //----  
       ArrayResize(RSIBuf, Bars); 
       ArrayResize(MaBuf, Bars); 
       ArrayResize(MbBuf, Bars); 
       //----
       ArraySetAsSeries(RSIBuf, true);
       ArraySetAsSeries(MaBuf, true);
       ArraySetAsSeries(MbBuf, true); 
     } 
      // INSERTION OF A STATIC INTEGER MEMORY VARIABLE
      static int IndCounted;
      //----+ Insertion of variables with a floating point
      double Resalt0, Resalt1, Resalt2;
      //----+ Insertion of integer variables and GETTING ALREADY CALCULATED BARS
      int limit, MaxBar, bar, counted_bars = IndCounted;
      //----+ REMEMBERING THE AMOUNT OF ALL BARS OF THE CHART
      IndCounted = IBARS - 1;
      //---- defining the number of the oldest bar,   
      //     starting from which new bars will be recalculated
      limit = IBARS - counted_bars - 1; 
      //---- defining the number of the oldest bar, 
      //     starting from which new bars will be recalculated
      MaxBar = IBARS - 1 - (RSI_Period); 
      //---- initialization of zero 
      if(limit > MaxBar)
         {
         limit = MaxBar;
         for(bar = IBARS - 1; bar >= 0; bar--)
            {
            RSIBuf[bar] = 0.0;
            MaBuf[bar] = 0.0;
            MbBuf[bar] = 0.0;
            }
         }
      //----+ THE FIRST CYCLE OF INDICATOR CALCULATION   
      for(bar = limit; bar >= 0; bar--)
            {
               
               RSIBuf[bar] = (iRSI(NULL,0,RSI_Period,RSI_Price,bar)); 
               //PriceLine Buffer
               MaBuf[bar] = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,bar));
               //TradeLine Buffer
               MbBuf[bar] = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,bar));               
               
               //Check to see if the PriceLine has Crossed the TradeSignalLine Up or Down
               if (MaBuf[bar] > MbBuf[bar]) {
                  //*************************************
                  //*************************************
                  // Long Trade Operations here
                  //*************************************
                  //*************************************
                  }
               else if (MaBuf[bar] < MbBuf[bar]) {
                  //*************************************
                  //*************************************
                  // Short Trade Operations here
                  //*************************************
                  //*************************************
                  }   
               
            }
                
                return(0);
        }
 

I would say just before . . .

return(0);
 
  1. Article "Transferring an Indicator Code into an EA code"
    I didn't see anything overly wrong except you need this form:
    int IndCounted;
    int init(){ IndCounted = 0; }
    :
          limit = IBARS - IndCounted - 1; 
          for(int bar = limit; bar >= 0; bar--){ 
              :
          }
          IndCounted = IBARS - 1; // All bars done except bar 0.
    

  2. where do I make my trade operations
    After the FOR loop, not inside.
 

RaptorUK & WHRoeder, your expertise is very much appreciated! I will try your recommendations.

Thank You Again.

Reason: