break-even script - needs help

 

Hi. The break-even scrip (that I want to insert into my EA) works for the buy orders, but doesn't work for the sell orders. Can anyone tell me why? Did I miss something?

// Breakeven / stoploss

void TrP()

{ double pb,pa,pp;
pp=MarketInfo(OrderSymbol(),MODE_POINT);

if(OrderType()==OP_BUY)
{ pb=MarketInfo(OrderSymbol(),MODE_BID);
if(BE>0)
{ if((pb-OrderOpenPrice())>BE*pp)
{ if((OrderStopLoss()-OrderOpenPrice())<0)
{ ModSL(OrderOpenPrice()+0*pp);
return; }}}}

if(OrderType()==OP_SELL)
{ pa=MarketInfo(OrderSymbol(),MODE_ASK);
if(BE>0)
{ if((pa-OrderOpenPrice())<BE*pp)
{ if((OrderStopLoss()-OrderOpenPrice())>0)
{ ModSL(OrderOpenPrice()-1*pp);
return; }}}}}

void ModSL(double ldSL)
{ bool fm; fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}

 
pipen:

Hi. The break-even scrip (that I want to insert into my EA) works for the buy orders, but doesn't work for the sell orders. Can anyone tell me why? Did I miss something?

// Breakeven / stoploss

void TrP()

{ double pb,pa,pp;
pp=MarketInfo(OrderSymbol(),MODE_POINT);

if(OrderType()==OP_BUY)
{ pb=MarketInfo(OrderSymbol(),MODE_BID);
if(BE>0)
{ if((pb-OrderOpenPrice())>BE*pp)
{ if((OrderStopLoss()-OrderOpenPrice())<0)
{ ModSL(OrderOpenPrice()+0*pp);
return; }}}}

if(OrderType()==OP_SELL)
{ pa=MarketInfo(OrderSymbol(),MODE_ASK);
if(BE>0)
{ if((pa-OrderOpenPrice())<BE*pp)
{ if((OrderStopLoss()-OrderOpenPrice())>0)
{ ModSL(OrderOpenPrice()-1*pp);
return; }}}}}

void ModSL(double ldSL)
{ bool fm; fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}


Use SRC button for insert code in your messages


// Breakeven / stoploss


void TrP()

{ double pb,pa,pp;
pp=MarketInfo(OrderSymbol(),MODE_POINT);

if(OrderType()==OP_BUY)
{ pb=MarketInfo(OrderSymbol(),MODE_BID);
if(BE>0)
{ if((pb-OrderOpenPrice())>BE*pp)
{ if((OrderStopLoss()-OrderOpenPrice())<0)
{ ModSL(OrderOpenPrice()+0*pp);
return; }}}}

if(OrderType()==OP_SELL)
{ pa=MarketInfo(OrderSymbol(),MODE_ASK);
if(BE>0)
{ if((pa-OrderOpenPrice())<BE*pp)
{ if((OrderStopLoss()-OrderOpenPrice())>0)
{ ModSL(OrderOpenPrice()-1*pp);
return; }}}}}

void ModSL(double ldSL)
{ bool fm; fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}

your error

if(OrderType()==OP_SELL)
   { 
    pa=MarketInfo(OrderSymbol(),MODE_ASK);
    if(BE>0)
       { 
//      if((pa-OrderOpenPrice())<BE*pp)            //at opening trade this is already true
        if((OrderOpenPrice()-pa)>BE*pp)  //change it in
          { 
           if((OrderStopLoss()-OrderOpenPrice())>0)
             { 
              ModSL(OrderOpenPrice()-1*pp);
              return; 
             }
          }
       }
   }

at opening trade you open

at bid or ask that distant is spread i think it should be your breakeven is bigger then the spread