gpt4 book ai didi

mql4 - 算法交易 : How to incorporate this type of trailing stop?

转载 作者:行者123 更新时间:2023-12-05 07:32:52 25 4
gpt4 key购买 nike

我目前有一个几乎每 5 分钟就开始一次交易的系统。

我目前正在全神贯注地创建一个执行以下操作的追踪止损:

每个订单号扫描所有未结订单并修改它们,如果它们还没有被修改,像这样:

  1. 以 25 点的静态止损开始

  2. 在获利 5 点时将止损移至入场价

  3. 8 点利润移动止损 8 点利润(当前价格)后 4 点

这是我目前的情况

//---- input parameters
extern double InitialStop = 25;
extern double BreakEven = 20; // Profit Lock in pips
extern double StepSize = 5;
extern double MinDistance = 10;

int k, digit=0;
bool BE = false;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{

//----
return(0);
}

// ---- Stepped Stops
void StepStops()
{
double BuyStop, SellStop;
int total=OrdersTotal();
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
if ( OrderSymbol()==Symbol() )
{
if ( mode==OP_BUY )
{
BuyStop = OrderStopLoss();
if ( Bid-OrderOpenPrice()>0 || OrderStopLoss()==0)
{
if ( Bid-OrderOpenPrice()>=Point*BreakEven && !BE) {BuyStop = OrderOpenPrice();BE = true;}

if (OrderStopLoss()==0) {BuyStop = OrderOpenPrice() - InitialStop * Point; k=1; BE = false;}

if ( Bid-OrderOpenPrice()>= k*StepSize*Point)
{
BuyStop = OrderStopLoss()+ StepSize*Point;
if (Bid - BuyStop >= MinDistance*Point)
{ BuyStop = BuyStop; k=k+1;}
else
BuyStop = OrderStopLoss();
}
//Print( " k=",k ," del=", k*StepSize*Point, " BuyStop=", BuyStop," digit=", digit);
OrderModify(OrderTicket(),OrderOpenPrice(),
NormalizeDouble(BuyStop, digit),
OrderTakeProfit(),0,LightGreen);
return(0);
}
}
if ( mode==OP_SELL )
{
SellStop = OrderStopLoss();
if ( OrderOpenPrice()-Ask>0 || OrderStopLoss()==0)
{
if ( OrderOpenPrice()-Ask>=Point*BreakEven && !BE) {SellStop = OrderOpenPrice(); BE = true;}

if ( OrderStopLoss()==0 ) { SellStop = OrderOpenPrice() + InitialStop * Point; k=1; BE = false;}

if ( OrderOpenPrice()-Ask>=k*StepSize*Point)
{
SellStop = OrderStopLoss() - StepSize*Point;
if (SellStop - Ask >= MinDistance*Point)
{ SellStop = SellStop; k=k+1;}
else
SellStop = OrderStopLoss();
}
//Print( " k=",k," del=", k*StepSize*Point, " SellStop=",SellStop," digit=", digit);
OrderModify(OrderTicket(),OrderOpenPrice(),
NormalizeDouble(SellStop, digit),
OrderTakeProfit(),0,Yellow);
return(0);
}
}
}
}
}

// ---- Scan Trades
int ScanTrades()
{
int total = OrdersTotal();
int numords = 0;

for(int cnt=0; cnt<total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
if(OrderSymbol() == Symbol() && OrderType()<=OP_SELL)
numords++;
}
return(numords);
}


//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
digit = MarketInfo(Symbol(),MODE_DIGITS);


if (ScanTrades()<1) return(0);
else
if (BreakEven>0 || InitialStop>0 || StepSize>0) StepStops();

return(0);
}//int start
//+------------------------------------------------------------------+

如您所见,此 EA 确实以 25 点的静态止损开始,但我无法让它执行最后两个步骤,它们是:

  1. 在获利 5 点时将止损移至入场价
  2. 8 点利润移动止损 8 点利润(当前价格)后 4 点

如果您可以分享我可以合并到我的 EA 中或作为独立脚本/EA 运行的代码/想法,那将真的很有帮助。

谢谢

最佳答案

建议不要在服务器端申请止损,只要满足条件就直接用自己的代码平仓。

关于mql4 - 算法交易 : How to incorporate this type of trailing stop?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50965143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com