how should fix this error(int -name expected) while compiling this code and (unbalance parenthesis)

 
//+------------------------------------------------------------------+
//|                                                trailing stop.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"
#property strict

extern double TrailingStart = 50;
extern double TrailingStop = 25;
extern double TrailingStep = 5;

double vPoint; 
int vSlippage;
int MagicNumber = 11111,


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int  OnInit()
  { 
//---
   Alert("Trailing started");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit
  {
//---
   Alert("Trailing started");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   double TrailOrder(double Trailingstart,double Trailingstop)

   {  
   int ticket = 0;


   double tStopLoss = NormalizeDouble(OrderStopLoss(), Digits); // Stop Loss

   int cnt, vPoint, vSlippage;
   
   
   double sl     = OrderStopLoss(); // Stop Loss

   if (Digits == 3 || Digits == 5)
    {
     vPoint = Point * 10; 
    
    vSlippage = Slippage * 10; 
    }
    else
    {
    vPoint = Point; 
    
    vSlippage = Slippage;
    }

 
   RefreshRates();
   
   if(OrdersTotal()>0)
   {
   for(cnt=OrdersTotal();cnt>=0;cnt --)
   {
   OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
   
   if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()&& OrderMagicNumber()==MagicNumber)
   
   {

   if(OrderType()==OP_BUY)
   {
   if(Ask> NormalizeDouble(OrderOpenPrice()+TrailingStart* vPoint,Digits) && tStopLoss < NormalizeDouble(Bid-(TrailingStop+TrailingStep)*vPoint,Digits))
   {
   tStopLoss = NormalizeDouble(Bid-TrailingStop*vPoint,Digits);
   
   ticket = OrderModify(OrderTicket(),OrderOpenPrice(),tStopLoss,OrderTakeProfit(),0,Blue);
   
   if (ticket > 0)
   {
   Print ("TrailingStop #2 Activated: ", OrderSymbol(), ": SL", tStopLoss, ": Bid", Bid);
   return(0);
}}}

   if (OrderType()==OP_SELL) 
   {
   if (Bid < NormalizeDouble(OrderOpenPrice()-TrailingStart*vPoint,Digits)&& (sl >(NormalizeDouble(Ask+(TrailingStop+TrailingStep)*vPoint,Digits)))|| (OrderStopLoss()==0))
   {
   tStopLoss = NormalizeDouble(Ask+TrailingStop*vPoint,Digits);
   
   ticket = OrderModify(OrderTicket(),OrderOpenPrice(),tStopLoss,OrderTakeProfit(),0,Red);
   
   if (ticket > 0)
   {
   Print ("Trailing #2 Activated: ", OrderSymbol(), ": SL ",tStopLoss, ": Ask ", Ask);
   return(0);
   }
   }
   }
 
   }
   }
   }
   }
  
//+------------------------------------------------------------------+

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2022.07.30
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

That code seems so messed up! Why declare a function "TrailOrder" inside the OnTick function and why call OrderStopLoss before selecting an order...That doesn't make sense to me.


The error about int can be fixed with "int MagicNumber = 11111;


OnDeinit function should have an argument...

 
Nelson3056:

No easy fix - I suggest you generate a new file and then start pasting small sections of code across, compiling/fixing as you go.

 
I suppose you try different styles from settings. With some, the brackets are in a rectangular order meeting on the top left corner of the code block they belong to (Java or Google Style for example). For some people it is easier than counting ten brackets in a straight line over and over.
 
R4tna C #:

No easy fix - I suggest you generate a new file and then start pasting small sections of code across, compiling/fixing as you go.

Thank you very much
 
Tobias Johannes Zimmer #:
I suppose you try different styles from settings. With some, the brackets are in a rectangular order meeting on the top left corner of the code block they belong to (Java or Google Style for example). For some people it is easier than counting ten brackets in a straight line over and over.
Thanks really appreciate your help
 
void OnTick()
  {
//---

   double TrailOrder(double Trailingstart,double Trailingstop)

   {  
You can not define a function inside another function.
 
Thanks for the help.