First Script, I need to update indefinitely SL

 

Hi there,


Im a noob here, and Im tryng my first script. But i got a problem this script finished when I dont want. 


OK, my idea is:


1. The script open trade with stop loss

2. The script will update that stop loss if price move in the direcction of purchase.


I got to make the purchase, but then script ends and not done anything else. I suppose I need some instruction to the script running in the background indefinitely.... until next update of the SL.


This is my code.


int start()

  {

//----

    //Open trade

    OrderSend(Symbol(),OP_SELL,0.1,Bid,1,Bid+7*Point,0); 


    for(int i=1; i<=OrdersTotal(); i++)          

      {

        if (OrderSelect(i-1,SELECT_BY_POS)==true) 

          {            

            OrderPrint();                           

            int    Tip=OrderType();                 

            int    Ticket=OrderTicket();            

            double Price=OrderOpenPrice();        

            double SL;                           

       

            while(true)                       

              {                

                switch(Tip)                         

                  {

                    case 0 :                            

                         if (Ask <= Price-2*Point)     

                           {

                             SL=Price;

                             

                             if(OrderModify(Ticket,OrderOpenPrice(),SL,OrderTakeProfit(),0)==false)  //To update

                               {

                                 return(-3);

                               }

                           }

                         break;                        

                  }                                

                break;                            

              }   

              OrderPrint();                                

           }                                      

        }                                  

//----

   return(0);

  }



Guys i need some help.


Thanks for your time.

 
I would gear more towards an EA ("Expert Adviser") rather than a script. Scripts are good for for 1-offs. EA's are used for ongoing. You can use both in tandem.