当前位置:首页 股票知识 正文

自动止盈止损及追踪止损源码总结

2020-08-14 17:48:32

股票止损怎么定?想必是很股民在止损止赢过程中想要迫切知道的,有时止损止盈点设置的高低不太合适,对之后的追踪会有一定影响,那么如何才能将这个点设置的合理呢?其实有一种能够自动止盈止损,并且还可以追踪止损的源码可以解决你的困惑。

//---- input parameters

extern int 止赢=550;

extern int 止损=320;

extern int 追踪止损=150;

extern int Magic=0;

extern string 参数说明="建议不要小于10点";

int start()

{

//----

//追踪止损

_MoveStop(Magic, 追踪止损,0);

//设置止赢

_TakeProfit(Magic,止赢);

//设置止损

_StopLoss(Magic,止损);

//----

return(0);

}

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

//| _MoveStop 移动止损函数 function |

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

int _MoveStop(int MAGIC, int MOVE,int STEP)//_MoveStop(MAGIC, MOVE);

{

//----

if (MOVE<=0) return(0);

double MoveStopPrice;

for ( int z = OrdersTotal() - 1; z >= 0; z -- )

{

if ( !OrderSelect( z, SELECT_BY_** ) )

{

Print("OrderSelect(", z, ",SELECT_BY_**) - Error #",GetLastError() );

continue;

}

if (OrderSymbol()!=Symbol())continue;

if (OrderMagicNumber() != MAGIC )continue;

switch (OrderType())

{

case OP_BUY :

{

MoveStopPrice=NormalizeDouble(Bid-MOVE*Point,Digits);

if (MoveStopPrice>OrderOpenPrice() && OrderStopLoss()

{

if(!OrderModify(OrderTicket(),OrderOpenPrice(),MoveStopPrice+STEP*Point,OrderTakeProfit(),OrderExpiration()))

{

Alert("MoveStop_OrderModify Error #",GetLastError());

return(-1);

}

}

continue;

}

case OP_SELL:

{

MoveStopPrice=NormalizeDouble(Ask+MOVE*Point,Digits);

if (MoveStopPriceMoveStopPrice)

{

if(!OrderModify(OrderTicket(),OrderOpenPrice(),MoveStopPrice-STEP*Point,OrderTakeProfit(),OrderExpiration()))

{

Alert("MoveStop_OrderModify Error #",GetLastError());

return(-1);

}

}

continue;

}

default: continue;

}

}

//----

return(0);

}

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

//| _MoveStop 移动止损函数 function |

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

int _TakeProfit(int MAGIC, int TP)//

{

//----

if (TP<=0) return(0);

double TakeProfit;

for ( int z = OrdersTotal() - 1; z >= 0; z -- )

{

if ( !OrderSelect( z, SELECT_BY_** ) )

{

Print("OrderSelect(", z, ",SELECT_BY_**) - Error #",GetLastError() );

continue;

}

if (OrderSymbol()!=Symbol())continue;

if (OrderMagicNumber() != MAGIC )continue;

switch (OrderType())

{

case OP_BUY :

{

TakeProfit=NormalizeDouble(OrderOpenPrice()+TP*Point,Digits);

if (OrderTakeProfit()==0.0)

{

if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit,OrderExpiration()))

{

Alert("TakeProfit_OrderModify Error #",GetLastError());

}

}

continue;

}

case OP_SELL:

{

TakeProfit=NormalizeDouble(OrderOpenPrice()-TP*Point,Digits);

if (OrderTakeProfit()==0.0)

{

if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit,OrderExpiration()))

{

Alert("TakeProfit_OrderModify Error #",GetLastError());

}

}

continue;

}

default: continue;

}

}

//----

return(0);

}

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

//| _MoveStop 移动止损函数 function |

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

int _StopLoss(int MAGIC, int SL)//_MoveStop(MAGIC, MOVE);

{

//----

if (SL<=0) return(0);

double StopLoss;

for ( int z = OrdersTotal() - 1; z >= 0; z -- )

{

if ( !OrderSelect( z, SELECT_BY_** ) )

{

Print("OrderSelect(", z, ",SELECT_BY_**) - Error #",GetLastError() );

continue;

}

if (OrderSymbol()!=Symbol())continue;

if (OrderMagicNumber() != MAGIC )continue;

switch (OrderType())

{

case OP_BUY :

{

StopLoss=NormalizeDouble(OrderOpenPrice()-SL*Point,Digits);

if (OrderStopLoss()==0.0)

{

if(!OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,OrderTakeProfit(),OrderExpiration()))

{

Alert("StopLoss_OrderModify Error #",GetLastError());

}

}

continue;

}

case OP_SELL:

{

StopLoss=NormalizeDouble(OrderOpenPrice()+SL*Point,Digits);

if (OrderStopLoss()==0.0)

{

if(!OrderModify(OrderTicket(),OrderOpenPrice(),StopLoss,OrderTakeProfit(),OrderExpiration()))

{

Alert("StopLoss_OrderModify Error #",GetLastError());

}

}

continue;

}

default: continue;

}

}

//----

return(0);

}

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

自动止盈止损及追踪止损的方法,不仅可以及时进行止损,还可以在盈利之时将利润大化处理,同时还能够规避掉一些不可预知的风险,这是股票止损技巧中困难的,也是难把握的地方,这种方法的出现无疑也给投资增加了一层防护膜。

推荐阅读

隔日超短线止损止盈点有何技巧?止损止盈设定范围!

超短线止盈止损点怎么设置?有哪些止损止盈方法?

合理的止盈止损比例怎么设置?如何正确对待止损止盈?

温馨提示:《自动止盈止损及追踪止损源码总结》内容整理自网络以及网友投稿,仅供参考交流使用,版权归原作者所有,如有侵权请联系本站删除,谢谢。投资有风险,入市需谨慎。

免责声明:文章不代表本站观点及立场,不构成本平台任何投资建议。投资决策需建立在独立思考之上,本文内容仅供参考,风险自担!
基金公司 期货公司 证券公司 股票软件 金融问答 金融期货 信托知识 债券知识 保险知识 理财知识 银行知识 沪深股票 期货知识 基金知识 基金概况 股票知识 贷款知识 金融热点 常见问题 专题推荐 产品百科 软件中心 金融平台 金融知识 黄金知识 白银知识