Hello Forum!
I'm trying to code a very simple EA which opens a trade when the new / next candle occurs + TS .
Part of the code is working as I want and new trades are opening fine but TS simply doesn't work.
I was wondering if somebody would be so kind and help me fixing this code ?
I'm trying to code a very simple EA which opens a trade when the new / next candle occurs + TS .
Part of the code is working as I want and new trades are opening fine but TS simply doesn't work.
I was wondering if somebody would be so kind and help me fixing this code ?
Code:
#property strict
input double lot = 0.07; // lot
input int slippage = 10; // max slippage
input int TP=1000; // Take Profiti
input int SL=55; // Stop Loss
input int MagicNumber=100; // Magic Number
extern bool ProfitTrailing = True;
extern int TrailingStop = 20;
extern int TrailingStep = 10;
extern bool UseSound = True;
extern string NameFileSound = "expert.wav";
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
void start() {
for (int i=0; iTrailingStop*pp) {
if (OrderStopLoss()TrailingStop*pp) {
if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) {
ModifyStopLoss(pAsk+TrailingStop*pp);
return;
}
}
}
}
//+------------------------------------------------------------------+
//| |
//| : |
//| StopLoss |
//+------------------------------------------------------------------+
void ModifyStopLoss(double ldStopLoss) {
bool fm;
fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
if (fm && UseSound) PlaySound(NameFileSound);
}
datetime tlast;
int OnInit()
{
tlast = INT_MAX;
return INIT_SUCCEEDED;
}
void OnTick()
{
if(Time[0] > tlast)
{
if(Open[1] >= Close[1])
bool res = OrderSend(Symbol(),OP_SELL,lot,Bid,slippage,Bid+SL*Point,Bid-TP*Point,NULL,MagicNumber,0);
else
if(Open[1] <= Close[1])
bool res = OrderSend(Symbol(),OP_SELL,lot,Bid,slippage,Bid+SL*Point,Bid-TP*Point,NULL,MagicNumber,0);
}
tlast = Time[0];
}