[langtitle=en]please help[/langtitle]
[lang=en]Why just sell trading opens, please help
//+------------------------------------------------------------------+
//| Masterforex-V3_bot.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Kostefan"
#property link "_http://forum.masterforex-v.org
#include <stderror.mqh>
#include <stdlib.mqh>
extern int ADXbars=1.0;
extern int CountBars=5000;
extern int StopLoss=0;
extern int TakeProfit=0;
extern int TrailingStop=3;
extern double Lots=0.01;
extern int Slippage=3;
extern int MagicNumber = 24212;
double SL,TP;
int bars_p,
trades_per_bar;
int init()
{
bars_p=Bars;
return;
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int Signal=0;
if(iCustom(NULL,0,"Signal v3 Masterforex-v",ADXbars,CountBars,0,1)!=EMPTY_VALUE) Signal=1;
if(iCustom(NULL,0,"Signal v3 Masterforex-v",ADXbars,CountBars,1,1)!=EMPTY_VALUE) Signal=-1;
int bars_c=Bars;
if(bars_p!=bars_c)
trades_per_bar=0;
bars_p=bars_c;
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(Signal<0)
{
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage);
return(0);
}
if(TrailingStop>0 && Bid-OrderOpenPrice()>(TrailingStop+0.1)*Point
&& Bid-OrderStopLoss()>(TrailingStop+0.1)*Point)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0);
return(0);
}
}
if(OrderType()==OP_SELL)
{
if(Signal>0)
{
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage);
return(0);
}
if(TrailingStop>0 && OrderOpenPrice()-Ask>(TrailingStop+0.1)*Point
&& (OrderStopLoss()-Ask>(TrailingStop+0.1)*Point || OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0);
return(0);
}
}
}
}
{
if(Signal>0)
{
SL=0;TP=0;
if(StopLoss>0) SL=Ask-Point*StopLoss;
if(TakeProfit>0) TP=Ask+Point*TakeProfit;
int open=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,WindowExpertName(),MagicNumber,0,Blue);
if(open>0)
trades_per_bar++;
return(0);
}
if(Signal<0)
{
SL=0;TP=0;
if(StopLoss>0) SL=Bid+Point*StopLoss;
if(TakeProfit>0) TP=Bid-Point*TakeProfit;
open=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,WindowExpertName(),MagicNumber,0,Red);
if(open>0)
trades_per_bar++;
return(0);
}
}
return(0);
}[/lang]