How to change signal when SL is hit

 

Hi all,

I have a string CurrentSignal = "NONE";

I have my SL code.

So once I have a buy or sell signal it will activate the thrailing stop however, after it takes profit using thrailing stop I got no where to reset my CurrentSignal to "NONE".

How can I reset it?

 

CODE:

if(type==OP_BUY)

   {

      for(c=0;c<NumberOfTries;c++)

      {

         RefreshRates();

         if(stoploss!=0)

         {

            aStopLoss   = NormalizeDouble(Ask-stoploss*MyPoint,Digits);

            bStopLoss   = NormalizeDouble(Bid+stoploss*MyPoint,Digits);

         }

   

         if(takeprofit!=0)

         {

            aTakeProfit = NormalizeDouble(Ask+takeprofit*MyPoint,Digits);

            bTakeProfit = NormalizeDouble(Bid-takeprofit*MyPoint,Digits);

         }


         if(BrokerIsECN==false)ticket=OrderSend(Symbol(),OP_BUY,Lotzs,NormalizeDouble(Ask,Digits),Slippage,aStopLoss,aTakeProfit,TicketComment,MagicNumber,0,Green);

         if(BrokerIsECN==True)

         {

            ticket=OrderSend(Symbol(),OP_BUY,Lotz,NormalizeDouble(Ask,Digits),Slippage,0,0,TicketComment,MagicNumber,0,Green);

            if(ticket>0)

            {

               OrderSelect(ticket,SELECT_BY_TICKET);

               if(stoploss!=0)

               {

                  aStopLoss   = NormalizeDouble(OrderOpenPrice()-stoploss*MyPoint,Digits);

                  bStopLoss   = NormalizeDouble(OrderOpenPrice()+stoploss*MyPoint,Digits);

               }

   

               if(takeprofit!=0)

               {

                  aTakeProfit = NormalizeDouble(OrderOpenPrice()+takeprofit*MyPoint,Digits);

                  bTakeProfit = NormalizeDouble(OrderOpenPrice()-takeprofit*MyPoint,Digits);

               }

               if(aStopLoss>0 || aTakeProfit>0)

               {

                  if(OrderModify(ticket,OrderOpenPrice(),aStopLoss,aTakeProfit,0,Red)==false)

                  {

                     OrderModify(ticket,OrderOpenPrice(),aStopLoss,aTakeProfit,0,Red);

                  }

               }

            }

         }

      }   

   } 

 
Please use SRC.

if(type==OP_BUY)

   {

      for(c=0;c<NumberOfTries;c++)

      {

         RefreshRates();

         if(stoploss!=0)

         {

            aStopLoss   = NormalizeDouble(Ask-stoploss*MyPoint,Digits);

            bStopLoss   = NormalizeDouble(Bid+stoploss*MyPoint,Digits);

         }

   

         if(takeprofit!=0)

         {

            aTakeProfit = NormalizeDouble(Ask+takeprofit*MyPoint,Digits);

            bTakeProfit = NormalizeDouble(Bid-takeprofit*MyPoint,Digits);

         }


         if(BrokerIsECN==false)ticket=OrderSend(Symbol(),OP_BUY,Lotzs,NormalizeDouble(Ask,Digits),Slippage,aStopLoss,aTakeProfit,TicketComment,MagicNumber,0,Green);

         if(BrokerIsECN==True)

         {

            ticket=OrderSend(Symbol(),OP_BUY,Lotz,NormalizeDouble(Ask,Digits),Slippage,0,0,TicketComment,MagicNumber,0,Green);

            if(ticket>0)

            {

               OrderSelect(ticket,SELECT_BY_TICKET);

               if(stoploss!=0)

               {

                  aStopLoss   = NormalizeDouble(OrderOpenPrice()-stoploss*MyPoint,Digits);

                  bStopLoss   = NormalizeDouble(OrderOpenPrice()+stoploss*MyPoint,Digits);

               }

   

               if(takeprofit!=0)

               {

                  aTakeProfit = NormalizeDouble(OrderOpenPrice()+takeprofit*MyPoint,Digits);

                  bTakeProfit = NormalizeDouble(OrderOpenPrice()-takeprofit*MyPoint,Digits);

               }

               if(aStopLoss>0 || aTakeProfit>0)

               {

                  if(OrderModify(ticket,OrderOpenPrice(),aStopLoss,aTakeProfit,0,Red)==false)

                  {

                     OrderModify(ticket,OrderOpenPrice(),aStopLoss,aTakeProfit,0,Red);

                  }

               }

            }

         }

      }   

   } 
 
deysmacro:


Sorry I don't really know how to use SRC. Its Signal registration command right? how can i use it in my code? 
 

It makes your code easier to read.

 

 
roflshark: Sorry I don't really know how to use SRC. Its Signal registration command right? how can i use it in my code?
SRC = SouRce Code
Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it.
 
if(type==OP_BUY)
   {

      for(c=0;c<NumberOfTries;c++)

      {

         RefreshRates();

         if(stoploss!=0)

         {

            aStopLoss   = NormalizeDouble(Ask-stoploss*MyPoint,Digits);

            bStopLoss   = NormalizeDouble(Bid+stoploss*MyPoint,Digits);

         }

   

         if(takeprofit!=0)

         {

            aTakeProfit = NormalizeDouble(Ask+takeprofit*MyPoint,Digits);

            bTakeProfit = NormalizeDouble(Bid-takeprofit*MyPoint,Digits);

         }



         if(BrokerIsECN==false)ticket=OrderSend(Symbol(),OP_BUY,Lotzs,NormalizeDouble(Ask,Digits),Slippage,aStopLoss,aTakeProfit,TicketComment,MagicNumber,0,Green);

         if(BrokerIsECN==True)

         {

            ticket=OrderSend(Symbol(),OP_BUY,Lotz,NormalizeDouble(Ask,Digits),Slippage,0,0,TicketComment,MagicNumber,0,Green);

            if(ticket>0)

            {

               OrderSelect(ticket,SELECT_BY_TICKET);

               if(stoploss!=0)

               {

                  aStopLoss   = NormalizeDouble(OrderOpenPrice()-stoploss*MyPoint,Digits);

                  bStopLoss   = NormalizeDouble(OrderOpenPrice()+stoploss*MyPoint,Digits);

               }

   

               if(takeprofit!=0)

               {

                  aTakeProfit = NormalizeDouble(OrderOpenPrice()+takeprofit*MyPoint,Digits);

                  bTakeProfit = NormalizeDouble(OrderOpenPrice()-takeprofit*MyPoint,Digits);

               }

               if(aStopLoss>0 || aTakeProfit>0)

               {

                  if(OrderModify(ticket,OrderOpenPrice(),aStopLoss,aTakeProfit,0,Red)==false)

                  {

                     OrderModify(ticket,OrderOpenPrice(),aStopLoss,aTakeProfit,0,Red);

                  }

               }

            }

         }

      }   

   } 
 
So where can I reset my CurrentSignal after the thrail stop activated and took profit? Thanks.
 
You just need to do a loop for OrderHistory. If there is a new one, reset your CurrentSignal. Something like that.
 
Ok thanks deysmacro. Done :)