Help me please. Traling Stop

Back to topics list To post a new topic, please log in or register
avatar
1
ProdigyID 2015.10.03 14:59
 

input double SIFNOKBUY=1.10011; //*BUY FIYATI
input double SIFNOKSELL=1.10011; //*SELL FIYATI
input double BASLOT=0.01; //*BAŞLAMA LOTU
input double KLA=0.01; //*KADEME LOT ARTIMI
input int PIP=50; //*KADEME PIP DEGERI
input int Slippage=0; //*ELLEME
input int STOPLOSS=0;
input int TAKEPROFIT=100;
input double TrailingStop = 35;//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{

return(0);
}
//+-------------------S-----------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{




return(0);
}

int gMagicNumber=1;
int gMagicNumber1=2;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{



bool Trade1 = false;
bool Trade2 = false;


for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_PO S))
continue;
if(OrderSymbol()!=Symbol())
continue;
if(OrderMagicNumber()==gMagicN umber)
{
Trade1=true;
continue;
}
if(OrderMagicNumber()==gMagicN umber1)

Trade2=true;

}
if(TrailingStop>0)
{
OrderSelect(1,SELECT_BY_TICKET );
if(Bid-OrderOpenPrice()>Point*Trailin gStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
bool res=OrderModify(OrderTicket(), OrderOpenPrice(),NormalizeDoub le(Bid-Point*TrailingStop,Digits),Ord erTakeProfit(),0,Blue);
if(!res)
Print("Error in OrderModify. Error code=",GetLastError());
else
Print("Order modified successfully.");
}
}
}


if(!Trade2) 

OrderSend(Symbol(),OP_SELL,BAS LOT,Bid,Slippage,STOPLOSS,Bid-TAKEPROFIT*Point,"1.KADEME",2, 0,clrRed);

if(!Trade1)

OrderSend(Symbol(),OP_BUY,BASL OT,Ask,Slippage,STOPLOSS,Ask+T AKEPROFIT*Point,"1.KADEME",1,0 ,clrYellow);






return;
}

Traling stop not run. What is the problem? i not see help me please.  thank you

avatar
120
DeanDeV 2015.10.04 22:25 #
 

Use SRC button for code 

What are your errors being printed? 

avatar
Moderator
3419
GumRai 2015.10.04 23:55 #
 
OrderSelect(1,SELECT_BY_TICKET );

There is unlikely to be an order with the ticket number#1 except in the tester and then only a single order.

 

Maybe better to use int instead of bools 

   int Trade1 = 0;
   int Trade2 = 0;


   for(int i=0; i<OrdersTotal(); i++)
     {
      if(!OrderSelect(i,SELECT_BY_POS))
         continue;
      if(OrderSymbol()!=Symbol())
         continue;
      if(OrderMagicNumber()==gMagicNumber)
        {
         Trade1=OrderTicket();
         continue;
        }
      if(OrderMagicNumber()==gMagicNumber1)
         Trade2=OrderTicket();
     }

 Then

   if(TrailingStop>0)
     {
      if(Trade1>0 && OrderSelect(Trade1,SELECT_BY_TICKET));
        {
         //Code to check trailing stop
        }
      if(Trade2>0 && OrderSelect(Trade2,SELECT_BY_TICKET));
        {
         //Code to check trailing stop
        }
     }

.... 


Back to topics list  

To add comments, please log in or register