Expert Adv. Help

 

Hello everybody;

i have a robot in my hand. i want to trailing stop in system but i cant do it. is there anyone who can help me?

Thanks...

//| day open_baris.mq4 |

//| Copyright 2014, MetaQuotes Software Corp. |

//| http://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2014, MetaQuotes Software Corp."

#property link "http://www.mql5.com"

#property version "2.00"

#property strict

extern double LOT=0.01;

extern int Profit=100;

extern int Stoploss=150;

int bars;

bool trade;

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

trade=false;

bars=iBars(Symbol(),PERIOD_M15);

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---



}

//+------------------------------------------------------------------+

//| Expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{
bool OrderSendResult;
// auto lot
int count = 1;
static double autoLot = LOT;
while(AccountBalance() > 100.0*count){
LOT = autoLot*count;
count++;
}

if (bars!=iBars(Symbol(),PERIOD_M15)){bars=iBars(Symbol(),PERIOD_M15);trade=true;}
/* Sizin Kodunuz
if (trade && tradingHour()){
if(iClose(NULL, PERIOD_M15, 1) > iClose(NULL, PERIOD_M15, 2)){ // Condition for buy order
OrderSend(Symbol(),OP_BUY,LOT,Ask,2,Bid-Stoploss*Point,0,NULL,0123456,0,clrRed);
}
else if(iClose(NULL, PERIOD_M15, 1) < iClose(NULL, PERIOD_M15, 2)){ // Condition for sell order
OrderSend(Symbol(),OP_SELL,LOT,Bid,2,Ask+Stoploss*Point,0,NULL,0123456,0,clrRed);
}
trade=false;
}
*/
// Düzeltilmis Kod
if (trade && tradingHour()){
if(iClose(NULL, PERIOD_M15, 1) > iClose(NULL, PERIOD_M15, 2)){ // Condition for buy order
OrderSendResult=OrderSend(Symbol(),OP_BUY,LOT,Ask,2,Bid-Stoploss*Point,Ask+Profit*Point,NULL,0123456,0,clrRed);
}
else if(iClose(NULL, PERIOD_M15, 1) < iClose(NULL, PERIOD_M15, 2)){ // Condition for sell order
OrderSendResult=OrderSend(Symbol(),OP_SELL,LOT,Bid,2,Ask+Stoploss*Point,Bid-Profit*Point,NULL,0123456,0,clrRed);
}
trade=false;
}

int tot=OrdersTotal();

for(int i=0; i<=tot;i++)

{
OrderSendResult=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol()==Symbol() &&OrderMagicNumber()==0123456)

{

if(OrderType()==OP_BUY){if (Bid>= OrderOpenPrice()+Profit*Point) OrderSendResult=OrderClose(OrderTicket(),LOT,Bid,2,clrAqua);}

if(OrderType()==OP_SELL){if (Ask<= OrderOpenPrice()-Profit*Point)OrderSendResult=OrderClose(OrderTicket(),LOT,Ask,2,clrAqua);}

}

}

}

//+------------------------------------------------------------------+

bool tradingHour(){
bool hour = false;
if(Hour() >= 11 && Minute() >= 00 && Hour() <=11 && Minute() < 15){
hour = true;
}
return hour;
}
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Ok. sorry...
 
Baris Kesgin:

Hello everybody;

i have a robot in my hand. i want to trailing stop in system but i cant do it. is there anyone who can help me?

Thanks...

https://www.mql5.com/en/code/18803

Tipu EA
Tipu EA
  • www.mql5.com
A simple EA based on Tipu Trend indicator and Tipu Stops indicator.
 

Mr. Mehmet;

What is this? You shared another robot. This is not the answer to my question. :)

 
Baris Kesgin:

Mr. Mehmet;

What is this? You shared another robot. This is not the answer to my question. :)

There is this expertte trailing stop example. for example

 

mmm yes i have saw this code in its other robot which is tipo_ea but When I encoded the existing code into the system, I encountered errors. so it was not successful.

Unfortunately :((

Reason: