Download MetaTrader 5
To add comments, please log in or register
Publish your articles and improve your rating!
zavier
16
zavier 2014.08.06 06:33 

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);

                  }

               }

            }

         }

      }   

   } 

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.08.06 07:24  
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);

                  }

               }

            }

         }

      }   

   } 
zavier
16
zavier 2014.08.06 07:34  
deysmacro:


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

It makes your code easier to read.

 

whroeder1
13602
whroeder1 2014.08.06 12:30  
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.
zavier
16
zavier 2014.08.07 09:05  
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);

                  }

               }

            }

         }

      }   

   } 
zavier
16
zavier 2014.08.07 09:07  
So where can I reset my CurrentSignal after the thrail stop activated and took profit? Thanks.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.08.07 09:11  
You just need to do a loop for OrderHistory. If there is a new one, reset your CurrentSignal. Something like that.
zavier
16
zavier 2014.08.07 09:29  
Ok thanks deysmacro. Done :)
/
To add comments, please log in or register