如何编码? - 页 145

 

嗨,Roger09。

再次感谢您的帮助。我的目标是使用一个脚本来移动我的止损,在买入交易中达到收支平衡加x点,或者在卖出交易中达到收支平衡减x点。我为该脚本设置了一个热键,这样当交易向我有利的方向发展时,我可以迅速锁定一些利润。我知道有些ES有这个功能,但我更喜欢使用脚本,这样我可以手动操作。

 

进程中不停止买入和停止卖出

你好。

我有一个使用CCI的EA。

我的程序在前一个条形图超过CCI>100时进行买入,但我想在最后一个条形图上高5点买入。

我想用同样的方法止损卖出(比最后的低点低5个点)。

这是我的EA,你能帮助我吗?

谢谢

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

//| 这个MQL是由专家顾问生成器生成的。

//|MetaTrader 4的专家顾问生成器

//| |

/+-------------------,不要删除这个标题 --------------------+

#define SIGNAL_NONE 0

#define SIGNAL_BUY 1

#define SIGNAL_SELL 2

#define SIGNAL_CLOSEBUY 3

#define SIGNAL_CLOSESELL 4

#property copyright "Expert Advisor Builder"

#property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

外部int MagicNumber = 0;

extern bool SignalMail = False;

extern bool EachTickMode = False;

外置双倍数 Lots = 1.0;

extern int Slippage = 30;

外部 bool UseStopLoss = True;

外置 int StopLoss = 200;

外部 bool UseTakeProfit = True;

外置 int TakeProfit = 600;

外部 bool UseTrailingStop = True;

外置 int TrailingStop = 250;

int BarCount;

int Current;

bool TickCheck = False;

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

//| 专家初始化函数 |

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

int init() {

BarCount = Bars;

如果(EachTickMode)Current = 0;否则Current = 1。

return(0);

}

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

//| 专家去初始化功能|

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

int deinit() {

return(0);

}

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

//| 专家启动功能|

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

int start() {

int Order = SIGNAL_NONE;

int Total, Ticket;

double StopLossLevel, TakeProfitLevel;

如果(EachTickMode && Bars != BarCount) TickCheck = False;

Total = OrdersTotal();

订单 = SIGNAL_NONE;

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

//| 变量开始 |

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

double Var1 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 0);

double Var2 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 1);

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

双倍Buy2_2 = 100;

double Buy3_1 = Var2 ;

双倍Buy3_2 = 100。

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 100;

double Sell3_1 = Var2 ;

双份Sell3_2 = - 100。

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

//| 变量结束 |

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

//检查仓位

bool IsTrade = False;

for (int i = 0; i < Total; i ++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES)。

如果(OrderType() <= OP_SELL && OrderSymbol() == Symbol() ) {

IsTrade = True。

如果(OrderType() == OP_BUY){

//关闭

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

//| 信号开始(退出买入)|

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

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

//| 信号结束(退出买入)|

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

如果(Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){

OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen)。

if (SignalMail) SendMail("[信号提示]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

继续。

}

//拖曳止损

if(UseTrailingStop && TrailingStop > 0) {

if(Bid - OrderOpenPrice() > Point * TrailingStop) {

如果(OrderStopLoss() < Bid - Point * TrailingStop) {

OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen) 。

if (!EachTickMode) BarCount = Bars;

继续。

}

}

}

} else {

//关闭

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

//| 信号开始(退出卖出)|

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

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

//| 信号结束(退出卖出)|

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

如果(Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){

OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange)。

如果(SignalMail) SendMail("[信号警报]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");

if (!EachTickMode) BarCount = Bars;

IsTrade = False。

继续。

}

//拖曳止损

if(UseTrailingStop && TrailingStop > 0) {

if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {

如果((OrderStopLoss() > (Ask + Point * TrailingStop))|| (OrderStopLoss() == 0)) {

OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange) 。

if (!EachTickMode) BarCount = Bars;

继续。

}

}

}

}

}

}

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

//| Signal Begin(Entry) |

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

如果(Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2 && Buy3_1 <= Buy3_2) Order = SIGNAL_BUY;

如果(Sell1_1 < Sell1_2 && Sell2_1 Sell3_2) Order = SIGNAL_SELL;

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

//| 信号结束 |

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

//买入

如果(Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){

if(!IsTrade) {

//检查自由保证金

如果(AccountFreeMargin() < (1000 * Lots)) {

Print("我们没有钱。Free Margin = ", AccountFreeMargin())。

return(0);

}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;

if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue) 。

如果(Ticket > 0) {

如果(OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("BUY订单打开:", OrderOpenPrice())。

if (SignalMail) SendMail("[信号提示]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");

} else {

Print("打开买入订单出错。", GetLastError())。

}

}

if (EachTickMode) TickCheck = True;

如果(!EachTickMode) BarCount = Bars;

return(0);

}

}

//卖出

如果(Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount))))){

if(!IsTrade) {

//检查自由保证金

如果(AccountFreeMargin() < (1000 * Lots)) {

Print("我们没有钱。Free Margin = ", AccountFreeMargin())。

return(0);

}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0。

if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink) 。

如果(Ticket > 0) {

如果(OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("Sell order opened : " , OrderOpenPrice());

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");

} else {

Print("错误打开卖出订单。", GetLastError())。

}

}

if (EachTickMode) TickCheck = True;

如果(!EachTickMode) BarCount = Bars;

return(0);

}

}

如果(!EachTickMode) BarCount = Bars;

return(0);

}

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

 
tk748:
嗨,Roger09,再次感谢您的帮助。我的目标是使用一个脚本来移动我的止损,在买入交易中达到收支平衡加x点,或者在卖出交易中达到收支平衡减x点。我为该脚本设置了一个热键,这样当交易向我有利的方向发展时,我可以迅速锁定一些利润。我知道有些ES有这个功能,但我更喜欢使用脚本,这样我可以手动操作。

如果你只需要设置一次止损,请使用此EA代码

extern int pips=10;//

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

//| 脚本程序启动功能|

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

int start()

{

//----

int ot = OrdersTotal();

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

{

int o = OrderSelect(i, SELECT_BY_POS);

如果(OrderSymbol() == Symbol()&&OrderType() <2)

{

double sl = 0。

如果(OrderType() == OP_BUY&& OrderStopLoss() =pips*Point)

sl = OrderOpenPrice() +pips*Point;

如果(OrderType() == OP_SELL && (OrderStopLoss() > OrderOpenPrice()||OrderStopLoss() ==0)

&&OrderOpenPrice()-Ask>=pips*Point)

sl = OrderOpenPrice() -pips*Point;

如果(!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0))

Print("Error_Modifying - ",GetLastError())。

}

}

//----

return(0);

}

 
cgassfr67:
你好。

我有一个使用CCI的EA。

我的程序在前一个条形图超过CCI>100时进行买入,但我想在最后一个条形图上高5点买入。

我想用同样的方法止损卖出(比最后的低点低5个点)。

这是我的EA,你能帮助我吗?

谢谢

替换

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 100;

double Buy3_1 = Var2 ;

double Buy3_2 = 100;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 100;

double Sell3_1 = Var2 ;

double Sell3_2 = - 100;[/CODE]

To

[CODE]

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 105;

double Buy3_1 = Var2 ;

double Buy3_2 = 105;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 105;

double Sell3_1 = Var2 ;

double Sell3_2 = - 105;
 
Roger09:
替换
double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 100;

double Buy3_1 = Var2 ;

double Buy3_2 = 100;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 100;

double Sell3_1 = Var2 ;

double Sell3_2 = - 100;[/CODE]

To

[CODE]

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 105;

double Buy3_1 = Var2 ;

double Buy3_2 = 105;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 105;

double Sell3_1 = Var2 ;

double Sell3_2 = - 105;

是的,但是使用这个代码,我将在下一个交易日的开盘时进入,而且我确信下一个交易日会增加,所以必须在最后一个高点之上5个点买入。

 

每小时的顶部交易

你好,我想根据一天的时间来调用我的EA,也许是早上5点和下午5点,或者每30分钟,等等。

我怎样才能做到这一点?

非常感谢任何帮助。

凯文

 

也许这可以帮助你。

如果((TimeHour(TimeLocal( ))!=5&&TimeMinute(TimeLocal( ))!=0)|(TimeHour(TimeLocal( ))=17

&&TimeMinute(TimeLocal( ))!=0))返回()。

把它放在start()的开头。

 

谁能看一下这个,让我知道为什么它不能工作。

我想把它作为一个注释使用。

Double AvgWin()

{

double CountTrades = 0;

双倍CountPips = 0。

for(int Ticket=0;Ticket<OrdersHistoryTotal(); Ticket++)

{

OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY);

如果(MyAccount==AccountNumber() &&OrderSymbol()==Symbol() &&OrderMagicNumber() == MagicNumber)

{

//------>>>>

如果(OrderType()==OP_BUY &&OrderClosePrice()>=OrderOpenPrice()

CountTrades++;

{

如果(OrderProfit() >= 0)

CountPips++;

}

如果(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice()

CountTrades++;

{

如果(OrderProfit() >= 0)

CountPips++;

}

}

}

如果(CountPips < 0)

返回(MathRound(CountPips/CountTrades)*10)。

否则

Print("Real Time AvgWin not Available");

return(mAvgWin);

}

 

首先,将

SELECT_BY_TICKET改为SELECT_BY_POS

第二,CountPips总是大于0。

 
Roger09:
首先是替换

SELECT_BY_TICKET改为SELECT_BY_POS

第二,CountPips总是大于0。

这样做可以吗?

平均赢钱()

{

int CountTrades = 0;

int CountPips = 0;

for(int Ticket=0;Ticket<OrdersHistoryTotal(); Ticket++)

{

OrderSelect(Ticket,SELECT_BY_POS,MODE_HISTORY);

如果(MyAccount==AccountNumber() &&OrderSymbol()==Symbol() &&OrderMagicNumber() == MagicNumber)

{

//------>>>>

如果(OrderType()==OP_BUY &&OrderClosePrice()>=OrderOpenPrice()

CountTrades++;

{

如果(OrderProfit() >= 0)

CountPips++;

}

如果(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice()

CountTrades++;

{

如果(OrderProfit() >= 0)

CountPips++;

}

}

}

如果(CountPips > 0)

返回(MathRound(CountPips/CountTrades)*10)。

否则

Print("Real Time AvgWin not Available");

return(mAvgWin);

}

原因: