Tight_Trailing_Stops
Tight_Trailing_Stops

Tight_Trailing_Stops

更新日期:
2022-10-26
分类标签:
语言:
中文
平台:
没限制

26 人已下载 手机查看

Tight_Trailing_Stops

//+——————————————————————+
//| Tight Trailing Stops.mq4 |
//| Nicholishen |
//| www.tradingintl.com |
//+——————————————————————+
#property copyright “Nicholishen”
#property link “www.tradingintl.com”

#define OrderID 1928378

extern bool UseTightStop=false;
extern int ScalpPips=3;
extern bool UseTrailing = false;

extern double TrailingAct = 6;
extern double TrailingStep = 3;
int TrailPrice;

void TrailingPositions() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() ) {
if (OrderType()==OP_SELL) {
if (OrderOpenPrice()-Ask>TrailingAct*Point && TrailPrice ==0) {
TrailPrice=Ask+TrailingStep*Point;
Print(“TRAIL PRICE SET: “,TrailPrice);
if(TrailingStep > 8){
ModifyStopLoss(TrailPrice);
}
}
if (TrailPrice!=0 && Ask+TrailingStep*Point < TrailPrice ){
TrailPrice=Ask-TrailingStep*Point;
Print(“TRAIL PRICE MODIFIED: “,TrailPrice);
if(TrailingStep > 8){
ModifyStopLoss(TrailPrice);
}
}
if (TrailPrice != 0 && Ask >= TrailPrice ){
CloseOrder(2);
}
}
if (OrderType()==OP_BUY) {
if (Bid-OrderOpenPrice() > TrailingAct*Point && TrailPrice ==0) {
TrailPrice=Bid-TrailingStep*Point;
Print(“TRAIL PRICE MODIFIED: “,TrailPrice);
if(TrailingStep > 8){
ModifyStopLoss(TrailPrice);
}
}
if (TrailPrice!= 0 && Bid-TrailingStep*Point > TrailPrice ){
TrailPrice=Bid-TrailingStep*Point;
Print(“TRAIL PRICE MODIFIED: “,TrailPrice);
if(TrailingStep > 8){
ModifyStopLoss(TrailPrice);
}
}
if (TrailPrice != 0 && Bid <= TrailPrice ){
CloseOrder(1);
}
}
}
}
}
}

void CloseOrder(int ord){
for(int i=0;i<OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY && OrderMagicNumber()==OrderID){
if (ord==1){
int res = OrderClose(OrderTicket(),OrderLots(),Bid,3,White); // close
TrailPrice=0;
if(res<0){
int error=GetLastError();
//Print(“Error = “,ErrorDescription(error));
}
}}

if (OrderType()==OP_SELL && OrderMagicNumber()==OrderID ){
if (ord==2) { // MA BUY signals
res = OrderClose(OrderTicket(),OrderLots(),Ask,3,White); // close
TrailPrice=0;
if(res<0){
error=GetLastError();
// Print(“Error = “,ErrorDescription(error));
}
}
}
}
}
void Scalp(){
double res;int error;
for(int i=0;i<OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()){
if(OrderType()==OP_BUY){
if(Bid – OrderOpenPrice() >= ScalpPips*Point){
res = OrderClose(OrderTicket(),OrderLots(),Bid,3,White); // close
TrailPrice=0;
if(res<0){
error=GetLastError();
// Print(“Error = “,ErrorDescription(error));
}
}
}
if(OrderType()==OP_SELL){
if(OrderOpenPrice() – Ask >= ScalpPips*Point){
res = OrderClose(OrderTicket(),OrderLots(),Ask,3,White); // close
TrailPrice=0;
if(res<0){
error=GetLastError();
// Print(“Error = “,ErrorDescription(error));
}
}
}
}
}
}
//+——————————————————————+
// Order Modify function
//+——————————————————————+
int openpos(){
int orders=0;
for(int i=0;i<OrdersTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderSymbol()==Symbol() ){
orders++;
}
}
}
return(orders);
}

void ModifyStopLoss(double ldStop) {
bool fm;
double ldOpen=OrderOpenPrice();
double ldTake=OrderTakeProfit();

fm=OrderModify(OrderTicket(), ldOpen, ldStop, ldTake, 0, Pink);

}
int start()
{
if(openpos()>1){Comment(“Cannot Track Multiple Orders with TTS”);return;}
if(openpos()==0)TrailPrice=0;
if(UseTrailing)TrailingPositions();
if(UseTightStop)Scalp();

return(0);
}
//+——————————————————————+

 

如果你对文件有了解,请帮助投票!

If you are familiar with the file, please help vote!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位投票人。

相关资源

暂无评论

none
暂无评论...