I want to figure out my error

 

here is the script I wanted it to loop all the way to get max profit but it seem that I overcharged it with functions or something

says stack overflow but I don't get where it's overloaded with functions (I seen lots of eas that does use way more functions then that and ran)

extern double threshold = 20;
int selection;
int tstype;
int tsprofit;
int tsticket;
double tstp;
double tssl;
double psl;
double slr = 0.6;
double tsopen;

int init()
   {
      return(0);
   }
int deinit()
   {
      return(0);
   }

int start()
   {
      if (OrdersTotal() != 0)
         {
            Trail();
         }
      else
         {
            Comment("No Orders To Manage.Waiting 30 minutes for more trades to open on",
                    "\n", syb);
            Sleep(1800000);
            return(0);
         }
   }
int Trail()
   {
      for (selection=0;selection<OrdersTotal();selection++)
         {
            OrderSelect(selection,SELECT_BY_POS,MODE_TRADES);
               {
                  tstp = OrderTakeProfit();
                  tssl = OrderStopLoss();
                  tsticket = OrderTicket();
                  tstype = OrderType();
                  tsprofit = OrderProfit();
                  tsopen = OrderOpenPrice();
                     if ((tstype == OP_SELL) && (tsprofit > threshold) && (tssl > tsopen))
                        {
                           OrderModify(tsticket, OrderOpenPrice(), tsopen, tstp, 0, Blue);
                        }
                     if ((tstype == OP_BUY) && (tsprofit > threshold) && (tssl < tsopen))
                        {
                           OrderModify(tsticket, OrderOpenPrice(), tsopen, tstp, 0, Blue);
                        }
               }
         }
      start();
   }

thanks to anyone that could help me out :)

 

Add "string syb = Symbol () ;" before "Comment (..) ;"

or change :

"Comment ( "No Orders To Manage.Waiting 30 minutes for more trades to open on", "\n", Symbol () ) ;"

 
Ais:

Add "string syb = Symbol () ;" before "Comment (..) ;"

or change :

"Comment ( "No Orders To Manage.Waiting 30 minutes for more trades to open on", "\n", Symbol () ) ;"


yes thanks but this is not the problem that causes it not to work properly tough :(
 

Delete invocation "start()" from "Trail()" that causes "stack overflow".

And change declaration "int tsprofit ;" to "double tsprofit ;"

And these declarftions are not used:
"double psl ;"
"double slr = 0.6 ;"

extern double threshold = 20 ;

int tsticket                 ;
int tstype                   ;

double tsprofit              ;
double tsopen                ;
double tssl                  ;
double tstp                  ;

int start()
{
    if ( OrdersTotal() != 0 )
         Trail () ;
    else 
      {  Comment("No Orders To Manage.Waiting 30 minutes for more trades to open on","\n", Symbol () ) ;
         Sleep  (1800000) ;
      }
}// start()
 
int Trail()
{
    for (int selection=0;selection<OrdersTotal();selection++)
        {
         OrderSelect(selection,SELECT_BY_POS,MODE_TRADES);

         tsticket = OrderTicket     () ;
         tstype   = OrderType       () ;

         tsprofit = OrderProfit     () ;
         tsopen   = OrderOpenPrice  () ;
         tssl     = OrderStopLoss   () ;
         tstp     = OrderTakeProfit () ;

         if ((tstype == OP_SELL) && (tsprofit > threshold) && (tssl > tsopen))
                    OrderModify(tsticket, OrderOpenPrice(), tsopen, tstp, 0, Blue);

         if ((tstype == OP_BUY ) && (tsprofit > threshold) && (tssl < tsopen))
                    OrderModify(tsticket, OrderOpenPrice(), tsopen, tstp, 0, Blue);

        }// for
}// Trail

or

extern double tsThreshold = 20 ;

int start()
{
    if ( OrdersTotal() == 0 ) { Comment ( "No Orders To Manage.Waiting 30 minutes for more trades to open on","\n", Symbol () ) ; Sleep  ( 1800000 ) ; }
    else Trail() ;

}// start
 
int Trail()
{
    for (int selection = 0 ; selection < OrdersTotal() ; selection++ )
        {
         OrderSelect ( selection, SELECT_BY_POS, MODE_TRADES ) ;

         double tsNewSL = OrderOpenPrice() ;

         if      ( ( OrderType() == OP_SELL) && ( OrderProfit() > tsThreshold ) && ( OrderStopLoss() > OrderOpenPrice() ) )
                     OrderModify ( OrderTicket(), OrderOpenPrice(), tsNewSL, OrderTakeProfit(), 0, Blue) ;

         else if ( ( OrderType() == OP_BUY ) && ( OrderProfit() > tsTthreshold ) && ( OrderStopLoss() < OrderOpenPrice() ) )
                     OrderModify ( OrderTicket(), OrderOpenPrice(), tsNewSL, OrderTakeProfit(), 0, Blue) ;

        }// for

}// Trail
 
Ais:

Delete invocation "start()" from "Trail()" that causes "stack overflow". <<<===========================

And change declaration "int tsprofit ;" to "double tsprofit ;"

And these declarftions are not used:
"double psl ;"
"double slr = 0.6 ;"

or

you got it man ! thank you very much :)
 
Always count down with modifying, deleting, closing in the presence of multiple order (multiple charts). Always check return codes
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol() ){              // and my pair.
        ....
        if (!OrderModify(...) ) Alert("OrderModify failed: ",GetLastError());