السلام عليكم ورحمة الله وبركاتة
استاذي مستر دولار
قمت باضافة دالة التريلينج استوب الى اكسبيرت اوامر معلقة
لكن لا يعمل معي التريلنج استوب
الرجاء تفسير ماهي المشكلة
كود:
extern double Distance_Between_Price_And_Order =15;
extern int Take_Profit = 50;
extern int Stop_loss = 50;
extern double Manual_Lot = 0.1;
extern int Magic_Number = 1234;
extern int TrailingStop=20;
extern int TrailingStep=10;
double point;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
if(Digits==3||Digits==5)point=10; else point=1;
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(TrailingStop>0)MoveTrailingStop();
//--//
double BuyPrice=Ask + Distance_Between_Price_And_Order*point*Point;
double BuySL=BuyPrice-Stop_loss*point*Point;
double BuyTP=BuyPrice+Take_Profit*point*Point;
double SellPrice=Bid - Distance_Between_Price_And_Order*point*Point;
double SellSL=SellPrice+Stop_loss*point*Point;
double SellTP=SellPrice-Take_Profit*point*Point;
//--//
if(OrdersTotal() == 0)
{
bool asd=OrderSend(Symbol(),OP_BUYSTOP,Manual_Lot,BuyPrice,5,BuySL,BuyTP,NULL,Magic_Number,0,Green);
bool ads=OrderSend(Symbol(),OP_SELLSTOP,Manual_Lot,SellPrice,5,SellSL,SellTP,NULL,Magic_Number,0,Red);
}
///////////////
}
//+------------------------------------------------------------------+
void MoveTrailingStop()
{
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic_Number)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0&&NormalizeDouble(Ask,Digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*point,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailingStop*point,Digits))||(OrderStopLoss()==0))
{
bool action=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*point,Digits),OrderTakeProfit(),0,Blue);
}
}
}
else
{
if(TrailingStop>0&&NormalizeDouble(Bid,Digits)<NormalizeDouble(OrderOpenPrice()-TrailingStop*point,Digits))
{
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+TrailingStop*point,Digits)))||(OrderStopLoss()==0))
{
bool action=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*point,Digits),OrderTakeProfit(),0,Red);
}
}
}
}
}
}