Template for MQL4 Indicator to EA

 

Hello Everyone,

Please help me make a template for indicator to EA i tried something but it didn't work and i am getting errors with this code

template which i have


//+------------------------------------------------------------------+

//|                                                   MACDCustom.mq4 |

//|                        Copyright 2022, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2022, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"


input int  InpTakeProfitPts   = 100;     //Take Profit points

input int  InpStopLossPts     = 100;     //Stop Loss Points


//---MACD indicator parameters

input int InpFastEMA=12;   // Fast EMA Period

input int InpSlowEMA=26;   // Slow EMA Period

input int InpSignalSMA=9;  // Signal SMA Period


input double InpOrderSize     = 0.01;    //Order Size

input string InpTradeComment  = __FILE__;  // Trade Comment

input int    InpMagicNumber   = 2000001; //Magic number


double   TakeProfit;  //After conversion from points

double   StopLoss;


//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---

   double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT);

   TakeProfit   = InpTakeProfitPts * point;

   StopLoss     = InpStopLossPts * point;

   

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {

//---

   //

   // Where this is to only run once per bar

   //

   if(!NewBar()) return;

   

   //

   //Perform any calculations and analysis here

   //

   

   //

   //Execute the strategy here

   //

   bool buyCondition  = false;

   bool sellCondition = false;

   

   if(buyCondition) {

   OrderOpen (ORDER_TYPE_BUY, StopLoss, TakeProfit);

   } else

   if (sellCondition) {

   OrderOpen (ORDER_TYPE_SELL, StopLoss, TakeProfit);

   }

   

   //

   // Save any information for next time

   //

    

   return;

   

   }

   

   

  bool NewBar() {

  

  static datetime  prevTime  = 0;

  datetime         currentTime = iTime (Symbol(), Period (), 0);

  if (currentTime!=prevTime) {

  prevTime = currentTime;

  return(true);

  }

  return(false);

}

  

bool OrderOpen (ENUM_ORDER_TYPE orderType, double stopLoss, double takeProfit) {

   int         ticket;

   double      openPrice;

   double      stopLossPrice;

   double      takeProfitPrice;

   

   if (orderType==ORDER_TYPE_BUY) {

   openPrice         = SymbolInfoDouble(Symbol(), SYMBOL_ASK);

   stopLossPrice     = openPrice - stopLoss;

   takeProfitPrice   = openPrice + takeProfit;

   } else

   if (orderType==ORDER_TYPE_SELL) {

   openPrice         = SymbolInfoDouble(Symbol(), SYMBOL_BID);

   stopLossPrice     = openPrice + stopLoss;

   takeProfitPrice   = openPrice - takeProfit;

   } else

   return (false);

   }

   

   ticket = OrderSend(Symbol(), orderType, InpOrderSize, openPrice, 0, stopLossPrice, takeProfitPrice, InpTradeComment, InpMagicNumber);

     

  return(ticket>0);

  }


//+------------------------------------------------------------------+


Errors i am getting

I am just getting so much errors in the last ticket line please help me figure that out please

1) ticket - unexpected token, probably type is missing ?

2) orderType - undeclared identifier

3) openPrice - undeclared identifier

4) stopLossPrice -undeclared identifier

5) takeProfitPrice -undeclared identifier

6) return - expression are not allowed on a global scope

7) '}' - expressions are not allowed on a global scope and these are warnings

1) declaration of 'orderType' hides global variable

2) see previous declaration of 'orderType'

3) declaration of 'ticket' hides global variable

4) see previous declaration of 'ticket'

5) declaration of 'openPrice' hides global variable

6) see previous declaration of 'openPrice'

7)declaration of 'stopLossPrice' hides global variable

8) see previous declaration of 'stopLossPrice'

9)declaration of 'takeProfitPrice' hides global variable

10) see previous declaration of takeProfitPrice'

11) variable 'ticket' is not used

12) not all control paths return a value


 
Use the </> button to insert your code please.
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2.  } else
       return (false);
       }
       
       ticket = OrderSend
    The last close bracket terminates the function.