ผมต้องการให้มันตั้ง sl tp ทุกคู่เงินครับ ปัญหาก็คือ บางคู่เงินทศนิยม 3 จุด บางคู่เงินทศนิยม 5 จุด
แต่เราจะเอาอีเอใส่เพียงกราฟเดียว ผมไปต่อไม่ถูกครับ ช่วยแนะนำให้ด้วยครับ
//+------------------------------------------------------------------+
//| EA for Set TP-SL.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
int order_total;
int cb = 0;
int cs = 0;
int cbs = 0;
int css = 0;
int ticket_b;
int ticket_s;
double op_b;
double op_s;
extern int SL = 100;
extern int TP = 100;
extern int Trailling = 100;
int init()
{
return(0);
}
int start()
{
order_total = OrdersTotal();
cb = false;
cs = false;
cbs = false;
css = false;
for(int i = order_total; i >= 0; i--){
if(OrderSelect(i,SELECT_BY_POS) == true && OrderSymbol() == Symbol()){
if(OrderType() == OP_BUY){
cb = true;
ticket_b = OrderTicket();
op_b = NormalizeDouble(OrderOpenPrice(), Digits);
Modify_order();
Modify_Trailling();
}
if(OrderType() == OP_SELL){
cs = true;
ticket_s = OrderTicket();
op_s = NormalizeDouble(OrderOpenPrice(), Digits);
Modify_order();
Modify_Trailling();
}
}
}
return(0);
}
void Modify_order() {
if (cb == TRUE) {
if(OrderStopLoss()==0 && OrderTakeProfit()==0){
bool tic1= OrderModify(ticket_b, 0, op_b-SL*Point, op_b+TP*Point, 0, 0);
}
}
if (cs == TRUE) {
if(OrderStopLoss()==0 && OrderTakeProfit()==0){
bool tic2= OrderModify(ticket_s, 0, op_s+SL*Point, op_s-TP*Point, 0, 0);
}
}
}
void Modify_Trailling()
{
for(int cnt=OrdersTotal();cnt>=0;cnt--)
{
int result2 = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && Trailling!=0)
{
if (OrderType()==OP_SELL)
{
if (OrderOpenPrice()-Ask>=Trailling*Point)
{
if (OrderStopLoss()>Ask+Point*Trailling || OrderStopLoss()==0)
{
bool tic1 = OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*Trailling,OrderTakeProfit(),0,clrPurple);
//return(0);
}
}
}
if (OrderType()==OP_BUY)
{
if (Bid-OrderOpenPrice()>=Trailling*Point)
{
if ( OrderStopLoss() < Bid-Point*Trailling )
{
bool tic2 = OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Trailling*Point,OrderTakeProfit(),0,clrYellow);
//return(0);
}
}
}
}
}
}