how to end my ontick function after triggered

 

hi im trying to end the void ontick function just after my Stop Loss has been set. Sorry im a newbie and still learning.

Im using a strategy quaint moving average strategy and i want to add a trailing stop loss to the code. i think the only was is to end the void ontick function once the rule is completed..

please help of possible.


void OnTick() {



   sqInitStart();       

   

   sqManageOrders(MagicLong);

   

   openingOrdersAllowed = sqHandleTradingOptions();



   //------------------------

   // Rule: Trading signals

   //------------------------

        // init signals on every tick   

   LongEntrySignal = ((sqMA(NULL,0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, LongEMAShift+1) < sqMA(NULL,0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, LongEMAShift+1)) && (sqMA(NULL,0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, LongEMAShift) > sqMA(NULL,0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, LongEMAShift)));







                

   //------------------------

   // Rule: Long entry

   //------------------------

   if ((LongEntrySignal

      && (!(ShortEntrySignal))))

   {

      // Action #1

      sqClosePosition(OrderLots(), // size: SQ.Formulas.CloseSize.FullPosition

                    MagicShort, // magic number

                    "Current", // symbol

                    -1, // direction

                    "" // comment

       );



      // Action #2

      _ticket = sqOpenOrder(OP_BUY, "Current", mmLots, 0, MagicLong, "", 0, false, LongAllowDplTrd, CLR_NONE);



      if(_ticket > 0 && OrderSelect(_ticket, SELECT_BY_TICKET)) {

         // set or initialize all order exit methods (SL, PT, Trailing Stop, Exit After Bars, etc.)

         // StopLoss & ProfitTarget



         // ExitAfterBars initialization

         sqSetGlobalVariable(_ticket, "ExitAfterBars", LongExitAfterBars);

      }



  }



                

   //------------------------

   // Rule: Long - MoveSL2BE

   //------------------------

   if ((sqMarketPositionIsLong(MagicLong, "Current", "")

      && (sqGetBid("Current") >= (sqGetOrderOpenPrice("Current", MagicLong, 1, "") + sqConvertToRealPips("Current", MoveSL2BEAtPips)))))

   {

      // Action #1

      // Move SL to

      if(sqSelectOrder(MagicLong, "Current", 1, "")) {

         sqOrderModifySL(OrderTicket(), sqConvertToRealPips(OrderSymbol(), AddPipsToSL), SLPTTYPE_RANGE);

      }



  }



                

   //------------------------

   // Rule: Rule 4

   //------------------------

   if ((sqMarketPositionIsLong(MagicLong, "Current", "")

      && (sqGetBid("Current") >= (sqGetOrderOpenPrice("Current", MagicLong, 1, "") + sqConvertToRealPips("Current", tslactivation)))))

   {

      // Action #1

      // Move SL to

      if(sqSelectOrder(MagicLong, "Current", 1, "")) {

         sqOrderModifySL(OrderTicket(), sqConvertToRealPips(OrderSymbol(), tsl), SLPTTYPE_RANGE);

      }



  }



                

   return;

}
 
Daniel Sutherland:

hi im trying to end the void ontick function just after my Stop Loss has been set. Sorry im a newbie and still learning.

Im using a strategy quaint moving average strategy and i want to add a trailing stop loss to the code. i think the only was is to end the void ontick function once the rule is completed..

please help of possible.

I can't be bothered to read your code because of all the empty lines, you will find many people feel the same.

If you want the OnTick function to stop execution for that tick, then use

return;
 

Thanks mate i know i have to put return; there somewhere i have tried and tried.. too novice to know what i need to do, ive only just started to look at code..


Just trying to learn..

 
Daniel Sutherland:

hi im trying to end the void ontick function just after my Stop Loss has been set. Sorry im a newbie and still learning.

Im using a strategy quaint moving average strategy and i want to add a trailing stop loss to the code. i think the only was is to end the void ontick function once the rule is completed..

please help of possible.


when you post code use command Alt+S and insert your code properly and it will be easier readable!

code_insert

Always end your OnTick function as Keith wrote

void OnTick()
{
//-Do stuff here
//..
//..
return;//Stop
}
 
void OnTick() {
   sqInitStart();       
   sqManageOrders(MagicLong);   
   openingOrdersAllowed = sqHandleTradingOptions();
   //------------------------
   // Rule: Trading signals
   //------------------------
        // init signals on every tick   
   LongEntrySignal = ((sqMA(NULL,0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, LongEMAShift+1) < sqMA(NULL,0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, LongEMAShift+1)) && (sqMA(NULL,0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, LongEMAShift) > sqMA(NULL,0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, LongEMAShift)));              
   //------------------------
   // Rule: Long entry
   //------------------------
   if ((LongEntrySignal
      && (!(ShortEntrySignal))))
   {
      // Action #1
      sqClosePosition(OrderLots(), // size: SQ.Formulas.CloseSize.FullPosition
                    MagicShort, // magic number
                    "Current", // symbol
                    -1, // direction
                    "" // comment
       );
      // Action #2
      _ticket = sqOpenOrder(OP_BUY, "Current", mmLots, 0, MagicLong, "", 0, false, LongAllowDplTrd, CLR_NONE);

      if(_ticket > 0 && OrderSelect(_ticket, SELECT_BY_TICKET)) {
         // set or initialize all order exit methods (SL, PT, Trailing Stop, Exit After Bars, etc.)
         // StopLoss & ProfitTarget

         // ExitAfterBars initialization
         sqSetGlobalVariable(_ticket, "ExitAfterBars", LongExitAfterBars);
      }
  }               
   //------------------------
   // Rule: Long - MoveSL2BE
   //------------------------
   if ((sqMarketPositionIsLong(MagicLong, "Current", "")
      && (sqGetBid("Current") >= (sqGetOrderOpenPrice("Current", MagicLong, 1, "") + sqConvertToRealPips("Current", MoveSL2BEAtPips)))))
   {
      // Action #1
      // Move SL to
      if(sqSelectOrder(MagicLong, "Current", 1, "")) {
         sqOrderModifySL(OrderTicket(), sqConvertToRealPips(OrderSymbol(), AddPipsToSL), SLPTTYPE_RANGE);
      }              
return;//Stop
}
 

thanks for helping, much appreciated..


above ive entered return;//Stop with no luck,

maybe its in the wrong spot or im just clueless..


any hints..?


editor says

'}' - unexpected end of program DAN.mq4 6086 1


'{' - unbalanced parentheses DAN.mq4 155 15



 
Please use the code styler to properly align and indent your code. You'll find it under Tools - Styler or just hit Ctrl-, in MetaEditor. It will show you that you got a closing brace } missing somewhere in the OnTick function.
Reason: