ลองเปิด demo ดูการตัดมันนะครับแต่ก็น่าจะ ok แล้วหละ
extern double lot=0.1;
extern int magic=123;
extern bool UseTp=true;
extern int Tp=15;
extern bool UseSl=true;
extern int Sl =15;
extern bool UseTrailing=true;
extern int trailing =15;
extern int LessRsiDay=14;
extern int MuchRsiDay=49;
int temp;
int start()
{
double LessRsi =iRSI(NULL,0,LessRsiDay,PRICE_CLOSE,0);
double MuchRsi =iRSI(NULL,0,MuchRsiDay,PRICE_CLOSE,0);
int way= check(LessRsi,MuchRsi);
if(temp==0)
temp=way;
if(UseTp==false)
Tp=0;
if(UseSl==false)
Sl=0;
if(OrdersTotal()==0)
{
if(way==1 && temp==2)
{
if(Sl== 0 && Tp==0)
{
OrderSend(Symbol(),OP_BUY,lot,Ask,3,0,0,"dimdo",magic,0,Green);
}
if(Sl!= 0 && Tp==0)
{
OrderSend(Symbol(),OP_BUY,lot,Ask,3,Ask-Point*Sl,0,"dimdo",magic,0,Green);
}
if(Sl== 0 && Tp!=0)
{
OrderSend(Symbol(),OP_BUY,lot,0,0,"dimdo",magic,0,Green);
}
if(Sl!= 0 && Tp!=0)
{
OrderSend(Symbol(),OP_BUY,lot,Ask,3,Ask-Point*Sl,Ask+Point*Tp,"dimdo",magic,0,Green);
}
temp=1;
}
if(way==2 && temp==1)
{
if(Sl== 0 && Tp==0)
{
OrderSend(Symbol(),OP_SELL,lot,Bid,3,0,0,"dimdo",magic,0,Red);
}
if(Sl!= 0 && Tp==0)
{
OrderSend(Symbol(),OP_SELL,lot,Bid,3,Bid+Point*Sl,0,"dimdo",magic,0,Red);
}
if(Sl== 0 && Tp!=0)
{
OrderSend(Symbol(),OP_SELL,lot,Bid,3,0,Bid-Point*Tp,"dimdo",magic,0,Red);
}
if(Sl!= 0 && Tp!=0)
{
OrderSend(Symbol(),OP_SELL,lot,Bid,3,Bid+Point*Sl,Bid-Point*Tp,"dimdo",magic,0,Red);
}
temp=2;
}
}
if(UseTrailing==true)
trailingstop();
return(0);
}
int check (double v1 ,double v2)
{ static int lastway =0;
static int way =0;
if(v1 > v2)
{
way=1;
}
if(v1 < v2)
{
way=2;
}
if(way!= lastway)
{
lastway = way;
return (lastway);
}
return (0);
}
void trailingstop() {
for(int count=0;count<OrdersTotal();count++)
{OrderSelect(count,SELECT_BY_POS,MODE_TRADES);
if(OrderType() == OP_BUY)
{if(trailing > 0){
if(OrderStopLoss()==0 || (Bid - OrderStopLoss()> trailing*Point))
{
OrderModify(OrderTicket(), OrderOpenPrice(),Bid - trailing*Point, OrderTakeProfit(), 0, Blue);
}
}
}
if(OrderType() == OP_SELL)
{ if(trailing > 0)
{
if(OrderStopLoss() == 0 || ( OrderStopLoss()-Ask > trailing*Point ) )
{OrderModify(OrderTicket(), OrderOpenPrice(),Ask + trailing*Point, OrderTakeProfit(), 0, Red); }
}
}
}
}